1 /*- 2 * Copyright (c) 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley 6 * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension 7 * Support code is derived from software contributed to Berkeley 8 * by Atsushi Murai (amurai@spec.co.jp). 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)cd9660_vnops.c 8.19 (Berkeley) 5/27/95 39 * $FreeBSD$ 40 */ 41 42 #include <sys/param.h> 43 #include <sys/systm.h> 44 #include <sys/namei.h> 45 #include <sys/kernel.h> 46 #include <sys/stat.h> 47 #include <sys/bio.h> 48 #include <sys/buf.h> 49 #include <sys/mount.h> 50 #include <sys/vnode.h> 51 #include <fs/fifofs/fifo.h> 52 #include <sys/malloc.h> 53 #include <sys/dirent.h> 54 #include <sys/unistd.h> 55 #include <sys/filio.h> 56 57 #include <vm/vm.h> 58 #include <vm/vm_zone.h> 59 #include <vm/vnode_pager.h> 60 61 #include <isofs/cd9660/iso.h> 62 #include <isofs/cd9660/cd9660_node.h> 63 #include <isofs/cd9660/iso_rrip.h> 64 65 static int cd9660_setattr __P((struct vop_setattr_args *)); 66 static int cd9660_access __P((struct vop_access_args *)); 67 static int cd9660_getattr __P((struct vop_getattr_args *)); 68 static int cd9660_ioctl __P((struct vop_ioctl_args *)); 69 static int cd9660_pathconf __P((struct vop_pathconf_args *)); 70 static int cd9660_read __P((struct vop_read_args *)); 71 struct isoreaddir; 72 static int iso_uiodir __P((struct isoreaddir *idp, struct dirent *dp, 73 off_t off)); 74 static int iso_shipdir __P((struct isoreaddir *idp)); 75 static int cd9660_readdir __P((struct vop_readdir_args *)); 76 static int cd9660_readlink __P((struct vop_readlink_args *ap)); 77 static int cd9660_strategy __P((struct vop_strategy_args *)); 78 static int cd9660_print __P((struct vop_print_args *)); 79 80 /* 81 * Setattr call. Only allowed for block and character special devices. 82 */ 83 int 84 cd9660_setattr(ap) 85 struct vop_setattr_args /* { 86 struct vnodeop_desc *a_desc; 87 struct vnode *a_vp; 88 struct vattr *a_vap; 89 struct ucred *a_cred; 90 struct proc *a_p; 91 } */ *ap; 92 { 93 struct vnode *vp = ap->a_vp; 94 struct vattr *vap = ap->a_vap; 95 96 if (vap->va_flags != (u_long)VNOVAL || vap->va_uid != (uid_t)VNOVAL || 97 vap->va_gid != (gid_t)VNOVAL || vap->va_atime.tv_sec != VNOVAL || 98 vap->va_mtime.tv_sec != VNOVAL || vap->va_mode != (mode_t)VNOVAL) 99 return (EROFS); 100 if (vap->va_size != (u_quad_t)VNOVAL) { 101 switch (vp->v_type) { 102 case VDIR: 103 return (EISDIR); 104 case VLNK: 105 case VREG: 106 return (EROFS); 107 case VCHR: 108 case VBLK: 109 case VSOCK: 110 case VFIFO: 111 case VNON: 112 case VBAD: 113 return (0); 114 } 115 } 116 return (0); 117 } 118 119 /* 120 * Check mode permission on inode pointer. Mode is READ, WRITE or EXEC. 121 * The mode is shifted to select the owner/group/other fields. The 122 * super user is granted all permissions. 123 */ 124 /* ARGSUSED */ 125 static int 126 cd9660_access(ap) 127 struct vop_access_args /* { 128 struct vnode *a_vp; 129 int a_mode; 130 struct ucred *a_cred; 131 struct proc *a_p; 132 } */ *ap; 133 { 134 struct vnode *vp = ap->a_vp; 135 struct iso_node *ip = VTOI(vp); 136 mode_t mode = ap->a_mode; 137 138 /* 139 * Disallow write attempts unless the file is a socket, 140 * fifo, or a block or character device resident on the 141 * file system. 142 */ 143 if (mode & VWRITE) { 144 switch (vp->v_type) { 145 case VDIR: 146 case VLNK: 147 case VREG: 148 return (EROFS); 149 /* NOT REACHED */ 150 default: 151 break; 152 } 153 } 154 155 return (vaccess(vp->v_type, ip->inode.iso_mode, ip->inode.iso_uid, 156 ip->inode.iso_gid, ap->a_mode, ap->a_cred, NULL)); 157 } 158 159 static int 160 cd9660_getattr(ap) 161 struct vop_getattr_args /* { 162 struct vnode *a_vp; 163 struct vattr *a_vap; 164 struct ucred *a_cred; 165 struct proc *a_p; 166 } */ *ap; 167 168 { 169 struct vnode *vp = ap->a_vp; 170 register struct vattr *vap = ap->a_vap; 171 register struct iso_node *ip = VTOI(vp); 172 173 vap->va_fsid = dev2udev(ip->i_dev); 174 vap->va_fileid = ip->i_number; 175 176 vap->va_mode = ip->inode.iso_mode; 177 vap->va_nlink = ip->inode.iso_links; 178 vap->va_uid = ip->inode.iso_uid; 179 vap->va_gid = ip->inode.iso_gid; 180 vap->va_atime = ip->inode.iso_atime; 181 vap->va_mtime = ip->inode.iso_mtime; 182 vap->va_ctime = ip->inode.iso_ctime; 183 vap->va_rdev = ip->inode.iso_rdev; 184 185 vap->va_size = (u_quad_t) ip->i_size; 186 if (ip->i_size == 0 && (vap->va_mode & S_IFMT) == S_IFLNK) { 187 struct vop_readlink_args rdlnk; 188 struct iovec aiov; 189 struct uio auio; 190 char *cp; 191 192 MALLOC(cp, char *, MAXPATHLEN, M_TEMP, M_WAITOK); 193 aiov.iov_base = cp; 194 aiov.iov_len = MAXPATHLEN; 195 auio.uio_iov = &aiov; 196 auio.uio_iovcnt = 1; 197 auio.uio_offset = 0; 198 auio.uio_rw = UIO_READ; 199 auio.uio_segflg = UIO_SYSSPACE; 200 auio.uio_procp = ap->a_p; 201 auio.uio_resid = MAXPATHLEN; 202 rdlnk.a_uio = &auio; 203 rdlnk.a_vp = ap->a_vp; 204 rdlnk.a_cred = ap->a_cred; 205 if (cd9660_readlink(&rdlnk) == 0) 206 vap->va_size = MAXPATHLEN - auio.uio_resid; 207 FREE(cp, M_TEMP); 208 } 209 vap->va_flags = 0; 210 vap->va_gen = 1; 211 vap->va_blocksize = ip->i_mnt->logical_block_size; 212 vap->va_bytes = (u_quad_t) ip->i_size; 213 vap->va_type = vp->v_type; 214 vap->va_filerev = 0; 215 return (0); 216 } 217 218 /* 219 * Vnode op for ioctl. 220 */ 221 static int 222 cd9660_ioctl(ap) 223 struct vop_ioctl_args /* { 224 struct vnode *a_vp; 225 int a_command; 226 caddr_t a_data; 227 int a_fflag; 228 struct ucred *a_cred; 229 struct proc *a_p; 230 } */ *ap; 231 { 232 struct vnode *vp = ap->a_vp; 233 struct iso_node *ip = VTOI(vp); 234 235 switch (ap->a_command) { 236 237 case FIOGETLBA: 238 *(int *)(ap->a_data) = ip->iso_start; 239 return 0; 240 default: 241 return (ENOTTY); 242 } 243 } 244 245 /* 246 * Vnode op for reading. 247 */ 248 static int 249 cd9660_read(ap) 250 struct vop_read_args /* { 251 struct vnode *a_vp; 252 struct uio *a_uio; 253 int a_ioflag; 254 struct ucred *a_cred; 255 } */ *ap; 256 { 257 struct vnode *vp = ap->a_vp; 258 register struct uio *uio = ap->a_uio; 259 register struct iso_node *ip = VTOI(vp); 260 register struct iso_mnt *imp; 261 struct buf *bp; 262 daddr_t lbn, rablock; 263 off_t diff; 264 int rasize, error = 0; 265 int seqcount; 266 long size, n, on; 267 268 seqcount = ap->a_ioflag >> 16; 269 270 if (uio->uio_resid == 0) 271 return (0); 272 if (uio->uio_offset < 0) 273 return (EINVAL); 274 ip->i_flag |= IN_ACCESS; 275 imp = ip->i_mnt; 276 do { 277 lbn = lblkno(imp, uio->uio_offset); 278 on = blkoff(imp, uio->uio_offset); 279 n = min((u_int)(imp->logical_block_size - on), 280 uio->uio_resid); 281 diff = (off_t)ip->i_size - uio->uio_offset; 282 if (diff <= 0) 283 return (0); 284 if (diff < n) 285 n = diff; 286 size = blksize(imp, ip, lbn); 287 rablock = lbn + 1; 288 if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERR) == 0) { 289 if (lblktosize(imp, rablock) < ip->i_size) 290 error = cluster_read(vp, (off_t)ip->i_size, 291 lbn, size, NOCRED, uio->uio_resid, 292 (ap->a_ioflag >> 16), &bp); 293 else 294 error = bread(vp, lbn, size, NOCRED, &bp); 295 } else { 296 if (seqcount > 1 && 297 lblktosize(imp, rablock) < ip->i_size) { 298 rasize = blksize(imp, ip, rablock); 299 error = breadn(vp, lbn, size, &rablock, 300 &rasize, 1, NOCRED, &bp); 301 } else 302 error = bread(vp, lbn, size, NOCRED, &bp); 303 } 304 n = min(n, size - bp->b_resid); 305 if (error) { 306 brelse(bp); 307 return (error); 308 } 309 310 error = uiomove(bp->b_data + on, (int)n, uio); 311 brelse(bp); 312 } while (error == 0 && uio->uio_resid > 0 && n != 0); 313 return (error); 314 } 315 316 /* 317 * Structure for reading directories 318 */ 319 struct isoreaddir { 320 struct dirent saveent; 321 struct dirent assocent; 322 struct dirent current; 323 off_t saveoff; 324 off_t assocoff; 325 off_t curroff; 326 struct uio *uio; 327 off_t uio_off; 328 int eofflag; 329 u_long *cookies; 330 int ncookies; 331 }; 332 333 int 334 iso_uiodir(idp,dp,off) 335 struct isoreaddir *idp; 336 struct dirent *dp; 337 off_t off; 338 { 339 int error; 340 341 dp->d_name[dp->d_namlen] = 0; 342 dp->d_reclen = GENERIC_DIRSIZ(dp); 343 344 if (idp->uio->uio_resid < dp->d_reclen) { 345 idp->eofflag = 0; 346 return (-1); 347 } 348 349 if (idp->cookies) { 350 if (idp->ncookies <= 0) { 351 idp->eofflag = 0; 352 return (-1); 353 } 354 355 *idp->cookies++ = off; 356 --idp->ncookies; 357 } 358 359 if ((error = uiomove((caddr_t) dp,dp->d_reclen,idp->uio)) != 0) 360 return (error); 361 idp->uio_off = off; 362 return (0); 363 } 364 365 int 366 iso_shipdir(idp) 367 struct isoreaddir *idp; 368 { 369 struct dirent *dp; 370 int cl, sl, assoc; 371 int error; 372 char *cname, *sname; 373 374 cl = idp->current.d_namlen; 375 cname = idp->current.d_name; 376 assoc = (cl > 1) && (*cname == ASSOCCHAR); 377 if (assoc) { 378 cl--; 379 cname++; 380 } 381 382 dp = &idp->saveent; 383 sname = dp->d_name; 384 if (!(sl = dp->d_namlen)) { 385 dp = &idp->assocent; 386 sname = dp->d_name + 1; 387 sl = dp->d_namlen - 1; 388 } 389 if (sl > 0) { 390 if (sl != cl 391 || bcmp(sname,cname,sl)) { 392 if (idp->assocent.d_namlen) { 393 if ((error = iso_uiodir(idp,&idp->assocent,idp->assocoff)) != 0) 394 return (error); 395 idp->assocent.d_namlen = 0; 396 } 397 if (idp->saveent.d_namlen) { 398 if ((error = iso_uiodir(idp,&idp->saveent,idp->saveoff)) != 0) 399 return (error); 400 idp->saveent.d_namlen = 0; 401 } 402 } 403 } 404 idp->current.d_reclen = GENERIC_DIRSIZ(&idp->current); 405 if (assoc) { 406 idp->assocoff = idp->curroff; 407 bcopy(&idp->current,&idp->assocent,idp->current.d_reclen); 408 } else { 409 idp->saveoff = idp->curroff; 410 bcopy(&idp->current,&idp->saveent,idp->current.d_reclen); 411 } 412 return (0); 413 } 414 415 /* 416 * Vnode op for readdir 417 */ 418 static int 419 cd9660_readdir(ap) 420 struct vop_readdir_args /* { 421 struct vnode *a_vp; 422 struct uio *a_uio; 423 struct ucred *a_cred; 424 int *a_eofflag; 425 int *a_ncookies; 426 u_long *a_cookies; 427 } */ *ap; 428 { 429 register struct uio *uio = ap->a_uio; 430 struct isoreaddir *idp; 431 struct vnode *vdp = ap->a_vp; 432 struct iso_node *dp; 433 struct iso_mnt *imp; 434 struct buf *bp = NULL; 435 struct iso_directory_record *ep; 436 int entryoffsetinblock; 437 doff_t endsearch; 438 u_long bmask; 439 int error = 0; 440 int reclen; 441 u_short namelen; 442 int ncookies = 0; 443 u_long *cookies = NULL; 444 445 dp = VTOI(vdp); 446 imp = dp->i_mnt; 447 bmask = imp->im_bmask; 448 449 MALLOC(idp, struct isoreaddir *, sizeof(*idp), M_TEMP, M_WAITOK); 450 idp->saveent.d_namlen = idp->assocent.d_namlen = 0; 451 /* 452 * XXX 453 * Is it worth trying to figure out the type? 454 */ 455 idp->saveent.d_type = idp->assocent.d_type = idp->current.d_type = 456 DT_UNKNOWN; 457 idp->uio = uio; 458 if (ap->a_ncookies == NULL) { 459 idp->cookies = NULL; 460 } else { 461 /* 462 * Guess the number of cookies needed. 463 */ 464 ncookies = uio->uio_resid / 16; 465 MALLOC(cookies, u_long *, ncookies * sizeof(u_int), M_TEMP, 466 M_WAITOK); 467 idp->cookies = cookies; 468 idp->ncookies = ncookies; 469 } 470 idp->eofflag = 1; 471 idp->curroff = uio->uio_offset; 472 473 if ((entryoffsetinblock = idp->curroff & bmask) && 474 (error = cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp))) { 475 FREE(idp, M_TEMP); 476 return (error); 477 } 478 endsearch = dp->i_size; 479 480 while (idp->curroff < endsearch) { 481 /* 482 * If offset is on a block boundary, 483 * read the next directory block. 484 * Release previous if it exists. 485 */ 486 if ((idp->curroff & bmask) == 0) { 487 if (bp != NULL) 488 brelse(bp); 489 if ((error = 490 cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp)) != 0) 491 break; 492 entryoffsetinblock = 0; 493 } 494 /* 495 * Get pointer to next entry. 496 */ 497 ep = (struct iso_directory_record *) 498 ((char *)bp->b_data + entryoffsetinblock); 499 500 reclen = isonum_711(ep->length); 501 if (reclen == 0) { 502 /* skip to next block, if any */ 503 idp->curroff = 504 (idp->curroff & ~bmask) + imp->logical_block_size; 505 continue; 506 } 507 508 if (reclen < ISO_DIRECTORY_RECORD_SIZE) { 509 error = EINVAL; 510 /* illegal entry, stop */ 511 break; 512 } 513 514 if (entryoffsetinblock + reclen > imp->logical_block_size) { 515 error = EINVAL; 516 /* illegal directory, so stop looking */ 517 break; 518 } 519 520 idp->current.d_namlen = isonum_711(ep->name_len); 521 522 if (reclen < ISO_DIRECTORY_RECORD_SIZE + idp->current.d_namlen) { 523 error = EINVAL; 524 /* illegal entry, stop */ 525 break; 526 } 527 528 if (isonum_711(ep->flags)&2) 529 idp->current.d_fileno = isodirino(ep, imp); 530 else 531 idp->current.d_fileno = dbtob(bp->b_blkno) + 532 entryoffsetinblock; 533 534 idp->curroff += reclen; 535 536 switch (imp->iso_ftype) { 537 case ISO_FTYPE_RRIP: 538 cd9660_rrip_getname(ep,idp->current.d_name, &namelen, 539 &idp->current.d_fileno,imp); 540 idp->current.d_namlen = (u_char)namelen; 541 if (idp->current.d_namlen) 542 error = iso_uiodir(idp,&idp->current,idp->curroff); 543 break; 544 default: /* ISO_FTYPE_DEFAULT || ISO_FTYPE_9660 || ISO_FTYPE_HIGH_SIERRA*/ 545 strcpy(idp->current.d_name,".."); 546 if (idp->current.d_namlen == 1 && ep->name[0] == 0) { 547 idp->current.d_namlen = 1; 548 error = iso_uiodir(idp,&idp->current,idp->curroff); 549 } else if (idp->current.d_namlen == 1 && ep->name[0] == 1) { 550 idp->current.d_namlen = 2; 551 error = iso_uiodir(idp,&idp->current,idp->curroff); 552 } else { 553 isofntrans(ep->name,idp->current.d_namlen, 554 idp->current.d_name, &namelen, 555 imp->iso_ftype == ISO_FTYPE_9660, 556 isonum_711(ep->flags)&4, 557 imp->joliet_level); 558 idp->current.d_namlen = (u_char)namelen; 559 if (imp->iso_ftype == ISO_FTYPE_DEFAULT) 560 error = iso_shipdir(idp); 561 else 562 error = iso_uiodir(idp,&idp->current,idp->curroff); 563 } 564 } 565 if (error) 566 break; 567 568 entryoffsetinblock += reclen; 569 } 570 571 if (!error && imp->iso_ftype == ISO_FTYPE_DEFAULT) { 572 idp->current.d_namlen = 0; 573 error = iso_shipdir(idp); 574 } 575 if (error < 0) 576 error = 0; 577 578 if (ap->a_ncookies != NULL) { 579 if (error) 580 free(cookies, M_TEMP); 581 else { 582 /* 583 * Work out the number of cookies actually used. 584 */ 585 *ap->a_ncookies = ncookies - idp->ncookies; 586 *ap->a_cookies = cookies; 587 } 588 } 589 590 if (bp) 591 brelse (bp); 592 593 uio->uio_offset = idp->uio_off; 594 *ap->a_eofflag = idp->eofflag; 595 596 FREE(idp, M_TEMP); 597 598 return (error); 599 } 600 601 /* 602 * Return target name of a symbolic link 603 * Shouldn't we get the parent vnode and read the data from there? 604 * This could eventually result in deadlocks in cd9660_lookup. 605 * But otherwise the block read here is in the block buffer two times. 606 */ 607 typedef struct iso_directory_record ISODIR; 608 typedef struct iso_node ISONODE; 609 typedef struct iso_mnt ISOMNT; 610 static int 611 cd9660_readlink(ap) 612 struct vop_readlink_args /* { 613 struct vnode *a_vp; 614 struct uio *a_uio; 615 struct ucred *a_cred; 616 } */ *ap; 617 { 618 ISONODE *ip; 619 ISODIR *dirp; 620 ISOMNT *imp; 621 struct buf *bp; 622 struct uio *uio; 623 u_short symlen; 624 int error; 625 char *symname; 626 627 ip = VTOI(ap->a_vp); 628 imp = ip->i_mnt; 629 uio = ap->a_uio; 630 631 if (imp->iso_ftype != ISO_FTYPE_RRIP) 632 return (EINVAL); 633 634 /* 635 * Get parents directory record block that this inode included. 636 */ 637 error = bread(imp->im_devvp, 638 (ip->i_number >> imp->im_bshift) << 639 (imp->im_bshift - DEV_BSHIFT), 640 imp->logical_block_size, NOCRED, &bp); 641 if (error) { 642 brelse(bp); 643 return (EINVAL); 644 } 645 646 /* 647 * Setup the directory pointer for this inode 648 */ 649 dirp = (ISODIR *)(bp->b_data + (ip->i_number & imp->im_bmask)); 650 651 /* 652 * Just make sure, we have a right one.... 653 * 1: Check not cross boundary on block 654 */ 655 if ((ip->i_number & imp->im_bmask) + isonum_711(dirp->length) 656 > (unsigned)imp->logical_block_size) { 657 brelse(bp); 658 return (EINVAL); 659 } 660 661 /* 662 * Now get a buffer 663 * Abuse a namei buffer for now. 664 */ 665 if (uio->uio_segflg == UIO_SYSSPACE) 666 symname = uio->uio_iov->iov_base; 667 else 668 symname = zalloc(namei_zone); 669 670 /* 671 * Ok, we just gathering a symbolic name in SL record. 672 */ 673 if (cd9660_rrip_getsymname(dirp, symname, &symlen, imp) == 0) { 674 if (uio->uio_segflg != UIO_SYSSPACE) 675 zfree(namei_zone, symname); 676 brelse(bp); 677 return (EINVAL); 678 } 679 /* 680 * Don't forget before you leave from home ;-) 681 */ 682 brelse(bp); 683 684 /* 685 * return with the symbolic name to caller's. 686 */ 687 if (uio->uio_segflg != UIO_SYSSPACE) { 688 error = uiomove(symname, symlen, uio); 689 zfree(namei_zone, symname); 690 return (error); 691 } 692 uio->uio_resid -= symlen; 693 uio->uio_iov->iov_base += symlen; 694 uio->uio_iov->iov_len -= symlen; 695 return (0); 696 } 697 698 /* 699 * Calculate the logical to physical mapping if not done already, 700 * then call the device strategy routine. 701 */ 702 static int 703 cd9660_strategy(ap) 704 struct vop_strategy_args /* { 705 struct buf *a_vp; 706 struct buf *a_bp; 707 } */ *ap; 708 { 709 register struct buf *bp = ap->a_bp; 710 register struct vnode *vp = bp->b_vp; 711 register struct iso_node *ip; 712 713 ip = VTOI(vp); 714 if (vp->v_type == VBLK || vp->v_type == VCHR) 715 panic("cd9660_strategy: spec"); 716 if (bp->b_blkno == bp->b_lblkno) { 717 bp->b_blkno = (ip->iso_start + bp->b_lblkno) << 718 (ip->i_mnt->im_bshift - DEV_BSHIFT); 719 if ((long)bp->b_blkno == -1) /* XXX: cut&paste junk ? */ 720 clrbuf(bp); 721 } 722 if ((long)bp->b_blkno == -1) { /* XXX: cut&paste junk ? */ 723 bufdone(bp); 724 return (0); 725 } 726 vp = ip->i_devvp; 727 bp->b_dev = vp->v_rdev; 728 VOP_STRATEGY(vp, bp); 729 return (0); 730 } 731 732 /* 733 * Print out the contents of an inode. 734 */ 735 static int 736 cd9660_print(ap) 737 struct vop_print_args /* { 738 struct vnode *a_vp; 739 } */ *ap; 740 { 741 742 printf("tag VT_ISOFS, isofs vnode\n"); 743 return (0); 744 } 745 746 /* 747 * Return POSIX pathconf information applicable to cd9660 filesystems. 748 */ 749 static int 750 cd9660_pathconf(ap) 751 struct vop_pathconf_args /* { 752 struct vnode *a_vp; 753 int a_name; 754 register_t *a_retval; 755 } */ *ap; 756 { 757 758 switch (ap->a_name) { 759 case _PC_LINK_MAX: 760 *ap->a_retval = 1; 761 return (0); 762 case _PC_NAME_MAX: 763 if (VTOI(ap->a_vp)->i_mnt->iso_ftype == ISO_FTYPE_RRIP) 764 *ap->a_retval = NAME_MAX; 765 else 766 *ap->a_retval = 37; 767 return (0); 768 case _PC_PATH_MAX: 769 *ap->a_retval = PATH_MAX; 770 return (0); 771 case _PC_PIPE_BUF: 772 *ap->a_retval = PIPE_BUF; 773 return (0); 774 case _PC_CHOWN_RESTRICTED: 775 *ap->a_retval = 1; 776 return (0); 777 case _PC_NO_TRUNC: 778 *ap->a_retval = 1; 779 return (0); 780 default: 781 return (EINVAL); 782 } 783 /* NOTREACHED */ 784 } 785 786 /* 787 * Global vfs data structures for cd9660 788 */ 789 vop_t **cd9660_vnodeop_p; 790 static struct vnodeopv_entry_desc cd9660_vnodeop_entries[] = { 791 { &vop_default_desc, (vop_t *) vop_defaultop }, 792 { &vop_access_desc, (vop_t *) cd9660_access }, 793 { &vop_bmap_desc, (vop_t *) cd9660_bmap }, 794 { &vop_cachedlookup_desc, (vop_t *) cd9660_lookup }, 795 { &vop_getattr_desc, (vop_t *) cd9660_getattr }, 796 { &vop_inactive_desc, (vop_t *) cd9660_inactive }, 797 { &vop_ioctl_desc, (vop_t *) cd9660_ioctl }, 798 { &vop_islocked_desc, (vop_t *) vop_stdislocked }, 799 { &vop_lock_desc, (vop_t *) vop_stdlock }, 800 { &vop_lookup_desc, (vop_t *) vfs_cache_lookup }, 801 { &vop_pathconf_desc, (vop_t *) cd9660_pathconf }, 802 { &vop_print_desc, (vop_t *) cd9660_print }, 803 { &vop_read_desc, (vop_t *) cd9660_read }, 804 { &vop_readdir_desc, (vop_t *) cd9660_readdir }, 805 { &vop_readlink_desc, (vop_t *) cd9660_readlink }, 806 { &vop_reclaim_desc, (vop_t *) cd9660_reclaim }, 807 { &vop_setattr_desc, (vop_t *) cd9660_setattr }, 808 { &vop_strategy_desc, (vop_t *) cd9660_strategy }, 809 { &vop_unlock_desc, (vop_t *) vop_stdunlock }, 810 { NULL, NULL } 811 }; 812 static struct vnodeopv_desc cd9660_vnodeop_opv_desc = 813 { &cd9660_vnodeop_p, cd9660_vnodeop_entries }; 814 VNODEOP_SET(cd9660_vnodeop_opv_desc); 815 816 /* 817 * Special device vnode ops 818 */ 819 vop_t **cd9660_specop_p; 820 static struct vnodeopv_entry_desc cd9660_specop_entries[] = { 821 { &vop_default_desc, (vop_t *) spec_vnoperate }, 822 { &vop_access_desc, (vop_t *) cd9660_access }, 823 { &vop_getattr_desc, (vop_t *) cd9660_getattr }, 824 { &vop_inactive_desc, (vop_t *) cd9660_inactive }, 825 { &vop_islocked_desc, (vop_t *) vop_stdislocked }, 826 { &vop_lock_desc, (vop_t *) vop_stdlock }, 827 { &vop_print_desc, (vop_t *) cd9660_print }, 828 { &vop_reclaim_desc, (vop_t *) cd9660_reclaim }, 829 { &vop_setattr_desc, (vop_t *) cd9660_setattr }, 830 { &vop_unlock_desc, (vop_t *) vop_stdunlock }, 831 { NULL, NULL } 832 }; 833 static struct vnodeopv_desc cd9660_specop_opv_desc = 834 { &cd9660_specop_p, cd9660_specop_entries }; 835 VNODEOP_SET(cd9660_specop_opv_desc); 836 837 vop_t **cd9660_fifoop_p; 838 static struct vnodeopv_entry_desc cd9660_fifoop_entries[] = { 839 { &vop_default_desc, (vop_t *) fifo_vnoperate }, 840 { &vop_access_desc, (vop_t *) cd9660_access }, 841 { &vop_getattr_desc, (vop_t *) cd9660_getattr }, 842 { &vop_inactive_desc, (vop_t *) cd9660_inactive }, 843 { &vop_islocked_desc, (vop_t *) vop_stdislocked }, 844 { &vop_lock_desc, (vop_t *) vop_stdlock }, 845 { &vop_print_desc, (vop_t *) cd9660_print }, 846 { &vop_reclaim_desc, (vop_t *) cd9660_reclaim }, 847 { &vop_setattr_desc, (vop_t *) cd9660_setattr }, 848 { &vop_unlock_desc, (vop_t *) vop_stdunlock }, 849 { NULL, NULL } 850 }; 851 static struct vnodeopv_desc cd9660_fifoop_opv_desc = 852 { &cd9660_fifoop_p, cd9660_fifoop_entries }; 853 854 VNODEOP_SET(cd9660_fifoop_opv_desc); 855