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