1 /* $NetBSD: cd9660_vnops.c,v 1.48 2014/06/14 07:39:29 hannken Exp $ */ 2 3 /*- 4 * Copyright (c) 1994 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley 8 * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension 9 * Support code is derived from software contributed to Berkeley 10 * by Atsushi Murai (amurai@spec.co.jp). 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 3. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * @(#)cd9660_vnops.c 8.15 (Berkeley) 5/27/95 37 */ 38 39 #include <sys/cdefs.h> 40 __KERNEL_RCSID(0, "$NetBSD: cd9660_vnops.c,v 1.48 2014/06/14 07:39:29 hannken Exp $"); 41 42 #include <sys/param.h> 43 #include <sys/systm.h> 44 #include <sys/namei.h> 45 #include <sys/resourcevar.h> 46 #include <sys/kernel.h> 47 #include <sys/file.h> 48 #include <sys/stat.h> 49 #include <sys/buf.h> 50 #include <sys/proc.h> 51 #include <sys/mount.h> 52 #include <sys/vnode.h> 53 #include <sys/malloc.h> 54 #include <sys/dirent.h> 55 #include <sys/kauth.h> 56 57 #include <miscfs/fifofs/fifo.h> 58 #include <miscfs/genfs/genfs.h> 59 #include <miscfs/specfs/specdev.h> 60 61 #include <fs/cd9660/iso.h> 62 #include <fs/cd9660/cd9660_extern.h> 63 #include <fs/cd9660/cd9660_node.h> 64 #include <fs/cd9660/iso_rrip.h> 65 #include <fs/cd9660/cd9660_mount.h> 66 67 /* 68 * Structure for reading directories 69 */ 70 struct isoreaddir { 71 struct dirent saveent; 72 struct dirent assocent; 73 struct dirent current; 74 off_t saveoff; 75 off_t assocoff; 76 off_t curroff; 77 struct uio *uio; 78 off_t uio_off; 79 int eofflag; 80 off_t *cookies; 81 int ncookies; 82 }; 83 84 int iso_uiodir(struct isoreaddir *, struct dirent *, off_t); 85 int iso_shipdir(struct isoreaddir *); 86 87 static int 88 cd9660_check_possible(struct vnode *vp, struct iso_node *ip, mode_t mode) 89 { 90 91 /* 92 * Disallow write attempts unless the file is a socket, 93 * fifo, or a block or character device resident on the 94 * file system. 95 */ 96 if (mode & VWRITE) { 97 switch (vp->v_type) { 98 case VDIR: 99 case VLNK: 100 case VREG: 101 return (EROFS); 102 default: 103 break; 104 } 105 } 106 107 return 0; 108 } 109 110 /* 111 * Check mode permission on inode pointer. Mode is READ, WRITE or EXEC. 112 * The mode is shifted to select the owner/group/other fields. The 113 * super user is granted all permissions. 114 */ 115 static int 116 cd9660_check_permitted(struct vnode *vp, struct iso_node *ip, mode_t mode, 117 kauth_cred_t cred) 118 { 119 120 return kauth_authorize_vnode(cred, KAUTH_ACCESS_ACTION(mode, 121 vp->v_type, ip->inode.iso_mode & ALLPERMS), vp, NULL, 122 genfs_can_access(vp->v_type, ip->inode.iso_mode & ALLPERMS, 123 ip->inode.iso_uid, ip->inode.iso_gid, mode, cred)); 124 } 125 126 int 127 cd9660_access(void *v) 128 { 129 struct vop_access_args /* { 130 struct vnode *a_vp; 131 int a_mode; 132 kauth_cred_t a_cred; 133 } */ *ap = v; 134 struct vnode *vp = ap->a_vp; 135 struct iso_node *ip = VTOI(vp); 136 int error; 137 138 error = cd9660_check_possible(vp, ip, ap->a_mode); 139 if (error) 140 return error; 141 142 error = cd9660_check_permitted(vp, ip, ap->a_mode, ap->a_cred); 143 144 return error; 145 } 146 147 int 148 cd9660_getattr(void *v) 149 { 150 struct vop_getattr_args /* { 151 struct vnode *a_vp; 152 struct vattr *a_vap; 153 kauth_cred_t a_cred; 154 } */ *ap = v; 155 struct vnode *vp = ap->a_vp; 156 struct iso_node *ip = VTOI(vp); 157 struct vattr *vap = ap->a_vap; 158 159 vap->va_fsid = ip->i_dev; 160 vap->va_fileid = ip->i_number; 161 162 vap->va_mode = ip->inode.iso_mode & ALLPERMS; 163 vap->va_nlink = ip->inode.iso_links; 164 vap->va_uid = ip->inode.iso_uid; 165 vap->va_gid = ip->inode.iso_gid; 166 vap->va_atime = ip->inode.iso_atime; 167 vap->va_mtime = ip->inode.iso_mtime; 168 vap->va_ctime = ip->inode.iso_ctime; 169 vap->va_rdev = ip->inode.iso_rdev; 170 171 vap->va_size = (u_quad_t) ip->i_size; 172 if (ip->i_size == 0 && vp->v_type == VLNK) { 173 struct vop_readlink_args rdlnk; 174 struct iovec aiov; 175 struct uio auio; 176 char *cp; 177 178 cp = (char *)malloc(MAXPATHLEN, M_TEMP, M_WAITOK); 179 aiov.iov_base = cp; 180 aiov.iov_len = MAXPATHLEN; 181 auio.uio_iov = &aiov; 182 auio.uio_iovcnt = 1; 183 auio.uio_offset = 0; 184 auio.uio_rw = UIO_READ; 185 auio.uio_resid = MAXPATHLEN; 186 UIO_SETUP_SYSSPACE(&auio); 187 rdlnk.a_uio = &auio; 188 rdlnk.a_vp = ap->a_vp; 189 rdlnk.a_cred = ap->a_cred; 190 if (cd9660_readlink(&rdlnk) == 0) 191 vap->va_size = MAXPATHLEN - auio.uio_resid; 192 free(cp, M_TEMP); 193 } 194 vap->va_flags = 0; 195 vap->va_gen = 1; 196 vap->va_blocksize = ip->i_mnt->logical_block_size; 197 vap->va_bytes = (u_quad_t) ip->i_size; 198 vap->va_type = vp->v_type; 199 return (0); 200 } 201 202 /* 203 * Vnode op for reading. 204 */ 205 int 206 cd9660_read(void *v) 207 { 208 struct vop_read_args /* { 209 struct vnode *a_vp; 210 struct uio *a_uio; 211 int a_ioflag; 212 kauth_cred_t a_cred; 213 } */ *ap = v; 214 struct vnode *vp = ap->a_vp; 215 struct uio *uio = ap->a_uio; 216 struct iso_node *ip = VTOI(vp); 217 struct iso_mnt *imp; 218 struct buf *bp; 219 daddr_t lbn, rablock; 220 off_t diff; 221 int rasize, error = 0; 222 long size, n, on; 223 224 if (uio->uio_resid == 0) 225 return (0); 226 if (uio->uio_offset < 0) 227 return (EINVAL); 228 if (uio->uio_offset >= ip->i_size) 229 return 0; 230 ip->i_flag |= IN_ACCESS; 231 imp = ip->i_mnt; 232 233 if (vp->v_type == VREG) { 234 const int advice = IO_ADV_DECODE(ap->a_ioflag); 235 error = 0; 236 237 while (uio->uio_resid > 0) { 238 vsize_t bytelen = MIN(ip->i_size - uio->uio_offset, 239 uio->uio_resid); 240 241 if (bytelen == 0) 242 break; 243 error = ubc_uiomove(&vp->v_uobj, uio, bytelen, advice, 244 UBC_READ | UBC_PARTIALOK | UBC_UNMAP_FLAG(vp)); 245 if (error) 246 break; 247 } 248 goto out; 249 } 250 251 do { 252 lbn = cd9660_lblkno(imp, uio->uio_offset); 253 on = cd9660_blkoff(imp, uio->uio_offset); 254 n = MIN(imp->logical_block_size - on, uio->uio_resid); 255 diff = (off_t)ip->i_size - uio->uio_offset; 256 if (diff <= 0) 257 return (0); 258 if (diff < n) 259 n = diff; 260 size = cd9660_blksize(imp, ip, lbn); 261 rablock = lbn + 1; 262 if (cd9660_lblktosize(imp, rablock) < ip->i_size) { 263 rasize = cd9660_blksize(imp, ip, rablock); 264 error = breadn(vp, lbn, size, &rablock, 265 &rasize, 1, NOCRED, 0, &bp); 266 } else { 267 error = bread(vp, lbn, size, NOCRED, 0, &bp); 268 } 269 if (error) { 270 return (error); 271 } 272 n = MIN(n, size - bp->b_resid); 273 274 error = uiomove((char *)bp->b_data + on, (int)n, uio); 275 brelse(bp, 0); 276 } while (error == 0 && uio->uio_resid > 0 && n != 0); 277 278 out: 279 return (error); 280 } 281 282 int 283 iso_uiodir(struct isoreaddir *idp, struct dirent *dp, off_t off) 284 { 285 int error; 286 287 dp->d_name[dp->d_namlen] = 0; 288 dp->d_reclen = _DIRENT_SIZE(dp); 289 290 if (idp->uio->uio_resid < dp->d_reclen) { 291 idp->eofflag = 0; 292 return (-1); 293 } 294 295 if (idp->cookies) { 296 if (idp->ncookies <= 0) { 297 idp->eofflag = 0; 298 return (-1); 299 } 300 301 *idp->cookies++ = off; 302 --idp->ncookies; 303 } 304 305 if ((error = uiomove(dp, dp->d_reclen, idp->uio)) != 0) 306 return (error); 307 idp->uio_off = off; 308 return (0); 309 } 310 311 int 312 iso_shipdir(struct isoreaddir *idp) 313 { 314 struct dirent *dp; 315 int cl, sl, assoc; 316 int error; 317 char *cname, *sname; 318 319 cl = idp->current.d_namlen; 320 cname = idp->current.d_name; 321 322 if ((assoc = cl > 1 && *cname == ASSOCCHAR)) { 323 cl--; 324 cname++; 325 } 326 327 dp = &idp->saveent; 328 sname = dp->d_name; 329 if (!(sl = dp->d_namlen)) { 330 dp = &idp->assocent; 331 sname = dp->d_name + 1; 332 sl = dp->d_namlen - 1; 333 } 334 if (sl > 0) { 335 if (sl != cl 336 || memcmp(sname, cname, sl)) { 337 if (idp->assocent.d_namlen) { 338 error = iso_uiodir(idp, &idp->assocent, 339 idp->assocoff); 340 if (error) 341 return (error); 342 idp->assocent.d_namlen = 0; 343 } 344 if (idp->saveent.d_namlen) { 345 error = iso_uiodir(idp, &idp->saveent, 346 idp->saveoff); 347 if (error) 348 return (error); 349 idp->saveent.d_namlen = 0; 350 } 351 } 352 } 353 idp->current.d_reclen = _DIRENT_SIZE(&idp->current); 354 if (assoc) { 355 idp->assocoff = idp->curroff; 356 memcpy(&idp->assocent, &idp->current, idp->current.d_reclen); 357 } else { 358 idp->saveoff = idp->curroff; 359 memcpy(&idp->saveent, &idp->current, idp->current.d_reclen); 360 } 361 return (0); 362 } 363 364 /* 365 * Vnode op for readdir 366 */ 367 int 368 cd9660_readdir(void *v) 369 { 370 struct vop_readdir_args /* { 371 struct vnode *a_vp; 372 struct uio *a_uio; 373 kauth_cred_t a_cred; 374 int *a_eofflag; 375 off_t **a_cookies; 376 int *a_ncookies; 377 } */ *ap = v; 378 struct uio *uio = ap->a_uio; 379 struct isoreaddir *idp; 380 struct vnode *vdp = ap->a_vp; 381 struct iso_node *dp; 382 struct iso_mnt *imp; 383 struct buf *bp = NULL; 384 struct iso_directory_record *ep; 385 int entryoffsetinblock; 386 doff_t endsearch; 387 u_long bmask; 388 int error = 0; 389 int reclen; 390 u_short namelen; 391 off_t *cookies = NULL; 392 int ncookies = 0; 393 394 if (vdp->v_type != VDIR) 395 return (ENOTDIR); 396 397 dp = VTOI(vdp); 398 imp = dp->i_mnt; 399 bmask = imp->im_bmask; 400 401 idp = (struct isoreaddir *)malloc(sizeof(*idp), M_TEMP, M_WAITOK); 402 idp->saveent.d_namlen = idp->assocent.d_namlen = 0; 403 /* 404 * XXX 405 * Is it worth trying to figure out the type? 406 */ 407 idp->saveent.d_type = idp->assocent.d_type = idp->current.d_type = 408 DT_UNKNOWN; 409 idp->uio = uio; 410 if (ap->a_ncookies == NULL) 411 idp->cookies = NULL; 412 else { 413 ncookies = uio->uio_resid / _DIRENT_MINSIZE((struct dirent *)0); 414 cookies = malloc(ncookies * sizeof(off_t), M_TEMP, M_WAITOK); 415 idp->cookies = cookies; 416 idp->ncookies = ncookies; 417 } 418 idp->eofflag = 1; 419 idp->curroff = uio->uio_offset; 420 421 if ((entryoffsetinblock = idp->curroff & bmask) && 422 (error = cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp))) { 423 free(idp, M_TEMP); 424 return (error); 425 } 426 endsearch = dp->i_size; 427 428 while (idp->curroff < endsearch) { 429 /* 430 * If offset is on a block boundary, 431 * read the next directory block. 432 * Release previous if it exists. 433 */ 434 if ((idp->curroff & bmask) == 0) { 435 if (bp != NULL) 436 brelse(bp, 0); 437 error = cd9660_blkatoff(vdp, (off_t)idp->curroff, 438 NULL, &bp); 439 if (error) 440 break; 441 entryoffsetinblock = 0; 442 } 443 /* 444 * Get pointer to next entry. 445 */ 446 KASSERT(bp != NULL); 447 ep = (struct iso_directory_record *) 448 ((char *)bp->b_data + entryoffsetinblock); 449 450 reclen = isonum_711(ep->length); 451 if (reclen == 0) { 452 /* skip to next block, if any */ 453 idp->curroff = 454 (idp->curroff & ~bmask) + imp->logical_block_size; 455 continue; 456 } 457 458 if (reclen < ISO_DIRECTORY_RECORD_SIZE) { 459 error = EINVAL; 460 /* illegal entry, stop */ 461 break; 462 } 463 464 if (entryoffsetinblock + reclen > imp->logical_block_size) { 465 error = EINVAL; 466 /* illegal directory, so stop looking */ 467 break; 468 } 469 470 idp->current.d_namlen = isonum_711(ep->name_len); 471 472 if (reclen < ISO_DIRECTORY_RECORD_SIZE + idp->current.d_namlen) { 473 error = EINVAL; 474 /* illegal entry, stop */ 475 break; 476 } 477 478 if (isonum_711(ep->flags)&2) 479 idp->current.d_fileno = isodirino(ep, imp); 480 else 481 idp->current.d_fileno = dbtob(bp->b_blkno) + 482 entryoffsetinblock; 483 484 idp->curroff += reclen; 485 486 switch (imp->iso_ftype) { 487 case ISO_FTYPE_RRIP: 488 cd9660_rrip_getname(ep, idp->current.d_name, &namelen, 489 &idp->current.d_fileno, imp); 490 idp->current.d_namlen = (u_char)namelen; 491 if (idp->current.d_namlen) 492 error = iso_uiodir(idp, &idp->current, 493 idp->curroff); 494 break; 495 default: /* ISO_FTYPE_DEFAULT || ISO_FTYPE_9660 */ 496 isofntrans(ep->name, idp->current.d_namlen, 497 idp->current.d_name, &namelen, 498 imp->iso_ftype == ISO_FTYPE_9660, 499 (imp->im_flags & ISOFSMNT_NOCASETRANS) == 0, 500 isonum_711(ep->flags)&4, 501 imp->im_joliet_level); 502 switch (idp->current.d_name[0]) { 503 case 0: 504 idp->current.d_name[0] = '.'; 505 idp->current.d_namlen = 1; 506 error = iso_uiodir(idp, &idp->current, 507 idp->curroff); 508 break; 509 case 1: 510 strlcpy(idp->current.d_name, "..", 511 sizeof(idp->current.d_name)); 512 idp->current.d_namlen = 2; 513 error = iso_uiodir(idp, &idp->current, 514 idp->curroff); 515 break; 516 default: 517 idp->current.d_namlen = (u_char)namelen; 518 if (imp->iso_ftype == ISO_FTYPE_DEFAULT) 519 error = iso_shipdir(idp); 520 else 521 error = iso_uiodir(idp, &idp->current, 522 idp->curroff); 523 break; 524 } 525 } 526 if (error) 527 break; 528 529 entryoffsetinblock += reclen; 530 } 531 532 if (!error && imp->iso_ftype == ISO_FTYPE_DEFAULT) { 533 idp->current.d_namlen = 0; 534 error = iso_shipdir(idp); 535 } 536 if (error < 0) 537 error = 0; 538 539 if (ap->a_ncookies != NULL) { 540 if (error) 541 free(cookies, M_TEMP); 542 else { 543 /* 544 * Work out the number of cookies actually used. 545 */ 546 *ap->a_ncookies = ncookies - idp->ncookies; 547 *ap->a_cookies = cookies; 548 } 549 } 550 551 if (bp) 552 brelse(bp, 0); 553 554 uio->uio_offset = idp->uio_off; 555 *ap->a_eofflag = idp->eofflag; 556 557 free(idp, M_TEMP); 558 559 return (error); 560 } 561 562 /* 563 * Return target name of a symbolic link 564 * Shouldn't we get the parent vnode and read the data from there? 565 * This could eventually result in deadlocks in cd9660_lookup. 566 * But otherwise the block read here is in the block buffer two times. 567 */ 568 typedef struct iso_directory_record ISODIR; 569 typedef struct iso_node ISONODE; 570 typedef struct iso_mnt ISOMNT; 571 572 int 573 cd9660_readlink(void *v) 574 { 575 struct vop_readlink_args /* { 576 struct vnode *a_vp; 577 struct uio *a_uio; 578 kauth_cred_t a_cred; 579 } */ *ap = v; 580 ISONODE *ip; 581 ISODIR *dirp; 582 ISOMNT *imp; 583 struct buf *bp; 584 struct uio *uio; 585 u_short symlen; 586 int error; 587 char *symname; 588 bool use_pnbuf; 589 590 ip = VTOI(ap->a_vp); 591 imp = ip->i_mnt; 592 uio = ap->a_uio; 593 594 if (imp->iso_ftype != ISO_FTYPE_RRIP) 595 return (EINVAL); 596 597 /* 598 * Get parents directory record block that this inode included. 599 */ 600 error = bread(imp->im_devvp, 601 (ip->i_number >> imp->im_bshift) << 602 (imp->im_bshift - DEV_BSHIFT), 603 imp->logical_block_size, NOCRED, 0, &bp); 604 if (error) { 605 return (EINVAL); 606 } 607 608 /* 609 * Setup the directory pointer for this inode 610 */ 611 dirp = (ISODIR *)((char *)bp->b_data + (ip->i_number & imp->im_bmask)); 612 613 /* 614 * Just make sure, we have a right one.... 615 * 1: Check not cross boundary on block 616 */ 617 if ((ip->i_number & imp->im_bmask) + isonum_711(dirp->length) 618 > imp->logical_block_size) { 619 brelse(bp, 0); 620 return (EINVAL); 621 } 622 623 /* 624 * Now get a buffer 625 * Abuse a namei buffer for now. 626 */ 627 use_pnbuf = !VMSPACE_IS_KERNEL_P(uio->uio_vmspace) || 628 uio->uio_iov->iov_len < MAXPATHLEN; 629 if (use_pnbuf) { 630 symname = PNBUF_GET(); 631 } else { 632 symname = uio->uio_iov->iov_base; 633 } 634 635 /* 636 * Ok, we just gathering a symbolic name in SL record. 637 */ 638 if (cd9660_rrip_getsymname(dirp, symname, &symlen, imp) == 0) { 639 if (use_pnbuf) { 640 PNBUF_PUT(symname); 641 } 642 brelse(bp, 0); 643 return (EINVAL); 644 } 645 /* 646 * Don't forget before you leave from home ;-) 647 */ 648 brelse(bp, 0); 649 650 /* 651 * return with the symbolic name to caller's. 652 */ 653 if (use_pnbuf) { 654 error = uiomove(symname, symlen, uio); 655 PNBUF_PUT(symname); 656 return (error); 657 } 658 uio->uio_resid -= symlen; 659 uio->uio_iov->iov_base = (char *)uio->uio_iov->iov_base + symlen; 660 uio->uio_iov->iov_len -= symlen; 661 return (0); 662 } 663 664 int 665 cd9660_link(void *v) 666 { 667 struct vop_link_args /* { 668 struct vnode *a_dvp; 669 struct vnode *a_vp; 670 struct componentname *a_cnp; 671 } */ *ap = v; 672 673 VOP_ABORTOP(ap->a_dvp, ap->a_cnp); 674 vput(ap->a_dvp); 675 return (EROFS); 676 } 677 678 int 679 cd9660_symlink(void *v) 680 { 681 struct vop_symlink_v3_args /* { 682 struct vnode *a_dvp; 683 struct vnode **a_vpp; 684 struct componentname *a_cnp; 685 struct vattr *a_vap; 686 char *a_target; 687 } */ *ap = v; 688 689 VOP_ABORTOP(ap->a_dvp, ap->a_cnp); 690 return (EROFS); 691 } 692 693 /* 694 * Calculate the logical to physical mapping if not done already, 695 * then call the device strategy routine. 696 */ 697 int 698 cd9660_strategy(void *v) 699 { 700 struct vop_strategy_args /* { 701 struct vnode *a_vp; 702 struct buf *a_bp; 703 } */ *ap = v; 704 struct buf *bp = ap->a_bp; 705 struct vnode *vp = ap->a_vp; 706 struct iso_node *ip; 707 int error; 708 709 ip = VTOI(vp); 710 if (vp->v_type == VBLK || vp->v_type == VCHR) 711 panic("cd9660_strategy: spec"); 712 if (bp->b_blkno == bp->b_lblkno) { 713 error = VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno, NULL); 714 if (error) { 715 bp->b_error = error; 716 biodone(bp); 717 return (error); 718 } 719 if ((long)bp->b_blkno == -1) 720 clrbuf(bp); 721 } 722 if ((long)bp->b_blkno == -1) { 723 biodone(bp); 724 return (0); 725 } 726 vp = ip->i_mnt->im_devvp; 727 return (VOP_STRATEGY(vp, bp)); 728 } 729 730 /* 731 * Print out the contents of an inode. 732 */ 733 /*ARGSUSED*/ 734 int 735 cd9660_print(void *v) 736 { 737 738 printf("tag VT_ISOFS, isofs vnode\n"); 739 return (0); 740 } 741 742 /* 743 * Return POSIX pathconf information applicable to cd9660 filesystems. 744 */ 745 int 746 cd9660_pathconf(void *v) 747 { 748 struct vop_pathconf_args /* { 749 struct vnode *a_vp; 750 int a_name; 751 register_t *a_retval; 752 } */ *ap = v; 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 = ISO_MAXNAMLEN; 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 case _PC_SYNC_IO: 776 *ap->a_retval = 1; 777 return (0); 778 case _PC_FILESIZEBITS: 779 *ap->a_retval = 32; 780 return (0); 781 default: 782 return (EINVAL); 783 } 784 /* NOTREACHED */ 785 } 786 787 /* 788 * Allow changing the size for special files (and fifos). 789 */ 790 int 791 cd9660_setattr(void *v) 792 { 793 struct vop_setattr_args /* { 794 struct vnodeop_desc *a_desc; 795 struct vnode *a_vp; 796 struct vattr *a_vap; 797 kauth_cred_t a_cred; 798 struct proc *a_p; 799 } */ *ap = v; 800 struct vattr *vap = ap->a_vap; 801 struct vnode *vp = ap->a_vp; 802 803 /* 804 * Only size is changeable. 805 */ 806 if (vap->va_type != VNON 807 || vap->va_nlink != (nlink_t)VNOVAL 808 || vap->va_fsid != VNOVAL 809 || vap->va_fileid != VNOVAL 810 || vap->va_blocksize != VNOVAL 811 || vap->va_rdev != (dev_t)VNOVAL 812 || (int)vap->va_bytes != VNOVAL 813 || vap->va_gen != VNOVAL 814 || vap->va_flags != VNOVAL 815 || vap->va_uid != (uid_t)VNOVAL 816 || vap->va_gid != (gid_t)VNOVAL 817 || vap->va_atime.tv_sec != VNOVAL 818 || vap->va_mtime.tv_sec != VNOVAL 819 || vap->va_mode != (mode_t)VNOVAL) 820 return EOPNOTSUPP; 821 822 if (vap->va_size != VNOVAL 823 && vp->v_type != VCHR 824 && vp->v_type != VBLK 825 && vp->v_type != VFIFO) 826 return EOPNOTSUPP; 827 828 return 0; 829 } 830 831 /* 832 * Global vfs data structures for isofs 833 */ 834 #define cd9660_create genfs_eopnotsupp 835 #define cd9660_mknod genfs_eopnotsupp 836 #define cd9660_write genfs_eopnotsupp 837 #define cd9660_fsync genfs_nullop 838 #define cd9660_remove genfs_eopnotsupp 839 #define cd9660_rename genfs_eopnotsupp 840 #define cd9660_mkdir genfs_eopnotsupp 841 #define cd9660_rmdir genfs_eopnotsupp 842 #define cd9660_advlock genfs_einval 843 #define cd9660_bwrite genfs_eopnotsupp 844 #define cd9660_revoke genfs_revoke 845 846 /* 847 * Global vfs data structures for cd9660 848 */ 849 int (**cd9660_vnodeop_p)(void *); 850 const struct vnodeopv_entry_desc cd9660_vnodeop_entries[] = { 851 { &vop_default_desc, vn_default_error }, 852 { &vop_lookup_desc, cd9660_lookup }, /* lookup */ 853 { &vop_create_desc, cd9660_create }, /* create */ 854 { &vop_mknod_desc, cd9660_mknod }, /* mknod */ 855 { &vop_open_desc, cd9660_open }, /* open */ 856 { &vop_close_desc, cd9660_close }, /* close */ 857 { &vop_access_desc, cd9660_access }, /* access */ 858 { &vop_getattr_desc, cd9660_getattr }, /* getattr */ 859 { &vop_setattr_desc, cd9660_setattr }, /* setattr */ 860 { &vop_read_desc, cd9660_read }, /* read */ 861 { &vop_write_desc, cd9660_write }, /* write */ 862 { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */ 863 { &vop_ioctl_desc, cd9660_ioctl }, /* ioctl */ 864 { &vop_poll_desc, cd9660_poll }, /* poll */ 865 { &vop_revoke_desc, cd9660_revoke }, /* revoke */ 866 { &vop_mmap_desc, cd9660_mmap }, /* mmap */ 867 { &vop_fsync_desc, cd9660_fsync }, /* fsync */ 868 { &vop_seek_desc, cd9660_seek }, /* seek */ 869 { &vop_remove_desc, cd9660_remove }, /* remove */ 870 { &vop_link_desc, cd9660_link }, /* link */ 871 { &vop_rename_desc, cd9660_rename }, /* rename */ 872 { &vop_mkdir_desc, cd9660_mkdir }, /* mkdir */ 873 { &vop_rmdir_desc, cd9660_rmdir }, /* rmdir */ 874 { &vop_symlink_desc, cd9660_symlink }, /* symlink */ 875 { &vop_readdir_desc, cd9660_readdir }, /* readdir */ 876 { &vop_readlink_desc, cd9660_readlink }, /* readlink */ 877 { &vop_abortop_desc, cd9660_abortop }, /* abortop */ 878 { &vop_inactive_desc, cd9660_inactive }, /* inactive */ 879 { &vop_reclaim_desc, cd9660_reclaim }, /* reclaim */ 880 { &vop_lock_desc, genfs_lock }, /* lock */ 881 { &vop_unlock_desc, genfs_unlock }, /* unlock */ 882 { &vop_bmap_desc, cd9660_bmap }, /* bmap */ 883 { &vop_strategy_desc, cd9660_strategy }, /* strategy */ 884 { &vop_print_desc, cd9660_print }, /* print */ 885 { &vop_islocked_desc, genfs_islocked }, /* islocked */ 886 { &vop_pathconf_desc, cd9660_pathconf }, /* pathconf */ 887 { &vop_advlock_desc, cd9660_advlock }, /* advlock */ 888 { &vop_bwrite_desc, vn_bwrite }, /* bwrite */ 889 { &vop_getpages_desc, genfs_getpages }, /* getpages */ 890 { &vop_putpages_desc, genfs_putpages }, /* putpages */ 891 { NULL, NULL } 892 }; 893 const struct vnodeopv_desc cd9660_vnodeop_opv_desc = 894 { &cd9660_vnodeop_p, cd9660_vnodeop_entries }; 895 896 /* 897 * Special device vnode ops 898 */ 899 int (**cd9660_specop_p)(void *); 900 const struct vnodeopv_entry_desc cd9660_specop_entries[] = { 901 { &vop_default_desc, vn_default_error }, 902 { &vop_lookup_desc, spec_lookup }, /* lookup */ 903 { &vop_create_desc, spec_create }, /* create */ 904 { &vop_mknod_desc, spec_mknod }, /* mknod */ 905 { &vop_open_desc, spec_open }, /* open */ 906 { &vop_close_desc, spec_close }, /* close */ 907 { &vop_access_desc, cd9660_access }, /* access */ 908 { &vop_getattr_desc, cd9660_getattr }, /* getattr */ 909 { &vop_setattr_desc, cd9660_setattr }, /* setattr */ 910 { &vop_read_desc, spec_read }, /* read */ 911 { &vop_write_desc, spec_write }, /* write */ 912 { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */ 913 { &vop_ioctl_desc, spec_ioctl }, /* ioctl */ 914 { &vop_poll_desc, spec_poll }, /* poll */ 915 { &vop_kqfilter_desc, spec_kqfilter }, /* kqfilter */ 916 { &vop_revoke_desc, spec_revoke }, /* revoke */ 917 { &vop_mmap_desc, spec_mmap }, /* mmap */ 918 { &vop_fsync_desc, spec_fsync }, /* fsync */ 919 { &vop_seek_desc, spec_seek }, /* seek */ 920 { &vop_remove_desc, spec_remove }, /* remove */ 921 { &vop_link_desc, spec_link }, /* link */ 922 { &vop_rename_desc, spec_rename }, /* rename */ 923 { &vop_mkdir_desc, spec_mkdir }, /* mkdir */ 924 { &vop_rmdir_desc, spec_rmdir }, /* rmdir */ 925 { &vop_symlink_desc, spec_symlink }, /* symlink */ 926 { &vop_readdir_desc, spec_readdir }, /* readdir */ 927 { &vop_readlink_desc, spec_readlink }, /* readlink */ 928 { &vop_abortop_desc, spec_abortop }, /* abortop */ 929 { &vop_inactive_desc, cd9660_inactive }, /* inactive */ 930 { &vop_reclaim_desc, cd9660_reclaim }, /* reclaim */ 931 { &vop_lock_desc, genfs_lock }, /* lock */ 932 { &vop_unlock_desc, genfs_unlock }, /* unlock */ 933 { &vop_bmap_desc, spec_bmap }, /* bmap */ 934 { &vop_strategy_desc, spec_strategy }, /* strategy */ 935 { &vop_print_desc, cd9660_print }, /* print */ 936 { &vop_islocked_desc, genfs_islocked }, /* islocked */ 937 { &vop_pathconf_desc, spec_pathconf }, /* pathconf */ 938 { &vop_advlock_desc, spec_advlock }, /* advlock */ 939 { &vop_bwrite_desc, vn_bwrite }, /* bwrite */ 940 { &vop_getpages_desc, spec_getpages }, /* getpages */ 941 { &vop_putpages_desc, spec_putpages }, /* putpages */ 942 { NULL, NULL } 943 }; 944 const struct vnodeopv_desc cd9660_specop_opv_desc = 945 { &cd9660_specop_p, cd9660_specop_entries }; 946 947 int (**cd9660_fifoop_p)(void *); 948 const struct vnodeopv_entry_desc cd9660_fifoop_entries[] = { 949 { &vop_default_desc, vn_default_error }, 950 { &vop_lookup_desc, vn_fifo_bypass }, /* lookup */ 951 { &vop_create_desc, vn_fifo_bypass }, /* create */ 952 { &vop_mknod_desc, vn_fifo_bypass }, /* mknod */ 953 { &vop_open_desc, vn_fifo_bypass }, /* open */ 954 { &vop_close_desc, vn_fifo_bypass }, /* close */ 955 { &vop_access_desc, cd9660_access }, /* access */ 956 { &vop_getattr_desc, cd9660_getattr }, /* getattr */ 957 { &vop_setattr_desc, cd9660_setattr }, /* setattr */ 958 { &vop_read_desc, vn_fifo_bypass }, /* read */ 959 { &vop_write_desc, vn_fifo_bypass }, /* write */ 960 { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */ 961 { &vop_ioctl_desc, vn_fifo_bypass }, /* ioctl */ 962 { &vop_poll_desc, vn_fifo_bypass }, /* poll */ 963 { &vop_kqfilter_desc, vn_fifo_bypass }, /* kqfilter */ 964 { &vop_revoke_desc, vn_fifo_bypass }, /* revoke */ 965 { &vop_mmap_desc, vn_fifo_bypass }, /* mmap */ 966 { &vop_fsync_desc, vn_fifo_bypass }, /* fsync */ 967 { &vop_seek_desc, vn_fifo_bypass }, /* seek */ 968 { &vop_remove_desc, vn_fifo_bypass }, /* remove */ 969 { &vop_link_desc, vn_fifo_bypass } , /* link */ 970 { &vop_rename_desc, vn_fifo_bypass }, /* rename */ 971 { &vop_mkdir_desc, vn_fifo_bypass }, /* mkdir */ 972 { &vop_rmdir_desc, vn_fifo_bypass }, /* rmdir */ 973 { &vop_symlink_desc, vn_fifo_bypass }, /* symlink */ 974 { &vop_readdir_desc, vn_fifo_bypass }, /* readdir */ 975 { &vop_readlink_desc, vn_fifo_bypass }, /* readlink */ 976 { &vop_abortop_desc, vn_fifo_bypass }, /* abortop */ 977 { &vop_inactive_desc, cd9660_inactive }, /* inactive */ 978 { &vop_reclaim_desc, cd9660_reclaim }, /* reclaim */ 979 { &vop_lock_desc, genfs_lock }, /* lock */ 980 { &vop_unlock_desc, genfs_unlock }, /* unlock */ 981 { &vop_bmap_desc, vn_fifo_bypass }, /* bmap */ 982 { &vop_strategy_desc, vn_fifo_bypass }, /* strategy */ 983 { &vop_print_desc, cd9660_print }, /* print */ 984 { &vop_islocked_desc, genfs_islocked }, /* islocked */ 985 { &vop_pathconf_desc, vn_fifo_bypass }, /* pathconf */ 986 { &vop_advlock_desc, vn_fifo_bypass }, /* advlock */ 987 { &vop_bwrite_desc, vn_bwrite }, /* bwrite */ 988 { &vop_putpages_desc, vn_fifo_bypass }, /* putpages */ 989 { NULL, NULL } 990 }; 991 const struct vnodeopv_desc cd9660_fifoop_opv_desc = 992 { &cd9660_fifoop_p, cd9660_fifoop_entries }; 993