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 <isofs/cd9660/iso.h> 61 #include <isofs/cd9660/cd9660_node.h> 62 #include <isofs/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 78 /* 79 * Setattr call. Only allowed for block and character special devices. 80 */ 81 static int 82 cd9660_setattr(ap) 83 struct vop_setattr_args /* { 84 struct vnodeop_desc *a_desc; 85 struct vnode *a_vp; 86 struct vattr *a_vap; 87 struct ucred *a_cred; 88 struct thread *a_td; 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 return (0); 112 } 113 } 114 return (0); 115 } 116 117 /* 118 * Check mode permission on inode pointer. Mode is READ, WRITE or EXEC. 119 * The mode is shifted to select the owner/group/other fields. The 120 * super user is granted all permissions. 121 */ 122 /* ARGSUSED */ 123 static int 124 cd9660_access(ap) 125 struct vop_access_args /* { 126 struct vnode *a_vp; 127 int a_mode; 128 struct ucred *a_cred; 129 struct thread *a_td; 130 } */ *ap; 131 { 132 struct vnode *vp = ap->a_vp; 133 struct iso_node *ip = VTOI(vp); 134 mode_t mode = ap->a_mode; 135 136 if (vp->v_type == VCHR || vp->v_type == VBLK) 137 return (EOPNOTSUPP); 138 139 /* 140 * Disallow write attempts unless the file is a socket, 141 * fifo, or a block or character device resident on the 142 * filesystem. 143 */ 144 if (mode & VWRITE) { 145 switch (vp->v_type) { 146 case VDIR: 147 case VLNK: 148 case VREG: 149 return (EROFS); 150 /* NOT REACHED */ 151 default: 152 break; 153 } 154 } 155 156 return (vaccess(vp->v_type, ip->inode.iso_mode, ip->inode.iso_uid, 157 ip->inode.iso_gid, ap->a_mode, ap->a_cred, NULL)); 158 } 159 160 static int 161 cd9660_open(ap) 162 struct vop_open_args /* { 163 struct vnode *a_vp; 164 int a_mode; 165 struct ucred *a_cred; 166 struct thread *a_td; 167 int a_fdidx; 168 } */ *ap; 169 { 170 struct iso_node *ip = VTOI(ap->a_vp); 171 172 vnode_create_vobject(ap->a_vp, ip->i_size, ap->a_td); 173 return 0; 174 } 175 176 177 static int 178 cd9660_getattr(ap) 179 struct vop_getattr_args /* { 180 struct vnode *a_vp; 181 struct vattr *a_vap; 182 struct ucred *a_cred; 183 struct thread *a_td; 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 MALLOC(cp, char *, 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 = ap->a_td; 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 MALLOC(idp, struct isoreaddir *, 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 MALLOC(cookies, u_long *, 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 497 if ((entryoffsetinblock = idp->curroff & bmask) && 498 (error = cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp))) { 499 FREE(idp, M_TEMP); 500 return (error); 501 } 502 endsearch = dp->i_size; 503 504 while (idp->curroff < endsearch) { 505 /* 506 * If offset is on a block boundary, 507 * read the next directory block. 508 * Release previous if it exists. 509 */ 510 if ((idp->curroff & bmask) == 0) { 511 if (bp != NULL) 512 brelse(bp); 513 if ((error = 514 cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp)) != 0) 515 break; 516 entryoffsetinblock = 0; 517 } 518 /* 519 * Get pointer to next entry. 520 */ 521 ep = (struct iso_directory_record *) 522 ((char *)bp->b_data + entryoffsetinblock); 523 524 reclen = isonum_711(ep->length); 525 if (reclen == 0) { 526 /* skip to next block, if any */ 527 idp->curroff = 528 (idp->curroff & ~bmask) + imp->logical_block_size; 529 continue; 530 } 531 532 if (reclen < ISO_DIRECTORY_RECORD_SIZE) { 533 error = EINVAL; 534 /* illegal entry, stop */ 535 break; 536 } 537 538 if (entryoffsetinblock + reclen > imp->logical_block_size) { 539 error = EINVAL; 540 /* illegal directory, so stop looking */ 541 break; 542 } 543 544 idp->current.d_namlen = isonum_711(ep->name_len); 545 546 if (reclen < ISO_DIRECTORY_RECORD_SIZE + idp->current.d_namlen) { 547 error = EINVAL; 548 /* illegal entry, stop */ 549 break; 550 } 551 552 if (isonum_711(ep->flags)&2) 553 idp->current.d_fileno = isodirino(ep, imp); 554 else 555 idp->current.d_fileno = dbtob(bp->b_blkno) + 556 entryoffsetinblock; 557 558 idp->curroff += reclen; 559 560 switch (imp->iso_ftype) { 561 case ISO_FTYPE_RRIP: 562 cd9660_rrip_getname(ep,idp->current.d_name, &namelen, 563 &idp->current.d_fileno,imp); 564 idp->current.d_namlen = (u_char)namelen; 565 if (idp->current.d_namlen) 566 error = iso_uiodir(idp,&idp->current,idp->curroff); 567 break; 568 default: /* ISO_FTYPE_DEFAULT || ISO_FTYPE_9660 || ISO_FTYPE_HIGH_SIERRA*/ 569 strcpy(idp->current.d_name,".."); 570 if (idp->current.d_namlen == 1 && ep->name[0] == 0) { 571 idp->current.d_namlen = 1; 572 error = iso_uiodir(idp,&idp->current,idp->curroff); 573 } else if (idp->current.d_namlen == 1 && ep->name[0] == 1) { 574 idp->current.d_namlen = 2; 575 error = iso_uiodir(idp,&idp->current,idp->curroff); 576 } else { 577 isofntrans(ep->name,idp->current.d_namlen, 578 idp->current.d_name, &namelen, 579 imp->iso_ftype == ISO_FTYPE_9660, 580 isonum_711(ep->flags)&4, 581 imp->joliet_level, 582 imp->im_flags, 583 imp->im_d2l); 584 idp->current.d_namlen = (u_char)namelen; 585 if (imp->iso_ftype == ISO_FTYPE_DEFAULT) 586 error = iso_shipdir(idp); 587 else 588 error = iso_uiodir(idp,&idp->current,idp->curroff); 589 } 590 } 591 if (error) 592 break; 593 594 entryoffsetinblock += reclen; 595 } 596 597 if (!error && imp->iso_ftype == ISO_FTYPE_DEFAULT) { 598 idp->current.d_namlen = 0; 599 error = iso_shipdir(idp); 600 } 601 if (error < 0) 602 error = 0; 603 604 if (ap->a_ncookies != NULL) { 605 if (error) 606 free(cookies, M_TEMP); 607 else { 608 /* 609 * Work out the number of cookies actually used. 610 */ 611 *ap->a_ncookies = ncookies - idp->ncookies; 612 *ap->a_cookies = cookies; 613 } 614 } 615 616 if (bp) 617 brelse (bp); 618 619 uio->uio_offset = idp->uio_off; 620 *ap->a_eofflag = idp->eofflag; 621 622 FREE(idp, M_TEMP); 623 624 return (error); 625 } 626 627 /* 628 * Return target name of a symbolic link 629 * Shouldn't we get the parent vnode and read the data from there? 630 * This could eventually result in deadlocks in cd9660_lookup. 631 * But otherwise the block read here is in the block buffer two times. 632 */ 633 typedef struct iso_directory_record ISODIR; 634 typedef struct iso_node ISONODE; 635 typedef struct iso_mnt ISOMNT; 636 static int 637 cd9660_readlink(ap) 638 struct vop_readlink_args /* { 639 struct vnode *a_vp; 640 struct uio *a_uio; 641 struct ucred *a_cred; 642 } */ *ap; 643 { 644 ISONODE *ip; 645 ISODIR *dirp; 646 ISOMNT *imp; 647 struct buf *bp; 648 struct uio *uio; 649 u_short symlen; 650 int error; 651 char *symname; 652 653 ip = VTOI(ap->a_vp); 654 imp = ip->i_mnt; 655 uio = ap->a_uio; 656 657 if (imp->iso_ftype != ISO_FTYPE_RRIP) 658 return (EINVAL); 659 660 /* 661 * Get parents directory record block that this inode included. 662 */ 663 error = bread(imp->im_devvp, 664 (ip->i_number >> imp->im_bshift) << 665 (imp->im_bshift - DEV_BSHIFT), 666 imp->logical_block_size, NOCRED, &bp); 667 if (error) { 668 brelse(bp); 669 return (EINVAL); 670 } 671 672 /* 673 * Setup the directory pointer for this inode 674 */ 675 dirp = (ISODIR *)(bp->b_data + (ip->i_number & imp->im_bmask)); 676 677 /* 678 * Just make sure, we have a right one.... 679 * 1: Check not cross boundary on block 680 */ 681 if ((ip->i_number & imp->im_bmask) + isonum_711(dirp->length) 682 > (unsigned)imp->logical_block_size) { 683 brelse(bp); 684 return (EINVAL); 685 } 686 687 /* 688 * Now get a buffer 689 * Abuse a namei buffer for now. 690 */ 691 if (uio->uio_segflg == UIO_SYSSPACE) 692 symname = uio->uio_iov->iov_base; 693 else 694 symname = uma_zalloc(namei_zone, M_WAITOK); 695 696 /* 697 * Ok, we just gathering a symbolic name in SL record. 698 */ 699 if (cd9660_rrip_getsymname(dirp, symname, &symlen, imp) == 0) { 700 if (uio->uio_segflg != UIO_SYSSPACE) 701 uma_zfree(namei_zone, symname); 702 brelse(bp); 703 return (EINVAL); 704 } 705 /* 706 * Don't forget before you leave from home ;-) 707 */ 708 brelse(bp); 709 710 /* 711 * return with the symbolic name to caller's. 712 */ 713 if (uio->uio_segflg != UIO_SYSSPACE) { 714 error = uiomove(symname, symlen, uio); 715 uma_zfree(namei_zone, symname); 716 return (error); 717 } 718 uio->uio_resid -= symlen; 719 uio->uio_iov->iov_base = (char *)uio->uio_iov->iov_base + symlen; 720 uio->uio_iov->iov_len -= symlen; 721 return (0); 722 } 723 724 /* 725 * Calculate the logical to physical mapping if not done already, 726 * then call the device strategy routine. 727 */ 728 static int 729 cd9660_strategy(ap) 730 struct vop_strategy_args /* { 731 struct buf *a_vp; 732 struct buf *a_bp; 733 } */ *ap; 734 { 735 struct buf *bp = ap->a_bp; 736 struct vnode *vp = ap->a_vp; 737 struct iso_node *ip; 738 struct bufobj *bo; 739 740 ip = VTOI(vp); 741 if (vp->v_type == VBLK || vp->v_type == VCHR) 742 panic("cd9660_strategy: spec"); 743 if (bp->b_blkno == bp->b_lblkno) { 744 bp->b_blkno = (ip->iso_start + bp->b_lblkno) << 745 (ip->i_mnt->im_bshift - DEV_BSHIFT); 746 if ((long)bp->b_blkno == -1) /* XXX: cut&paste junk ? */ 747 clrbuf(bp); 748 } 749 if ((long)bp->b_blkno == -1) { /* XXX: cut&paste junk ? */ 750 bufdone(bp); 751 return (0); 752 } 753 bp->b_iooffset = dbtob(bp->b_blkno); 754 bo = ip->i_mnt->im_bo; 755 BO_STRATEGY(bo, bp); 756 return (0); 757 } 758 759 /* 760 * Return POSIX pathconf information applicable to cd9660 filesystems. 761 */ 762 static int 763 cd9660_pathconf(ap) 764 struct vop_pathconf_args /* { 765 struct vnode *a_vp; 766 int a_name; 767 register_t *a_retval; 768 } */ *ap; 769 { 770 771 switch (ap->a_name) { 772 case _PC_LINK_MAX: 773 *ap->a_retval = 1; 774 return (0); 775 case _PC_NAME_MAX: 776 if (VTOI(ap->a_vp)->i_mnt->iso_ftype == ISO_FTYPE_RRIP) 777 *ap->a_retval = NAME_MAX; 778 else 779 *ap->a_retval = 37; 780 return (0); 781 case _PC_PATH_MAX: 782 *ap->a_retval = PATH_MAX; 783 return (0); 784 case _PC_PIPE_BUF: 785 *ap->a_retval = PIPE_BUF; 786 return (0); 787 case _PC_CHOWN_RESTRICTED: 788 *ap->a_retval = 1; 789 return (0); 790 case _PC_NO_TRUNC: 791 *ap->a_retval = 1; 792 return (0); 793 default: 794 return (EINVAL); 795 } 796 /* NOTREACHED */ 797 } 798 799 /* 800 * Global vfs data structures for cd9660 801 */ 802 struct vop_vector cd9660_vnodeops = { 803 .vop_default = &default_vnodeops, 804 .vop_open = cd9660_open, 805 .vop_access = cd9660_access, 806 .vop_bmap = cd9660_bmap, 807 .vop_cachedlookup = cd9660_lookup, 808 .vop_getattr = cd9660_getattr, 809 .vop_inactive = cd9660_inactive, 810 .vop_ioctl = cd9660_ioctl, 811 .vop_lookup = vfs_cache_lookup, 812 .vop_pathconf = cd9660_pathconf, 813 .vop_read = cd9660_read, 814 .vop_readdir = cd9660_readdir, 815 .vop_readlink = cd9660_readlink, 816 .vop_reclaim = cd9660_reclaim, 817 .vop_setattr = cd9660_setattr, 818 .vop_strategy = cd9660_strategy, 819 }; 820 821 /* 822 * Special device vnode ops 823 */ 824 825 struct vop_vector cd9660_fifoops = { 826 .vop_default = &fifo_specops, 827 .vop_access = cd9660_access, 828 .vop_getattr = cd9660_getattr, 829 .vop_inactive = cd9660_inactive, 830 .vop_reclaim = cd9660_reclaim, 831 .vop_setattr = cd9660_setattr, 832 }; 833