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