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