1 /* $NetBSD: cd9660_vnops.c,v 1.62 2022/03/27 17:10:55 christos 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.62 2022/03/27 17:10:55 christos 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, accmode_t accmode) 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 (accmode & 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, accmode_t accmode, 117 kauth_cred_t cred) 118 { 119 120 return kauth_authorize_vnode(cred, KAUTH_ACCESS_ACTION(accmode, 121 vp->v_type, ip->inode.iso_mode & ALLPERMS), vp, NULL, 122 genfs_can_access(vp, cred, ip->inode.iso_uid, ip->inode.iso_gid, 123 ip->inode.iso_mode & ALLPERMS, NULL, accmode)); 124 } 125 126 int 127 cd9660_access(void *v) 128 { 129 struct vop_access_args /* { 130 struct vnode *a_vp; 131 accmode_t a_accmode; 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_accmode); 139 if (error) 140 return error; 141 142 error = cd9660_check_permitted(vp, ip, ap->a_accmode, 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_VNODE_FLAGS(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, 0, &bp); 266 } else { 267 error = bread(vp, lbn, size, 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 assoc = (cl > 1) && (*cname == ASSOCCHAR); 323 if (assoc) { 324 cl--; 325 cname++; 326 } 327 328 dp = &idp->saveent; 329 sname = dp->d_name; 330 if (!(sl = dp->d_namlen)) { 331 dp = &idp->assocent; 332 sname = dp->d_name + 1; 333 sl = dp->d_namlen - 1; 334 } 335 if (sl > 0) { 336 if (sl != cl 337 || memcmp(sname, cname, sl)) { 338 if (idp->assocent.d_namlen) { 339 error = iso_uiodir(idp, &idp->assocent, 340 idp->assocoff); 341 if (error) 342 return (error); 343 idp->assocent.d_namlen = 0; 344 } 345 if (idp->saveent.d_namlen) { 346 error = iso_uiodir(idp, &idp->saveent, 347 idp->saveoff); 348 if (error) 349 return (error); 350 idp->saveent.d_namlen = 0; 351 } 352 } 353 } 354 idp->current.d_reclen = _DIRENT_SIZE(&idp->current); 355 if (assoc) { 356 idp->assocoff = idp->curroff; 357 memcpy(&idp->assocent, &idp->current, idp->current.d_reclen); 358 } else { 359 idp->saveoff = idp->curroff; 360 memcpy(&idp->saveent, &idp->current, idp->current.d_reclen); 361 } 362 return (0); 363 } 364 365 /* 366 * Vnode op for readdir 367 */ 368 int 369 cd9660_readdir(void *v) 370 { 371 struct vop_readdir_args /* { 372 struct vnode *a_vp; 373 struct uio *a_uio; 374 kauth_cred_t a_cred; 375 int *a_eofflag; 376 off_t **a_cookies; 377 int *a_ncookies; 378 } */ *ap = v; 379 struct uio *uio = ap->a_uio; 380 struct isoreaddir *idp; 381 struct vnode *vdp = ap->a_vp; 382 struct iso_node *dp; 383 struct iso_mnt *imp; 384 struct buf *bp = NULL; 385 struct iso_directory_record *ep; 386 int entryoffsetinblock; 387 doff_t endsearch; 388 u_long bmask; 389 int error = 0; 390 int reclen; 391 u_short namelen; 392 off_t *cookies = NULL; 393 int ncookies = 0; 394 395 if (vdp->v_type != VDIR) 396 return (ENOTDIR); 397 398 dp = VTOI(vdp); 399 imp = dp->i_mnt; 400 bmask = imp->im_bmask; 401 402 idp = malloc(sizeof(*idp), M_TEMP, M_WAITOK | M_ZERO); 403 idp->saveent.d_namlen = idp->assocent.d_namlen = 0; 404 /* 405 * XXX 406 * Is it worth trying to figure out the type? 407 */ 408 idp->saveent.d_type = idp->assocent.d_type = idp->current.d_type = 409 DT_UNKNOWN; 410 idp->uio = uio; 411 if (ap->a_ncookies == NULL) 412 idp->cookies = NULL; 413 else { 414 ncookies = uio->uio_resid / _DIRENT_MINSIZE((struct dirent *)0); 415 cookies = malloc(ncookies * sizeof(off_t), M_TEMP, M_WAITOK); 416 idp->cookies = cookies; 417 idp->ncookies = ncookies; 418 } 419 idp->eofflag = 1; 420 idp->curroff = uio->uio_offset; 421 422 if ((entryoffsetinblock = idp->curroff & bmask) && 423 (error = cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp))) { 424 free(idp, M_TEMP); 425 return (error); 426 } 427 endsearch = dp->i_size; 428 429 while (idp->curroff < endsearch) { 430 /* 431 * If offset is on a block boundary, 432 * read the next directory block. 433 * Release previous if it exists. 434 */ 435 if ((idp->curroff & bmask) == 0) { 436 if (bp != NULL) 437 brelse(bp, 0); 438 error = cd9660_blkatoff(vdp, (off_t)idp->curroff, 439 NULL, &bp); 440 if (error) 441 break; 442 entryoffsetinblock = 0; 443 } 444 /* 445 * Get pointer to next entry. 446 */ 447 KASSERT(bp != NULL); 448 ep = (struct iso_directory_record *) 449 ((char *)bp->b_data + entryoffsetinblock); 450 451 reclen = isonum_711(ep->length); 452 if (reclen == 0) { 453 /* skip to next block, if any */ 454 idp->curroff = 455 (idp->curroff & ~bmask) + imp->logical_block_size; 456 continue; 457 } 458 459 if (reclen < ISO_DIRECTORY_RECORD_SIZE) { 460 error = EINVAL; 461 /* illegal entry, stop */ 462 break; 463 } 464 465 if (entryoffsetinblock + reclen > imp->logical_block_size) { 466 error = EINVAL; 467 /* illegal directory, so stop looking */ 468 break; 469 } 470 471 idp->current.d_namlen = isonum_711(ep->name_len); 472 473 if (reclen < ISO_DIRECTORY_RECORD_SIZE + idp->current.d_namlen) { 474 error = EINVAL; 475 /* illegal entry, stop */ 476 break; 477 } 478 479 if (isonum_711(ep->flags)&2) 480 idp->current.d_fileno = isodirino(ep, imp); 481 else 482 idp->current.d_fileno = dbtob(bp->b_blkno) + 483 entryoffsetinblock; 484 485 idp->curroff += reclen; 486 487 switch (imp->iso_ftype) { 488 case ISO_FTYPE_RRIP: 489 cd9660_rrip_getname(ep, idp->current.d_name, &namelen, 490 &idp->current.d_fileno, imp); 491 idp->current.d_namlen = (u_char)namelen; 492 if (idp->current.d_namlen) 493 error = iso_uiodir(idp, &idp->current, 494 idp->curroff); 495 break; 496 default: /* ISO_FTYPE_DEFAULT || ISO_FTYPE_9660 */ 497 isofntrans(ep->name, idp->current.d_namlen, 498 idp->current.d_name, &namelen, 499 imp->iso_ftype == ISO_FTYPE_9660, 500 (imp->im_flags & ISOFSMNT_NOCASETRANS) == 0, 501 isonum_711(ep->flags)&4, 502 imp->im_joliet_level); 503 switch (idp->current.d_name[0]) { 504 case 0: 505 idp->current.d_name[0] = '.'; 506 idp->current.d_namlen = 1; 507 error = iso_uiodir(idp, &idp->current, 508 idp->curroff); 509 break; 510 case 1: 511 strlcpy(idp->current.d_name, "..", 512 sizeof(idp->current.d_name)); 513 idp->current.d_namlen = 2; 514 error = iso_uiodir(idp, &idp->current, 515 idp->curroff); 516 break; 517 default: 518 idp->current.d_namlen = (u_char)namelen; 519 if (imp->iso_ftype == ISO_FTYPE_DEFAULT) 520 error = iso_shipdir(idp); 521 else 522 error = iso_uiodir(idp, &idp->current, 523 idp->curroff); 524 break; 525 } 526 } 527 if (error) 528 break; 529 530 entryoffsetinblock += reclen; 531 } 532 533 if (!error && imp->iso_ftype == ISO_FTYPE_DEFAULT) { 534 idp->current.d_namlen = 0; 535 error = iso_shipdir(idp); 536 } 537 if (error < 0) 538 error = 0; 539 540 if (ap->a_ncookies != NULL) { 541 if (error) 542 free(cookies, M_TEMP); 543 else { 544 /* 545 * Work out the number of cookies actually used. 546 */ 547 *ap->a_ncookies = ncookies - idp->ncookies; 548 *ap->a_cookies = cookies; 549 } 550 } 551 552 if (bp) 553 brelse(bp, 0); 554 555 uio->uio_offset = idp->uio_off; 556 *ap->a_eofflag = idp->eofflag; 557 558 free(idp, M_TEMP); 559 560 return (error); 561 } 562 563 /* 564 * Return target name of a symbolic link 565 * Shouldn't we get the parent vnode and read the data from there? 566 * This could eventually result in deadlocks in cd9660_lookup. 567 * But otherwise the block read here is in the block buffer two times. 568 */ 569 typedef struct iso_directory_record ISODIR; 570 typedef struct iso_node ISONODE; 571 typedef struct iso_mnt ISOMNT; 572 573 int 574 cd9660_readlink(void *v) 575 { 576 struct vop_readlink_args /* { 577 struct vnode *a_vp; 578 struct uio *a_uio; 579 kauth_cred_t a_cred; 580 } */ *ap = v; 581 ISONODE *ip; 582 ISODIR *dirp; 583 ISOMNT *imp; 584 struct buf *bp; 585 struct uio *uio; 586 u_short symlen; 587 int error; 588 char *symname; 589 bool use_pnbuf; 590 591 ip = VTOI(ap->a_vp); 592 imp = ip->i_mnt; 593 uio = ap->a_uio; 594 595 if (imp->iso_ftype != ISO_FTYPE_RRIP) 596 return (EINVAL); 597 598 /* 599 * Get parents directory record block that this inode included. 600 */ 601 error = bread(imp->im_devvp, 602 (ip->i_number >> imp->im_bshift) << 603 (imp->im_bshift - DEV_BSHIFT), 604 imp->logical_block_size, 0, &bp); 605 if (error) { 606 return (EINVAL); 607 } 608 609 /* 610 * Setup the directory pointer for this inode 611 */ 612 dirp = (ISODIR *)((char *)bp->b_data + (ip->i_number & imp->im_bmask)); 613 614 /* 615 * Just make sure, we have a right one.... 616 * 1: Check not cross boundary on block 617 */ 618 if ((ip->i_number & imp->im_bmask) + isonum_711(dirp->length) 619 > imp->logical_block_size) { 620 brelse(bp, 0); 621 return (EINVAL); 622 } 623 624 /* 625 * Now get a buffer 626 * Abuse a namei buffer for now. 627 */ 628 use_pnbuf = !VMSPACE_IS_KERNEL_P(uio->uio_vmspace) || 629 uio->uio_iov->iov_len < MAXPATHLEN; 630 if (use_pnbuf) { 631 symname = PNBUF_GET(); 632 } else { 633 symname = uio->uio_iov->iov_base; 634 } 635 636 /* 637 * Ok, we just gathering a symbolic name in SL record. 638 */ 639 if (cd9660_rrip_getsymname(dirp, symname, &symlen, imp) == 0) { 640 if (use_pnbuf) { 641 PNBUF_PUT(symname); 642 } 643 brelse(bp, 0); 644 return (EINVAL); 645 } 646 /* 647 * Don't forget before you leave from home ;-) 648 */ 649 brelse(bp, 0); 650 651 /* 652 * return with the symbolic name to caller's. 653 */ 654 if (use_pnbuf) { 655 error = uiomove(symname, symlen, uio); 656 PNBUF_PUT(symname); 657 return (error); 658 } 659 uio->uio_resid -= symlen; 660 uio->uio_iov->iov_base = (char *)uio->uio_iov->iov_base + symlen; 661 uio->uio_iov->iov_len -= symlen; 662 return (0); 663 } 664 665 /* 666 * Calculate the logical to physical mapping if not done already, 667 * then call the device strategy routine. 668 */ 669 int 670 cd9660_strategy(void *v) 671 { 672 struct vop_strategy_args /* { 673 struct vnode *a_vp; 674 struct buf *a_bp; 675 } */ *ap = v; 676 struct buf *bp = ap->a_bp; 677 struct vnode *vp = ap->a_vp; 678 struct iso_node *ip; 679 int error; 680 681 ip = VTOI(vp); 682 if (vp->v_type == VBLK || vp->v_type == VCHR) 683 panic("cd9660_strategy: spec"); 684 if (bp->b_blkno == bp->b_lblkno) { 685 error = VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno, NULL); 686 if (error) { 687 bp->b_error = error; 688 biodone(bp); 689 return (error); 690 } 691 if ((long)bp->b_blkno == -1) 692 clrbuf(bp); 693 } 694 if ((long)bp->b_blkno == -1) { 695 biodone(bp); 696 return (0); 697 } 698 vp = ip->i_mnt->im_devvp; 699 return (VOP_STRATEGY(vp, bp)); 700 } 701 702 /* 703 * Print out the contents of an inode. 704 */ 705 /*ARGSUSED*/ 706 int 707 cd9660_print(void *v) 708 { 709 710 printf("tag VT_ISOFS, isofs vnode\n"); 711 return (0); 712 } 713 714 /* 715 * Return POSIX pathconf information applicable to cd9660 filesystems. 716 */ 717 int 718 cd9660_pathconf(void *v) 719 { 720 struct vop_pathconf_args /* { 721 struct vnode *a_vp; 722 int a_name; 723 register_t *a_retval; 724 } */ *ap = v; 725 switch (ap->a_name) { 726 case _PC_LINK_MAX: 727 *ap->a_retval = 1; 728 return (0); 729 case _PC_NAME_MAX: 730 if (VTOI(ap->a_vp)->i_mnt->iso_ftype == ISO_FTYPE_RRIP) 731 *ap->a_retval = ISO_MAXNAMLEN; 732 else 733 *ap->a_retval = 37; 734 return (0); 735 case _PC_PATH_MAX: 736 *ap->a_retval = PATH_MAX; 737 return (0); 738 case _PC_PIPE_BUF: 739 *ap->a_retval = PIPE_BUF; 740 return (0); 741 case _PC_CHOWN_RESTRICTED: 742 *ap->a_retval = 1; 743 return (0); 744 case _PC_NO_TRUNC: 745 *ap->a_retval = 1; 746 return (0); 747 case _PC_SYNC_IO: 748 *ap->a_retval = 1; 749 return (0); 750 case _PC_FILESIZEBITS: 751 *ap->a_retval = 32; 752 return (0); 753 default: 754 return genfs_pathconf(ap); 755 } 756 /* NOTREACHED */ 757 } 758 759 /* 760 * Allow changing the size for special files (and fifos). 761 */ 762 int 763 cd9660_setattr(void *v) 764 { 765 struct vop_setattr_args /* { 766 struct vnodeop_desc *a_desc; 767 struct vnode *a_vp; 768 struct vattr *a_vap; 769 kauth_cred_t a_cred; 770 struct proc *a_p; 771 } */ *ap = v; 772 struct vattr *vap = ap->a_vap; 773 struct vnode *vp = ap->a_vp; 774 775 /* 776 * Only size is changeable. 777 */ 778 if (vap->va_type != VNON 779 || vap->va_nlink != (nlink_t)VNOVAL 780 || vap->va_fsid != VNOVAL 781 || vap->va_fileid != VNOVAL 782 || vap->va_blocksize != VNOVAL 783 || vap->va_rdev != (dev_t)VNOVAL 784 || (int)vap->va_bytes != VNOVAL 785 || vap->va_gen != VNOVAL 786 || vap->va_flags != VNOVAL 787 || vap->va_uid != (uid_t)VNOVAL 788 || vap->va_gid != (gid_t)VNOVAL 789 || vap->va_atime.tv_sec != VNOVAL 790 || vap->va_mtime.tv_sec != VNOVAL 791 || vap->va_mode != (mode_t)VNOVAL) 792 return EOPNOTSUPP; 793 794 if (vap->va_size != VNOVAL 795 && vp->v_type != VCHR 796 && vp->v_type != VBLK 797 && vp->v_type != VFIFO) 798 return EOPNOTSUPP; 799 800 return 0; 801 } 802 803 /* 804 * Global vfs data structures for cd9660 805 */ 806 int (**cd9660_vnodeop_p)(void *); 807 const struct vnodeopv_entry_desc cd9660_vnodeop_entries[] = { 808 { &vop_default_desc, vn_default_error }, 809 { &vop_parsepath_desc, genfs_parsepath }, /* parsepath */ 810 { &vop_lookup_desc, cd9660_lookup }, /* lookup */ 811 { &vop_create_desc, genfs_eopnotsupp }, /* create */ 812 { &vop_mknod_desc, genfs_eopnotsupp }, /* mknod */ 813 { &vop_open_desc, genfs_nullop }, /* open */ 814 { &vop_close_desc, genfs_nullop }, /* close */ 815 { &vop_access_desc, cd9660_access }, /* access */ 816 { &vop_accessx_desc, genfs_accessx }, /* accessx */ 817 { &vop_getattr_desc, cd9660_getattr }, /* getattr */ 818 { &vop_setattr_desc, cd9660_setattr }, /* setattr */ 819 { &vop_read_desc, cd9660_read }, /* read */ 820 { &vop_write_desc, genfs_eopnotsupp }, /* write */ 821 { &vop_fallocate_desc, genfs_eopnotsupp }, /* fallocate */ 822 { &vop_fdiscard_desc, genfs_eopnotsupp }, /* fdiscard */ 823 { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */ 824 { &vop_ioctl_desc, genfs_enoioctl }, /* ioctl */ 825 { &vop_poll_desc, genfs_poll }, /* poll */ 826 { &vop_revoke_desc, genfs_revoke }, /* revoke */ 827 { &vop_mmap_desc, genfs_mmap }, /* mmap */ 828 { &vop_fsync_desc, genfs_nullop }, /* fsync */ 829 { &vop_seek_desc, genfs_seek }, /* seek */ 830 { &vop_remove_desc, genfs_eopnotsupp }, /* remove */ 831 { &vop_link_desc, genfs_erofs_link }, /* link */ 832 { &vop_rename_desc, genfs_eopnotsupp }, /* rename */ 833 { &vop_mkdir_desc, genfs_eopnotsupp }, /* mkdir */ 834 { &vop_rmdir_desc, genfs_eopnotsupp }, /* rmdir */ 835 { &vop_symlink_desc, genfs_erofs_symlink }, /* symlink */ 836 { &vop_readdir_desc, cd9660_readdir }, /* readdir */ 837 { &vop_readlink_desc, cd9660_readlink }, /* readlink */ 838 { &vop_abortop_desc, genfs_abortop }, /* abortop */ 839 { &vop_inactive_desc, cd9660_inactive }, /* inactive */ 840 { &vop_reclaim_desc, cd9660_reclaim }, /* reclaim */ 841 { &vop_lock_desc, genfs_lock }, /* lock */ 842 { &vop_unlock_desc, genfs_unlock }, /* unlock */ 843 { &vop_bmap_desc, cd9660_bmap }, /* bmap */ 844 { &vop_strategy_desc, cd9660_strategy }, /* strategy */ 845 { &vop_print_desc, cd9660_print }, /* print */ 846 { &vop_islocked_desc, genfs_islocked }, /* islocked */ 847 { &vop_pathconf_desc, cd9660_pathconf }, /* pathconf */ 848 { &vop_advlock_desc, genfs_einval }, /* advlock */ 849 { &vop_bwrite_desc, vn_bwrite }, /* bwrite */ 850 { &vop_getpages_desc, genfs_getpages }, /* getpages */ 851 { &vop_putpages_desc, genfs_putpages }, /* putpages */ 852 { NULL, NULL } 853 }; 854 const struct vnodeopv_desc cd9660_vnodeop_opv_desc = 855 { &cd9660_vnodeop_p, cd9660_vnodeop_entries }; 856 857 /* 858 * Special device vnode ops 859 */ 860 int (**cd9660_specop_p)(void *); 861 const struct vnodeopv_entry_desc cd9660_specop_entries[] = { 862 { &vop_default_desc, vn_default_error }, 863 GENFS_SPECOP_ENTRIES, 864 { &vop_close_desc, spec_close }, /* close */ 865 { &vop_access_desc, cd9660_access }, /* access */ 866 { &vop_accessx_desc, genfs_accessx }, /* accessx */ 867 { &vop_getattr_desc, cd9660_getattr }, /* getattr */ 868 { &vop_setattr_desc, cd9660_setattr }, /* setattr */ 869 { &vop_read_desc, spec_read }, /* read */ 870 { &vop_write_desc, spec_write }, /* write */ 871 { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */ 872 { &vop_fsync_desc, spec_fsync }, /* fsync */ 873 { &vop_inactive_desc, cd9660_inactive }, /* inactive */ 874 { &vop_reclaim_desc, cd9660_reclaim }, /* reclaim */ 875 { &vop_lock_desc, genfs_lock }, /* lock */ 876 { &vop_unlock_desc, genfs_unlock }, /* unlock */ 877 { &vop_print_desc, cd9660_print }, /* print */ 878 { &vop_islocked_desc, genfs_islocked }, /* islocked */ 879 { &vop_bwrite_desc, vn_bwrite }, /* bwrite */ 880 { NULL, NULL } 881 }; 882 const struct vnodeopv_desc cd9660_specop_opv_desc = 883 { &cd9660_specop_p, cd9660_specop_entries }; 884 885 int (**cd9660_fifoop_p)(void *); 886 const struct vnodeopv_entry_desc cd9660_fifoop_entries[] = { 887 { &vop_default_desc, vn_default_error }, 888 GENFS_FIFOOP_ENTRIES, 889 { &vop_close_desc, vn_fifo_bypass }, /* close */ 890 { &vop_access_desc, cd9660_access }, /* access */ 891 { &vop_accessx_desc, genfs_accessx }, /* accessx */ 892 { &vop_getattr_desc, cd9660_getattr }, /* getattr */ 893 { &vop_setattr_desc, cd9660_setattr }, /* setattr */ 894 { &vop_read_desc, vn_fifo_bypass }, /* read */ 895 { &vop_write_desc, vn_fifo_bypass }, /* write */ 896 { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */ 897 { &vop_fsync_desc, vn_fifo_bypass }, /* fsync */ 898 { &vop_inactive_desc, cd9660_inactive }, /* inactive */ 899 { &vop_reclaim_desc, cd9660_reclaim }, /* reclaim */ 900 { &vop_lock_desc, genfs_lock }, /* lock */ 901 { &vop_unlock_desc, genfs_unlock }, /* unlock */ 902 { &vop_strategy_desc, vn_fifo_bypass }, /* strategy */ 903 { &vop_print_desc, cd9660_print }, /* print */ 904 { &vop_islocked_desc, genfs_islocked }, /* islocked */ 905 { &vop_bwrite_desc, vn_bwrite }, /* bwrite */ 906 { NULL, NULL } 907 }; 908 const struct vnodeopv_desc cd9660_fifoop_opv_desc = 909 { &cd9660_fifoop_p, cd9660_fifoop_entries }; 910