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