1 /* $NetBSD: cd9660_vnops.c,v 1.40 2011/09/27 01:27:44 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.40 2011/09/27 01:27:44 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, 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 genfs_can_access(vp->v_type, ip->inode.iso_mode & ALLPERMS, 121 ip->inode.iso_uid, ip->inode.iso_gid, mode, cred); 122 } 123 124 int 125 cd9660_access(void *v) 126 { 127 struct vop_access_args /* { 128 struct vnode *a_vp; 129 int a_mode; 130 kauth_cred_t a_cred; 131 } */ *ap = v; 132 struct vnode *vp = ap->a_vp; 133 struct iso_node *ip = VTOI(vp); 134 int error; 135 136 error = cd9660_check_possible(vp, ip, ap->a_mode); 137 if (error) 138 return error; 139 140 error = cd9660_check_permitted(vp, ip, ap->a_mode, ap->a_cred); 141 142 return error; 143 } 144 145 int 146 cd9660_getattr(void *v) 147 { 148 struct vop_getattr_args /* { 149 struct vnode *a_vp; 150 struct vattr *a_vap; 151 kauth_cred_t a_cred; 152 } */ *ap = v; 153 struct vnode *vp = ap->a_vp; 154 struct iso_node *ip = VTOI(vp); 155 struct vattr *vap = ap->a_vap; 156 157 vap->va_fsid = ip->i_dev; 158 vap->va_fileid = ip->i_number; 159 160 vap->va_mode = ip->inode.iso_mode & ALLPERMS; 161 vap->va_nlink = ip->inode.iso_links; 162 vap->va_uid = ip->inode.iso_uid; 163 vap->va_gid = ip->inode.iso_gid; 164 vap->va_atime = ip->inode.iso_atime; 165 vap->va_mtime = ip->inode.iso_mtime; 166 vap->va_ctime = ip->inode.iso_ctime; 167 vap->va_rdev = ip->inode.iso_rdev; 168 169 vap->va_size = (u_quad_t) ip->i_size; 170 if (ip->i_size == 0 && vp->v_type == VLNK) { 171 struct vop_readlink_args rdlnk; 172 struct iovec aiov; 173 struct uio auio; 174 char *cp; 175 176 cp = (char *)malloc(MAXPATHLEN, M_TEMP, M_WAITOK); 177 aiov.iov_base = cp; 178 aiov.iov_len = MAXPATHLEN; 179 auio.uio_iov = &aiov; 180 auio.uio_iovcnt = 1; 181 auio.uio_offset = 0; 182 auio.uio_rw = UIO_READ; 183 auio.uio_resid = MAXPATHLEN; 184 UIO_SETUP_SYSSPACE(&auio); 185 rdlnk.a_uio = &auio; 186 rdlnk.a_vp = ap->a_vp; 187 rdlnk.a_cred = ap->a_cred; 188 if (cd9660_readlink(&rdlnk) == 0) 189 vap->va_size = MAXPATHLEN - auio.uio_resid; 190 free(cp, M_TEMP); 191 } 192 vap->va_flags = 0; 193 vap->va_gen = 1; 194 vap->va_blocksize = ip->i_mnt->logical_block_size; 195 vap->va_bytes = (u_quad_t) ip->i_size; 196 vap->va_type = vp->v_type; 197 return (0); 198 } 199 200 /* 201 * Vnode op for reading. 202 */ 203 int 204 cd9660_read(void *v) 205 { 206 struct vop_read_args /* { 207 struct vnode *a_vp; 208 struct uio *a_uio; 209 int a_ioflag; 210 kauth_cred_t a_cred; 211 } */ *ap = v; 212 struct vnode *vp = ap->a_vp; 213 struct uio *uio = ap->a_uio; 214 struct iso_node *ip = VTOI(vp); 215 struct iso_mnt *imp; 216 struct buf *bp; 217 daddr_t lbn, rablock; 218 off_t diff; 219 int rasize, error = 0; 220 long size, n, on; 221 222 if (uio->uio_resid == 0) 223 return (0); 224 if (uio->uio_offset < 0) 225 return (EINVAL); 226 if (uio->uio_offset >= ip->i_size) 227 return 0; 228 ip->i_flag |= IN_ACCESS; 229 imp = ip->i_mnt; 230 231 if (vp->v_type == VREG) { 232 const int advice = IO_ADV_DECODE(ap->a_ioflag); 233 error = 0; 234 235 while (uio->uio_resid > 0) { 236 vsize_t bytelen = MIN(ip->i_size - uio->uio_offset, 237 uio->uio_resid); 238 239 if (bytelen == 0) 240 break; 241 error = ubc_uiomove(&vp->v_uobj, uio, bytelen, advice, 242 UBC_READ | UBC_PARTIALOK | UBC_UNMAP_FLAG(vp)); 243 if (error) 244 break; 245 } 246 goto out; 247 } 248 249 do { 250 lbn = lblkno(imp, uio->uio_offset); 251 on = blkoff(imp, uio->uio_offset); 252 n = MIN(imp->logical_block_size - on, uio->uio_resid); 253 diff = (off_t)ip->i_size - uio->uio_offset; 254 if (diff <= 0) 255 return (0); 256 if (diff < n) 257 n = diff; 258 size = blksize(imp, ip, lbn); 259 rablock = lbn + 1; 260 if (lblktosize(imp, rablock) < ip->i_size) { 261 rasize = blksize(imp, ip, rablock); 262 error = breadn(vp, lbn, size, &rablock, 263 &rasize, 1, NOCRED, 0, &bp); 264 } else { 265 error = bread(vp, lbn, size, NOCRED, 0, &bp); 266 } 267 n = MIN(n, size - bp->b_resid); 268 if (error) { 269 brelse(bp, 0); 270 return (error); 271 } 272 273 error = uiomove((char *)bp->b_data + on, (int)n, uio); 274 brelse(bp, 0); 275 } while (error == 0 && uio->uio_resid > 0 && n != 0); 276 277 out: 278 return (error); 279 } 280 281 int 282 iso_uiodir(struct isoreaddir *idp, struct dirent *dp, off_t off) 283 { 284 int error; 285 286 dp->d_name[dp->d_namlen] = 0; 287 dp->d_reclen = _DIRENT_SIZE(dp); 288 289 if (idp->uio->uio_resid < dp->d_reclen) { 290 idp->eofflag = 0; 291 return (-1); 292 } 293 294 if (idp->cookies) { 295 if (idp->ncookies <= 0) { 296 idp->eofflag = 0; 297 return (-1); 298 } 299 300 *idp->cookies++ = off; 301 --idp->ncookies; 302 } 303 304 if ((error = uiomove(dp, dp->d_reclen, idp->uio)) != 0) 305 return (error); 306 idp->uio_off = off; 307 return (0); 308 } 309 310 int 311 iso_shipdir(struct isoreaddir *idp) 312 { 313 struct dirent *dp; 314 int cl, sl, assoc; 315 int error; 316 char *cname, *sname; 317 318 cl = idp->current.d_namlen; 319 cname = idp->current.d_name; 320 321 if ((assoc = cl > 1 && *cname == ASSOCCHAR)) { 322 cl--; 323 cname++; 324 } 325 326 dp = &idp->saveent; 327 sname = dp->d_name; 328 if (!(sl = dp->d_namlen)) { 329 dp = &idp->assocent; 330 sname = dp->d_name + 1; 331 sl = dp->d_namlen - 1; 332 } 333 if (sl > 0) { 334 if (sl != cl 335 || memcmp(sname, cname, sl)) { 336 if (idp->assocent.d_namlen) { 337 error = iso_uiodir(idp, &idp->assocent, 338 idp->assocoff); 339 if (error) 340 return (error); 341 idp->assocent.d_namlen = 0; 342 } 343 if (idp->saveent.d_namlen) { 344 error = iso_uiodir(idp, &idp->saveent, 345 idp->saveoff); 346 if (error) 347 return (error); 348 idp->saveent.d_namlen = 0; 349 } 350 } 351 } 352 idp->current.d_reclen = _DIRENT_SIZE(&idp->current); 353 if (assoc) { 354 idp->assocoff = idp->curroff; 355 memcpy(&idp->assocent, &idp->current, idp->current.d_reclen); 356 } else { 357 idp->saveoff = idp->curroff; 358 memcpy(&idp->saveent, &idp->current, idp->current.d_reclen); 359 } 360 return (0); 361 } 362 363 /* 364 * Vnode op for readdir 365 */ 366 int 367 cd9660_readdir(void *v) 368 { 369 struct vop_readdir_args /* { 370 struct vnode *a_vp; 371 struct uio *a_uio; 372 kauth_cred_t a_cred; 373 int *a_eofflag; 374 off_t **a_cookies; 375 int *a_ncookies; 376 } */ *ap = v; 377 struct uio *uio = ap->a_uio; 378 struct isoreaddir *idp; 379 struct vnode *vdp = ap->a_vp; 380 struct iso_node *dp; 381 struct iso_mnt *imp; 382 struct buf *bp = NULL; 383 struct iso_directory_record *ep; 384 int entryoffsetinblock; 385 doff_t endsearch; 386 u_long bmask; 387 int error = 0; 388 int reclen; 389 u_short namelen; 390 off_t *cookies = NULL; 391 int ncookies = 0; 392 393 if (vdp->v_type != VDIR) 394 return (ENOTDIR); 395 396 dp = VTOI(vdp); 397 imp = dp->i_mnt; 398 bmask = imp->im_bmask; 399 400 idp = (struct isoreaddir *)malloc(sizeof(*idp), M_TEMP, M_WAITOK); 401 idp->saveent.d_namlen = idp->assocent.d_namlen = 0; 402 /* 403 * XXX 404 * Is it worth trying to figure out the type? 405 */ 406 idp->saveent.d_type = idp->assocent.d_type = idp->current.d_type = 407 DT_UNKNOWN; 408 idp->uio = uio; 409 if (ap->a_ncookies == NULL) 410 idp->cookies = NULL; 411 else { 412 ncookies = uio->uio_resid / _DIRENT_MINSIZE((struct dirent *)0); 413 cookies = malloc(ncookies * sizeof(off_t), M_TEMP, M_WAITOK); 414 idp->cookies = cookies; 415 idp->ncookies = ncookies; 416 } 417 idp->eofflag = 1; 418 idp->curroff = uio->uio_offset; 419 420 if ((entryoffsetinblock = idp->curroff & bmask) && 421 (error = cd9660_blkatoff(vdp, (off_t)idp->curroff, NULL, &bp))) { 422 free(idp, M_TEMP); 423 return (error); 424 } 425 endsearch = dp->i_size; 426 427 while (idp->curroff < endsearch) { 428 /* 429 * If offset is on a block boundary, 430 * read the next directory block. 431 * Release previous if it exists. 432 */ 433 if ((idp->curroff & bmask) == 0) { 434 if (bp != NULL) 435 brelse(bp, 0); 436 error = cd9660_blkatoff(vdp, (off_t)idp->curroff, 437 NULL, &bp); 438 if (error) 439 break; 440 entryoffsetinblock = 0; 441 } 442 /* 443 * Get pointer to next entry. 444 */ 445 KASSERT(bp != NULL); 446 ep = (struct iso_directory_record *) 447 ((char *)bp->b_data + entryoffsetinblock); 448 449 reclen = isonum_711(ep->length); 450 if (reclen == 0) { 451 /* skip to next block, if any */ 452 idp->curroff = 453 (idp->curroff & ~bmask) + imp->logical_block_size; 454 continue; 455 } 456 457 if (reclen < ISO_DIRECTORY_RECORD_SIZE) { 458 error = EINVAL; 459 /* illegal entry, stop */ 460 break; 461 } 462 463 if (entryoffsetinblock + reclen > imp->logical_block_size) { 464 error = EINVAL; 465 /* illegal directory, so stop looking */ 466 break; 467 } 468 469 idp->current.d_namlen = isonum_711(ep->name_len); 470 471 if (reclen < ISO_DIRECTORY_RECORD_SIZE + idp->current.d_namlen) { 472 error = EINVAL; 473 /* illegal entry, stop */ 474 break; 475 } 476 477 if (isonum_711(ep->flags)&2) 478 idp->current.d_fileno = isodirino(ep, imp); 479 else 480 idp->current.d_fileno = dbtob(bp->b_blkno) + 481 entryoffsetinblock; 482 483 idp->curroff += reclen; 484 485 switch (imp->iso_ftype) { 486 case ISO_FTYPE_RRIP: 487 cd9660_rrip_getname(ep, idp->current.d_name, &namelen, 488 &idp->current.d_fileno, imp); 489 idp->current.d_namlen = (u_char)namelen; 490 if (idp->current.d_namlen) 491 error = iso_uiodir(idp, &idp->current, 492 idp->curroff); 493 break; 494 default: /* ISO_FTYPE_DEFAULT || ISO_FTYPE_9660 */ 495 isofntrans(ep->name, idp->current.d_namlen, 496 idp->current.d_name, &namelen, 497 imp->iso_ftype == ISO_FTYPE_9660, 498 (imp->im_flags & ISOFSMNT_NOCASETRANS) == 0, 499 isonum_711(ep->flags)&4, 500 imp->im_joliet_level); 501 switch (idp->current.d_name[0]) { 502 case 0: 503 idp->current.d_name[0] = '.'; 504 idp->current.d_namlen = 1; 505 error = iso_uiodir(idp, &idp->current, 506 idp->curroff); 507 break; 508 case 1: 509 strlcpy(idp->current.d_name, "..", 510 sizeof(idp->current.d_name)); 511 idp->current.d_namlen = 2; 512 error = iso_uiodir(idp, &idp->current, 513 idp->curroff); 514 break; 515 default: 516 idp->current.d_namlen = (u_char)namelen; 517 if (imp->iso_ftype == ISO_FTYPE_DEFAULT) 518 error = iso_shipdir(idp); 519 else 520 error = iso_uiodir(idp, &idp->current, 521 idp->curroff); 522 break; 523 } 524 } 525 if (error) 526 break; 527 528 entryoffsetinblock += reclen; 529 } 530 531 if (!error && imp->iso_ftype == ISO_FTYPE_DEFAULT) { 532 idp->current.d_namlen = 0; 533 error = iso_shipdir(idp); 534 } 535 if (error < 0) 536 error = 0; 537 538 if (ap->a_ncookies != NULL) { 539 if (error) 540 free(cookies, M_TEMP); 541 else { 542 /* 543 * Work out the number of cookies actually used. 544 */ 545 *ap->a_ncookies = ncookies - idp->ncookies; 546 *ap->a_cookies = cookies; 547 } 548 } 549 550 if (bp) 551 brelse(bp, 0); 552 553 uio->uio_offset = idp->uio_off; 554 *ap->a_eofflag = idp->eofflag; 555 556 free(idp, M_TEMP); 557 558 return (error); 559 } 560 561 /* 562 * Return target name of a symbolic link 563 * Shouldn't we get the parent vnode and read the data from there? 564 * This could eventually result in deadlocks in cd9660_lookup. 565 * But otherwise the block read here is in the block buffer two times. 566 */ 567 typedef struct iso_directory_record ISODIR; 568 typedef struct iso_node ISONODE; 569 typedef struct iso_mnt ISOMNT; 570 571 int 572 cd9660_readlink(void *v) 573 { 574 struct vop_readlink_args /* { 575 struct vnode *a_vp; 576 struct uio *a_uio; 577 kauth_cred_t a_cred; 578 } */ *ap = v; 579 ISONODE *ip; 580 ISODIR *dirp; 581 ISOMNT *imp; 582 struct buf *bp; 583 struct uio *uio; 584 u_short symlen; 585 int error; 586 char *symname; 587 bool use_pnbuf; 588 589 ip = VTOI(ap->a_vp); 590 imp = ip->i_mnt; 591 uio = ap->a_uio; 592 593 if (imp->iso_ftype != ISO_FTYPE_RRIP) 594 return (EINVAL); 595 596 /* 597 * Get parents directory record block that this inode included. 598 */ 599 error = bread(imp->im_devvp, 600 (ip->i_number >> imp->im_bshift) << 601 (imp->im_bshift - DEV_BSHIFT), 602 imp->logical_block_size, NOCRED, 0, &bp); 603 if (error) { 604 brelse(bp, 0); 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_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 vput(ap->a_dvp); 691 return (EROFS); 692 } 693 694 /* 695 * Calculate the logical to physical mapping if not done already, 696 * then call the device strategy routine. 697 */ 698 int 699 cd9660_strategy(void *v) 700 { 701 struct vop_strategy_args /* { 702 struct vnode *a_vp; 703 struct buf *a_bp; 704 } */ *ap = v; 705 struct buf *bp = ap->a_bp; 706 struct vnode *vp = ap->a_vp; 707 struct iso_node *ip; 708 int error; 709 710 ip = VTOI(vp); 711 if (vp->v_type == VBLK || vp->v_type == VCHR) 712 panic("cd9660_strategy: spec"); 713 if (bp->b_blkno == bp->b_lblkno) { 714 error = VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno, NULL); 715 if (error) { 716 bp->b_error = error; 717 biodone(bp); 718 return (error); 719 } 720 if ((long)bp->b_blkno == -1) 721 clrbuf(bp); 722 } 723 if ((long)bp->b_blkno == -1) { 724 biodone(bp); 725 return (0); 726 } 727 vp = ip->i_devvp; 728 return (VOP_STRATEGY(vp, bp)); 729 } 730 731 /* 732 * Print out the contents of an inode. 733 */ 734 /*ARGSUSED*/ 735 int 736 cd9660_print(void *v) 737 { 738 739 printf("tag VT_ISOFS, isofs vnode\n"); 740 return (0); 741 } 742 743 /* 744 * Return POSIX pathconf information applicable to cd9660 filesystems. 745 */ 746 int 747 cd9660_pathconf(void *v) 748 { 749 struct vop_pathconf_args /* { 750 struct vnode *a_vp; 751 int a_name; 752 register_t *a_retval; 753 } */ *ap = v; 754 switch (ap->a_name) { 755 case _PC_LINK_MAX: 756 *ap->a_retval = 1; 757 return (0); 758 case _PC_NAME_MAX: 759 if (VTOI(ap->a_vp)->i_mnt->iso_ftype == ISO_FTYPE_RRIP) 760 *ap->a_retval = ISO_MAXNAMLEN; 761 else 762 *ap->a_retval = 37; 763 return (0); 764 case _PC_PATH_MAX: 765 *ap->a_retval = PATH_MAX; 766 return (0); 767 case _PC_PIPE_BUF: 768 *ap->a_retval = PIPE_BUF; 769 return (0); 770 case _PC_CHOWN_RESTRICTED: 771 *ap->a_retval = 1; 772 return (0); 773 case _PC_NO_TRUNC: 774 *ap->a_retval = 1; 775 return (0); 776 case _PC_SYNC_IO: 777 *ap->a_retval = 1; 778 return (0); 779 case _PC_FILESIZEBITS: 780 *ap->a_retval = 32; 781 return (0); 782 default: 783 return (EINVAL); 784 } 785 /* NOTREACHED */ 786 } 787 788 /* 789 * Allow changing the size for special files (and fifos). 790 */ 791 int 792 cd9660_setattr(void *v) 793 { 794 struct vop_setattr_args /* { 795 struct vnodeop_desc *a_desc; 796 struct vnode *a_vp; 797 struct vattr *a_vap; 798 kauth_cred_t a_cred; 799 struct proc *a_p; 800 } */ *ap = v; 801 struct vattr *vap = ap->a_vap; 802 struct vnode *vp = ap->a_vp; 803 804 /* 805 * Only size is changeable. 806 */ 807 if (vap->va_type != VNON 808 || vap->va_nlink != (nlink_t)VNOVAL 809 || vap->va_fsid != VNOVAL 810 || vap->va_fileid != VNOVAL 811 || vap->va_blocksize != VNOVAL 812 || vap->va_rdev != (dev_t)VNOVAL 813 || (int)vap->va_bytes != VNOVAL 814 || vap->va_gen != VNOVAL 815 || vap->va_flags != VNOVAL 816 || vap->va_uid != (uid_t)VNOVAL 817 || vap->va_gid != (gid_t)VNOVAL 818 || vap->va_atime.tv_sec != VNOVAL 819 || vap->va_mtime.tv_sec != VNOVAL 820 || vap->va_mode != (mode_t)VNOVAL) 821 return EOPNOTSUPP; 822 823 if (vap->va_size != VNOVAL 824 && vp->v_type != VCHR 825 && vp->v_type != VBLK 826 && vp->v_type != VFIFO) 827 return EOPNOTSUPP; 828 829 return 0; 830 } 831 832 /* 833 * Global vfs data structures for isofs 834 */ 835 #define cd9660_create genfs_eopnotsupp 836 #define cd9660_mknod genfs_eopnotsupp 837 #define cd9660_write genfs_eopnotsupp 838 #define cd9660_fsync genfs_nullop 839 #define cd9660_remove genfs_eopnotsupp 840 #define cd9660_rename genfs_eopnotsupp 841 #define cd9660_mkdir genfs_eopnotsupp 842 #define cd9660_rmdir genfs_eopnotsupp 843 #define cd9660_advlock genfs_einval 844 #define cd9660_bwrite genfs_eopnotsupp 845 #define cd9660_revoke genfs_revoke 846 847 /* 848 * Global vfs data structures for cd9660 849 */ 850 int (**cd9660_vnodeop_p)(void *); 851 const struct vnodeopv_entry_desc cd9660_vnodeop_entries[] = { 852 { &vop_default_desc, vn_default_error }, 853 { &vop_lookup_desc, cd9660_lookup }, /* lookup */ 854 { &vop_create_desc, cd9660_create }, /* create */ 855 { &vop_mknod_desc, cd9660_mknod }, /* mknod */ 856 { &vop_open_desc, cd9660_open }, /* open */ 857 { &vop_close_desc, cd9660_close }, /* close */ 858 { &vop_access_desc, cd9660_access }, /* access */ 859 { &vop_getattr_desc, cd9660_getattr }, /* getattr */ 860 { &vop_setattr_desc, cd9660_setattr }, /* setattr */ 861 { &vop_read_desc, cd9660_read }, /* read */ 862 { &vop_write_desc, cd9660_write }, /* write */ 863 { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */ 864 { &vop_ioctl_desc, cd9660_ioctl }, /* ioctl */ 865 { &vop_poll_desc, cd9660_poll }, /* poll */ 866 { &vop_revoke_desc, cd9660_revoke }, /* revoke */ 867 { &vop_mmap_desc, cd9660_mmap }, /* mmap */ 868 { &vop_fsync_desc, cd9660_fsync }, /* fsync */ 869 { &vop_seek_desc, cd9660_seek }, /* seek */ 870 { &vop_remove_desc, cd9660_remove }, /* remove */ 871 { &vop_link_desc, cd9660_link }, /* link */ 872 { &vop_rename_desc, cd9660_rename }, /* rename */ 873 { &vop_mkdir_desc, cd9660_mkdir }, /* mkdir */ 874 { &vop_rmdir_desc, cd9660_rmdir }, /* rmdir */ 875 { &vop_symlink_desc, cd9660_symlink }, /* symlink */ 876 { &vop_readdir_desc, cd9660_readdir }, /* readdir */ 877 { &vop_readlink_desc, cd9660_readlink }, /* readlink */ 878 { &vop_abortop_desc, cd9660_abortop }, /* abortop */ 879 { &vop_inactive_desc, cd9660_inactive }, /* inactive */ 880 { &vop_reclaim_desc, cd9660_reclaim }, /* reclaim */ 881 { &vop_lock_desc, genfs_lock }, /* lock */ 882 { &vop_unlock_desc, genfs_unlock }, /* unlock */ 883 { &vop_bmap_desc, cd9660_bmap }, /* bmap */ 884 { &vop_strategy_desc, cd9660_strategy }, /* strategy */ 885 { &vop_print_desc, cd9660_print }, /* print */ 886 { &vop_islocked_desc, genfs_islocked }, /* islocked */ 887 { &vop_pathconf_desc, cd9660_pathconf }, /* pathconf */ 888 { &vop_advlock_desc, cd9660_advlock }, /* advlock */ 889 { &vop_bwrite_desc, vn_bwrite }, /* bwrite */ 890 { &vop_getpages_desc, genfs_getpages }, /* getpages */ 891 { &vop_putpages_desc, genfs_putpages }, /* putpages */ 892 { NULL, NULL } 893 }; 894 const struct vnodeopv_desc cd9660_vnodeop_opv_desc = 895 { &cd9660_vnodeop_p, cd9660_vnodeop_entries }; 896 897 /* 898 * Special device vnode ops 899 */ 900 int (**cd9660_specop_p)(void *); 901 const struct vnodeopv_entry_desc cd9660_specop_entries[] = { 902 { &vop_default_desc, vn_default_error }, 903 { &vop_lookup_desc, spec_lookup }, /* lookup */ 904 { &vop_create_desc, spec_create }, /* create */ 905 { &vop_mknod_desc, spec_mknod }, /* mknod */ 906 { &vop_open_desc, spec_open }, /* open */ 907 { &vop_close_desc, spec_close }, /* close */ 908 { &vop_access_desc, cd9660_access }, /* access */ 909 { &vop_getattr_desc, cd9660_getattr }, /* getattr */ 910 { &vop_setattr_desc, cd9660_setattr }, /* setattr */ 911 { &vop_read_desc, spec_read }, /* read */ 912 { &vop_write_desc, spec_write }, /* write */ 913 { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */ 914 { &vop_ioctl_desc, spec_ioctl }, /* ioctl */ 915 { &vop_poll_desc, spec_poll }, /* poll */ 916 { &vop_kqfilter_desc, spec_kqfilter }, /* kqfilter */ 917 { &vop_revoke_desc, spec_revoke }, /* revoke */ 918 { &vop_mmap_desc, spec_mmap }, /* mmap */ 919 { &vop_fsync_desc, spec_fsync }, /* fsync */ 920 { &vop_seek_desc, spec_seek }, /* seek */ 921 { &vop_remove_desc, spec_remove }, /* remove */ 922 { &vop_link_desc, spec_link }, /* link */ 923 { &vop_rename_desc, spec_rename }, /* rename */ 924 { &vop_mkdir_desc, spec_mkdir }, /* mkdir */ 925 { &vop_rmdir_desc, spec_rmdir }, /* rmdir */ 926 { &vop_symlink_desc, spec_symlink }, /* symlink */ 927 { &vop_readdir_desc, spec_readdir }, /* readdir */ 928 { &vop_readlink_desc, spec_readlink }, /* readlink */ 929 { &vop_abortop_desc, spec_abortop }, /* abortop */ 930 { &vop_inactive_desc, cd9660_inactive }, /* inactive */ 931 { &vop_reclaim_desc, cd9660_reclaim }, /* reclaim */ 932 { &vop_lock_desc, genfs_lock }, /* lock */ 933 { &vop_unlock_desc, genfs_unlock }, /* unlock */ 934 { &vop_bmap_desc, spec_bmap }, /* bmap */ 935 { &vop_strategy_desc, spec_strategy }, /* strategy */ 936 { &vop_print_desc, cd9660_print }, /* print */ 937 { &vop_islocked_desc, genfs_islocked }, /* islocked */ 938 { &vop_pathconf_desc, spec_pathconf }, /* pathconf */ 939 { &vop_advlock_desc, spec_advlock }, /* advlock */ 940 { &vop_bwrite_desc, vn_bwrite }, /* bwrite */ 941 { &vop_getpages_desc, spec_getpages }, /* getpages */ 942 { &vop_putpages_desc, spec_putpages }, /* putpages */ 943 { NULL, NULL } 944 }; 945 const struct vnodeopv_desc cd9660_specop_opv_desc = 946 { &cd9660_specop_p, cd9660_specop_entries }; 947 948 int (**cd9660_fifoop_p)(void *); 949 const struct vnodeopv_entry_desc cd9660_fifoop_entries[] = { 950 { &vop_default_desc, vn_default_error }, 951 { &vop_lookup_desc, vn_fifo_bypass }, /* lookup */ 952 { &vop_create_desc, vn_fifo_bypass }, /* create */ 953 { &vop_mknod_desc, vn_fifo_bypass }, /* mknod */ 954 { &vop_open_desc, vn_fifo_bypass }, /* open */ 955 { &vop_close_desc, vn_fifo_bypass }, /* close */ 956 { &vop_access_desc, cd9660_access }, /* access */ 957 { &vop_getattr_desc, cd9660_getattr }, /* getattr */ 958 { &vop_setattr_desc, cd9660_setattr }, /* setattr */ 959 { &vop_read_desc, vn_fifo_bypass }, /* read */ 960 { &vop_write_desc, vn_fifo_bypass }, /* write */ 961 { &vop_fcntl_desc, genfs_fcntl }, /* fcntl */ 962 { &vop_ioctl_desc, vn_fifo_bypass }, /* ioctl */ 963 { &vop_poll_desc, vn_fifo_bypass }, /* poll */ 964 { &vop_kqfilter_desc, vn_fifo_bypass }, /* kqfilter */ 965 { &vop_revoke_desc, vn_fifo_bypass }, /* revoke */ 966 { &vop_mmap_desc, vn_fifo_bypass }, /* mmap */ 967 { &vop_fsync_desc, vn_fifo_bypass }, /* fsync */ 968 { &vop_seek_desc, vn_fifo_bypass }, /* seek */ 969 { &vop_remove_desc, vn_fifo_bypass }, /* remove */ 970 { &vop_link_desc, vn_fifo_bypass } , /* link */ 971 { &vop_rename_desc, vn_fifo_bypass }, /* rename */ 972 { &vop_mkdir_desc, vn_fifo_bypass }, /* mkdir */ 973 { &vop_rmdir_desc, vn_fifo_bypass }, /* rmdir */ 974 { &vop_symlink_desc, vn_fifo_bypass }, /* symlink */ 975 { &vop_readdir_desc, vn_fifo_bypass }, /* readdir */ 976 { &vop_readlink_desc, vn_fifo_bypass }, /* readlink */ 977 { &vop_abortop_desc, vn_fifo_bypass }, /* abortop */ 978 { &vop_inactive_desc, cd9660_inactive }, /* inactive */ 979 { &vop_reclaim_desc, cd9660_reclaim }, /* reclaim */ 980 { &vop_lock_desc, genfs_lock }, /* lock */ 981 { &vop_unlock_desc, genfs_unlock }, /* unlock */ 982 { &vop_bmap_desc, vn_fifo_bypass }, /* bmap */ 983 { &vop_strategy_desc, vn_fifo_bypass }, /* strategy */ 984 { &vop_print_desc, cd9660_print }, /* print */ 985 { &vop_islocked_desc, genfs_islocked }, /* islocked */ 986 { &vop_pathconf_desc, vn_fifo_bypass }, /* pathconf */ 987 { &vop_advlock_desc, vn_fifo_bypass }, /* advlock */ 988 { &vop_bwrite_desc, vn_bwrite }, /* bwrite */ 989 { &vop_putpages_desc, vn_fifo_bypass }, /* putpages */ 990 { NULL, NULL } 991 }; 992 const struct vnodeopv_desc cd9660_fifoop_opv_desc = 993 { &cd9660_fifoop_p, cd9660_fifoop_entries }; 994