1 /* $OpenBSD: cd9660_vnops.c,v 1.95 2023/09/08 20:00:28 mvs Exp $ */ 2 /* $NetBSD: cd9660_vnops.c,v 1.42 1997/10/16 23:56:57 christos Exp $ */ 3 4 /*- 5 * Copyright (c) 1994 6 * The Regents of the University of California. All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley 9 * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension 10 * Support code is derived from software contributed to Berkeley 11 * by Atsushi Murai (amurai@spec.co.jp). 12 * 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the following conditions 15 * are met: 16 * 1. Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * 2. Redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution. 21 * 3. Neither the name of the University nor the names of its contributors 22 * may be used to endorse or promote products derived from this software 23 * without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35 * SUCH DAMAGE. 36 * 37 * @(#)cd9660_vnops.c 8.15 (Berkeley) 12/5/94 38 */ 39 40 #include <sys/param.h> 41 #include <sys/systm.h> 42 #include <sys/namei.h> 43 #include <sys/resourcevar.h> 44 #include <sys/kernel.h> 45 #include <sys/file.h> 46 #include <sys/stat.h> 47 #include <sys/buf.h> 48 #include <sys/conf.h> 49 #include <sys/mount.h> 50 #include <sys/vnode.h> 51 #include <sys/lock.h> 52 #include <sys/malloc.h> 53 #include <sys/pool.h> 54 #include <sys/dirent.h> 55 #include <sys/ioctl.h> 56 #include <sys/ioccom.h> 57 #include <sys/specdev.h> 58 #include <sys/unistd.h> 59 60 #include <miscfs/fifofs/fifo.h> 61 62 #include <isofs/cd9660/iso.h> 63 #include <isofs/cd9660/cd9660_extern.h> 64 #include <isofs/cd9660/cd9660_node.h> 65 #include <isofs/cd9660/iso_rrip.h> 66 67 int cd9660_kqfilter(void *v); 68 69 70 /* 71 * Structure for reading directories 72 */ 73 struct isoreaddir { 74 struct dirent saveent; 75 struct dirent assocent; 76 struct dirent current; 77 off_t saveoff; 78 off_t assocoff; 79 off_t curroff; 80 struct uio *uio; 81 off_t uio_off; 82 int eofflag; 83 }; 84 85 int iso_uiodir(struct isoreaddir *, struct dirent *, off_t); 86 int iso_shipdir(struct isoreaddir *); 87 88 /* 89 * Setattr call. Only allowed for block and character special devices. 90 */ 91 int 92 cd9660_setattr(void *v) 93 { 94 struct vop_setattr_args *ap = v; 95 struct vnode *vp = ap->a_vp; 96 struct vattr *vap = ap->a_vap; 97 98 if (vap->va_flags != VNOVAL || vap->va_uid != (uid_t)VNOVAL || 99 vap->va_gid != (gid_t)VNOVAL || vap->va_atime.tv_nsec != VNOVAL || 100 vap->va_mtime.tv_nsec != VNOVAL || vap->va_mode != (mode_t)VNOVAL || 101 (vap->va_vaflags & VA_UTIMES_CHANGE)) 102 return (EROFS); 103 if (vap->va_size != VNOVAL) { 104 switch (vp->v_type) { 105 case VDIR: 106 return (EISDIR); 107 case VLNK: 108 case VREG: 109 return (EROFS); 110 case VCHR: 111 case VBLK: 112 case VSOCK: 113 case VFIFO: 114 return (0); 115 default: 116 return (EINVAL); 117 } 118 } 119 120 return (EINVAL); 121 } 122 123 /* 124 * Open called. 125 * 126 * Nothing to do. 127 */ 128 int 129 cd9660_open(void *v) 130 { 131 return (0); 132 } 133 134 /* 135 * Close called 136 * 137 * Update the times on the inode on writeable file systems. 138 */ 139 int 140 cd9660_close(void *v) 141 { 142 return (0); 143 } 144 145 /* 146 * Check mode permission on inode pointer. Mode is READ, WRITE or EXEC. 147 * The mode is shifted to select the owner/group/other fields. The 148 * super user is granted all permissions. 149 */ 150 int 151 cd9660_access(void *v) 152 { 153 struct vop_access_args *ap = v; 154 struct iso_node *ip = VTOI(ap->a_vp); 155 156 return (vaccess(ap->a_vp->v_type, ip->inode.iso_mode & ALLPERMS, 157 ip->inode.iso_uid, ip->inode.iso_gid, ap->a_mode, ap->a_cred)); 158 } 159 160 int 161 cd9660_getattr(void *v) 162 { 163 struct vop_getattr_args *ap = v; 164 struct vnode *vp = ap->a_vp; 165 struct vattr *vap = ap->a_vap; 166 struct iso_node *ip = VTOI(vp); 167 168 vap->va_fsid = ip->i_dev; 169 vap->va_fileid = ip->i_number; 170 171 vap->va_mode = ip->inode.iso_mode & ALLPERMS; 172 vap->va_nlink = ip->inode.iso_links; 173 vap->va_uid = ip->inode.iso_uid; 174 vap->va_gid = ip->inode.iso_gid; 175 vap->va_atime = ip->inode.iso_atime; 176 vap->va_mtime = ip->inode.iso_mtime; 177 vap->va_ctime = ip->inode.iso_ctime; 178 vap->va_rdev = ip->inode.iso_rdev; 179 180 vap->va_size = (u_quad_t) ip->i_size; 181 if (ip->i_size == 0 && vp->v_type == VLNK) { 182 struct vop_readlink_args rdlnk; 183 struct iovec aiov; 184 struct uio auio; 185 char *cp; 186 187 cp = malloc(MAXPATHLEN, M_TEMP, M_WAITOK); 188 aiov.iov_base = cp; 189 aiov.iov_len = MAXPATHLEN; 190 auio.uio_iov = &aiov; 191 auio.uio_iovcnt = 1; 192 auio.uio_offset = 0; 193 auio.uio_rw = UIO_READ; 194 auio.uio_segflg = UIO_SYSSPACE; 195 auio.uio_procp = ap->a_p; 196 auio.uio_resid = MAXPATHLEN; 197 rdlnk.a_uio = &auio; 198 rdlnk.a_vp = ap->a_vp; 199 rdlnk.a_cred = ap->a_cred; 200 if (cd9660_readlink(&rdlnk) == 0) 201 vap->va_size = MAXPATHLEN - auio.uio_resid; 202 free(cp, M_TEMP, 0); 203 } 204 vap->va_flags = 0; 205 vap->va_gen = 1; 206 vap->va_blocksize = ip->i_mnt->logical_block_size; 207 vap->va_bytes = (u_quad_t) ip->i_size; 208 vap->va_type = vp->v_type; 209 return (0); 210 } 211 212 /* 213 * Vnode op for reading. 214 */ 215 int 216 cd9660_read(void *v) 217 { 218 struct vop_read_args *ap = v; 219 struct vnode *vp = ap->a_vp; 220 struct uio *uio = ap->a_uio; 221 struct iso_node *ip = VTOI(vp); 222 struct iso_mnt *imp; 223 struct buf *bp; 224 daddr_t lbn, rablock; 225 off_t diff; 226 int error = 0; 227 long size, on; 228 size_t n; 229 230 if (uio->uio_resid == 0) 231 return (0); 232 if (uio->uio_offset < 0) 233 return (EINVAL); 234 ip->i_flag |= IN_ACCESS; 235 imp = ip->i_mnt; 236 do { 237 struct cluster_info *ci = &ip->i_ci; 238 239 lbn = lblkno(imp, uio->uio_offset); 240 on = blkoff(imp, uio->uio_offset); 241 n = ulmin(imp->logical_block_size - on, uio->uio_resid); 242 diff = (off_t)ip->i_size - uio->uio_offset; 243 if (diff <= 0) 244 return (0); 245 if (diff < n) 246 n = diff; 247 size = blksize(imp, ip, lbn); 248 rablock = lbn + 1; 249 #define MAX_RA 32 250 if (ci->ci_lastr + 1 == lbn) { 251 struct ra { 252 daddr_t blks[MAX_RA]; 253 int sizes[MAX_RA]; 254 } *ra; 255 int i; 256 257 ra = malloc(sizeof *ra, M_TEMP, M_WAITOK); 258 for (i = 0; i < MAX_RA && 259 lblktosize(imp, (rablock + i)) < ip->i_size; 260 i++) { 261 ra->blks[i] = rablock + i; 262 ra->sizes[i] = blksize(imp, ip, rablock + i); 263 } 264 error = breadn(vp, lbn, size, ra->blks, 265 ra->sizes, i, &bp); 266 free(ra, M_TEMP, 0); 267 } else 268 error = bread(vp, lbn, size, &bp); 269 ci->ci_lastr = lbn; 270 n = ulmin(n, size - bp->b_resid); 271 if (error) { 272 brelse(bp); 273 return (error); 274 } 275 276 error = uiomove(bp->b_data + on, n, uio); 277 278 brelse(bp); 279 } while (error == 0 && uio->uio_resid > 0 && n != 0); 280 return (error); 281 } 282 283 int 284 cd9660_ioctl(void *v) 285 { 286 return (ENOTTY); 287 } 288 289 /* 290 * Mmap a file 291 * 292 * NB Currently unsupported. 293 */ 294 int 295 cd9660_mmap(void *v) 296 { 297 298 return (EINVAL); 299 } 300 301 /* 302 * Seek on a file 303 * 304 * Nothing to do, so just return. 305 */ 306 int 307 cd9660_seek(void *v) 308 { 309 return (0); 310 } 311 312 int 313 iso_uiodir(struct isoreaddir *idp, struct dirent *dp, off_t off) 314 { 315 int error; 316 317 dp->d_name[dp->d_namlen] = 0; 318 dp->d_reclen = DIRENT_SIZE(dp); 319 320 if (idp->uio->uio_resid < dp->d_reclen) { 321 idp->eofflag = 0; 322 return (-1); 323 } 324 325 dp->d_off = off; 326 if ((error = uiomove(dp, dp->d_reclen, idp->uio)) != 0) 327 return (error); 328 idp->uio_off = off; 329 return (0); 330 } 331 332 int 333 iso_shipdir(struct isoreaddir *idp) 334 { 335 struct dirent *dp; 336 int cl, sl, assoc; 337 int error; 338 char *cname, *sname; 339 340 cl = idp->current.d_namlen; 341 cname = idp->current.d_name; 342 343 if ((assoc = cl > 1 && *cname == ASSOCCHAR)) { 344 cl--; 345 cname++; 346 } 347 348 dp = &idp->saveent; 349 sname = dp->d_name; 350 if (!(sl = dp->d_namlen)) { 351 dp = &idp->assocent; 352 sname = dp->d_name + 1; 353 sl = dp->d_namlen - 1; 354 } 355 if (sl > 0) { 356 if (sl != cl 357 || bcmp(sname,cname,sl)) { 358 if (idp->assocent.d_namlen) { 359 error = iso_uiodir(idp, &idp->assocent, 360 idp->assocoff); 361 if (error) 362 return (error); 363 idp->assocent.d_namlen = 0; 364 } 365 if (idp->saveent.d_namlen) { 366 error = iso_uiodir(idp, &idp->saveent, 367 idp->saveoff); 368 if (error) 369 return (error); 370 idp->saveent.d_namlen = 0; 371 } 372 } 373 } 374 idp->current.d_reclen = DIRENT_SIZE(&idp->current); 375 if (assoc) { 376 idp->assocoff = idp->curroff; 377 bcopy(&idp->current,&idp->assocent,idp->current.d_reclen); 378 } else { 379 idp->saveoff = idp->curroff; 380 bcopy(&idp->current,&idp->saveent,idp->current.d_reclen); 381 } 382 return (0); 383 } 384 385 /* 386 * Vnode op for readdir 387 */ 388 int 389 cd9660_readdir(void *v) 390 { 391 struct vop_readdir_args *ap = v; 392 struct uio *uio = ap->a_uio; 393 struct isoreaddir *idp; 394 struct vnode *vdp = ap->a_vp; 395 struct iso_node *dp; 396 struct iso_mnt *imp; 397 struct buf *bp = NULL; 398 struct iso_directory_record *ep; 399 int entryoffsetinblock; 400 doff_t endsearch; 401 u_long bmask; 402 int error = 0; 403 int reclen; 404 u_short namelen; 405 cdino_t ino; 406 407 dp = VTOI(vdp); 408 imp = dp->i_mnt; 409 bmask = imp->im_bmask; 410 411 idp = malloc(sizeof(*idp), M_TEMP, M_WAITOK); 412 413 /* 414 * These are passed to copyout(), so make sure there's no garbage 415 * being leaked in padding or after short names. 416 */ 417 memset(&idp->saveent, 0, sizeof(idp->saveent)); 418 memset(&idp->assocent, 0, sizeof(idp->assocent)); 419 memset(&idp->current, 0, sizeof(idp->current)); 420 421 /* 422 * XXX 423 * Is it worth trying to figure out the type? 424 */ 425 idp->saveent.d_type = idp->assocent.d_type = idp->current.d_type = 426 DT_UNKNOWN; 427 idp->uio = uio; 428 idp->eofflag = 1; 429 idp->curroff = uio->uio_offset; 430 idp->uio_off = uio->uio_offset; 431 432 if ((entryoffsetinblock = idp->curroff & bmask) && 433 (error = cd9660_bufatoff(dp, (off_t)idp->curroff, NULL, &bp))) { 434 free(idp, M_TEMP, 0); 435 return (error); 436 } 437 endsearch = dp->i_size; 438 439 while (idp->curroff < endsearch) { 440 /* 441 * If offset is on a block boundary, 442 * read the next directory block. 443 * Release previous if it exists. 444 */ 445 if ((idp->curroff & bmask) == 0) { 446 if (bp != NULL) 447 brelse(bp); 448 error = cd9660_bufatoff(dp, (off_t)idp->curroff, 449 NULL, &bp); 450 if (error) 451 break; 452 entryoffsetinblock = 0; 453 } 454 /* 455 * Get pointer to next entry. 456 */ 457 ep = (struct iso_directory_record *) 458 ((char *)bp->b_data + entryoffsetinblock); 459 460 reclen = isonum_711(ep->length); 461 if (reclen == 0) { 462 /* skip to next block, if any */ 463 idp->curroff = 464 (idp->curroff & ~bmask) + imp->logical_block_size; 465 continue; 466 } 467 468 if (reclen < ISO_DIRECTORY_RECORD_SIZE) { 469 error = EINVAL; 470 /* illegal entry, stop */ 471 break; 472 } 473 474 if (entryoffsetinblock + reclen > imp->logical_block_size) { 475 error = EINVAL; 476 /* illegal directory, so stop looking */ 477 break; 478 } 479 480 idp->current.d_namlen = isonum_711(ep->name_len); 481 482 if (reclen < ISO_DIRECTORY_RECORD_SIZE + idp->current.d_namlen) { 483 error = EINVAL; 484 /* illegal entry, stop */ 485 break; 486 } 487 488 if (isonum_711(ep->flags)&2) 489 ino = isodirino(ep, imp); 490 else 491 ino = dbtob(bp->b_blkno) + entryoffsetinblock; 492 493 idp->curroff += reclen; 494 495 switch (imp->iso_ftype) { 496 case ISO_FTYPE_RRIP: 497 cd9660_rrip_getname(ep,idp->current.d_name, &namelen, 498 &ino, imp); 499 idp->current.d_fileno = ino; 500 idp->current.d_namlen = (u_char)namelen; 501 if (idp->current.d_namlen) 502 error = iso_uiodir(idp,&idp->current,idp->curroff); 503 break; 504 default: /* ISO_FTYPE_DEFAULT || ISO_FTYPE_9660 */ 505 idp->current.d_fileno = ino; 506 strlcpy(idp->current.d_name,"..", 507 sizeof idp->current.d_name); 508 if (idp->current.d_namlen == 1 && ep->name[0] == 0) { 509 idp->current.d_namlen = 1; 510 error = iso_uiodir(idp,&idp->current,idp->curroff); 511 } else if (idp->current.d_namlen == 1 && 512 ep->name[0] == 1) { 513 idp->current.d_namlen = 2; 514 error = iso_uiodir(idp,&idp->current,idp->curroff); 515 } else { 516 isofntrans(ep->name,idp->current.d_namlen, 517 idp->current.d_name, &namelen, 518 imp->iso_ftype == ISO_FTYPE_9660, 519 isonum_711(ep->flags) & 4, 520 imp->joliet_level); 521 idp->current.d_namlen = (u_char)namelen; 522 if (imp->iso_ftype == ISO_FTYPE_DEFAULT) 523 error = iso_shipdir(idp); 524 else 525 error = iso_uiodir(idp,&idp->current,idp->curroff); 526 } 527 } 528 if (error) 529 break; 530 531 entryoffsetinblock += reclen; 532 } 533 534 if (!error && imp->iso_ftype == ISO_FTYPE_DEFAULT) { 535 idp->current.d_namlen = 0; 536 error = iso_shipdir(idp); 537 } 538 if (error < 0) 539 error = 0; 540 541 if (bp) 542 brelse (bp); 543 544 uio->uio_offset = idp->uio_off; 545 *ap->a_eofflag = idp->eofflag; 546 547 free(idp, M_TEMP, 0); 548 549 return (error); 550 } 551 552 /* 553 * Return target name of a symbolic link 554 * Shouldn't we get the parent vnode and read the data from there? 555 * This could eventually result in deadlocks in cd9660_lookup. 556 * But otherwise the block read here is in the block buffer two times. 557 */ 558 typedef struct iso_directory_record ISODIR; 559 typedef struct iso_node ISONODE; 560 typedef struct iso_mnt ISOMNT; 561 int 562 cd9660_readlink(void *v) 563 { 564 struct vop_readlink_args *ap = v; 565 ISONODE *ip; 566 ISODIR *dirp; 567 ISOMNT *imp; 568 struct buf *bp; 569 struct uio *uio; 570 u_short symlen; 571 int error; 572 char *symname; 573 574 ip = VTOI(ap->a_vp); 575 imp = ip->i_mnt; 576 uio = ap->a_uio; 577 578 if (imp->iso_ftype != ISO_FTYPE_RRIP) 579 return (EINVAL); 580 581 /* 582 * Get parents directory record block that this inode included. 583 */ 584 error = bread(imp->im_devvp, 585 (ip->i_number >> imp->im_bshift) << 586 (imp->im_bshift - DEV_BSHIFT), 587 imp->logical_block_size, &bp); 588 if (error) { 589 brelse(bp); 590 return (EINVAL); 591 } 592 593 /* 594 * Setup the directory pointer for this inode 595 */ 596 dirp = (ISODIR *)(bp->b_data + (ip->i_number & imp->im_bmask)); 597 598 /* 599 * Just make sure, we have a right one.... 600 * 1: Check not cross boundary on block 601 */ 602 if ((ip->i_number & imp->im_bmask) + isonum_711(dirp->length) 603 > imp->logical_block_size) { 604 brelse(bp); 605 return (EINVAL); 606 } 607 608 /* 609 * Now get a buffer 610 * Abuse a namei buffer for now. 611 */ 612 if (uio->uio_segflg == UIO_SYSSPACE && 613 uio->uio_iov->iov_len >= MAXPATHLEN) 614 symname = uio->uio_iov->iov_base; 615 else 616 symname = pool_get(&namei_pool, PR_WAITOK); 617 618 /* 619 * Ok, we just gathering a symbolic name in SL record. 620 */ 621 if (cd9660_rrip_getsymname(dirp, symname, &symlen, imp) == 0) { 622 if (uio->uio_segflg != UIO_SYSSPACE || 623 uio->uio_iov->iov_len < MAXPATHLEN) 624 pool_put(&namei_pool, symname); 625 brelse(bp); 626 return (EINVAL); 627 } 628 /* 629 * Don't forget before you leave from home ;-) 630 */ 631 brelse(bp); 632 633 /* 634 * return with the symbolic name to caller's. 635 */ 636 if (uio->uio_segflg != UIO_SYSSPACE || 637 uio->uio_iov->iov_len < MAXPATHLEN) { 638 error = uiomove(symname, symlen, uio); 639 pool_put(&namei_pool, symname); 640 return (error); 641 } 642 uio->uio_resid -= symlen; 643 uio->uio_iov->iov_base = (char *)uio->uio_iov->iov_base + symlen; 644 uio->uio_iov->iov_len -= symlen; 645 return (0); 646 } 647 648 int 649 cd9660_link(void *v) 650 { 651 struct vop_link_args *ap = v; 652 653 VOP_ABORTOP(ap->a_dvp, ap->a_cnp); 654 vput(ap->a_dvp); 655 return (EROFS); 656 } 657 658 int 659 cd9660_symlink(void *v) 660 { 661 struct vop_symlink_args *ap = v; 662 663 VOP_ABORTOP(ap->a_dvp, ap->a_cnp); 664 vput(ap->a_dvp); 665 return (EROFS); 666 } 667 668 /* 669 * Lock an inode. 670 */ 671 int 672 cd9660_lock(void *v) 673 { 674 struct vop_lock_args *ap = v; 675 struct vnode *vp = ap->a_vp; 676 677 return rrw_enter(&VTOI(vp)->i_lock, ap->a_flags & LK_RWFLAGS); 678 } 679 680 /* 681 * Unlock an inode. 682 */ 683 int 684 cd9660_unlock(void *v) 685 { 686 struct vop_unlock_args *ap = v; 687 struct vnode *vp = ap->a_vp; 688 689 rrw_exit(&VTOI(vp)->i_lock); 690 return 0; 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 *ap = v; 701 struct buf *bp = ap->a_bp; 702 struct vnode *vp = bp->b_vp; 703 struct iso_node *ip; 704 int error; 705 int s; 706 707 ip = VTOI(vp); 708 if (vp->v_type == VBLK || vp->v_type == VCHR) 709 panic("cd9660_strategy: spec"); 710 if (bp->b_blkno == bp->b_lblkno) { 711 error = VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno, NULL); 712 if (error) { 713 bp->b_error = error; 714 bp->b_flags |= B_ERROR; 715 s = splbio(); 716 biodone(bp); 717 splx(s); 718 return (error); 719 } 720 if ((long)bp->b_blkno == -1) 721 clrbuf(bp); 722 } 723 if ((long)bp->b_blkno == -1) { 724 s = splbio(); 725 biodone(bp); 726 splx(s); 727 return (0); 728 } 729 vp = ip->i_devvp; 730 bp->b_dev = vp->v_rdev; 731 VOP_STRATEGY(vp, bp); 732 return (0); 733 } 734 735 /* 736 * Print out the contents of an inode. 737 */ 738 int 739 cd9660_print(void *v) 740 { 741 printf("tag VT_ISOFS, isofs vnode\n"); 742 return (0); 743 } 744 745 /* 746 * Check for a locked inode. 747 */ 748 int 749 cd9660_islocked(void *v) 750 { 751 struct vop_islocked_args *ap = v; 752 753 return rrw_status(&VTOI(ap->a_vp)->i_lock); 754 } 755 756 /* 757 * Return POSIX pathconf information applicable to cd9660 filesystems. 758 */ 759 int 760 cd9660_pathconf(void *v) 761 { 762 struct vop_pathconf_args *ap = v; 763 int error = 0; 764 765 switch (ap->a_name) { 766 case _PC_LINK_MAX: 767 *ap->a_retval = 1; 768 break; 769 case _PC_NAME_MAX: 770 if (VTOI(ap->a_vp)->i_mnt->iso_ftype == ISO_FTYPE_RRIP) 771 *ap->a_retval = NAME_MAX; 772 else 773 *ap->a_retval = 37; 774 break; 775 case _PC_CHOWN_RESTRICTED: 776 *ap->a_retval = 1; 777 break; 778 case _PC_NO_TRUNC: 779 *ap->a_retval = 1; 780 break; 781 case _PC_TIMESTAMP_RESOLUTION: 782 *ap->a_retval = 1000000000; /* one billion nanoseconds */ 783 break; 784 default: 785 error = EINVAL; 786 break; 787 } 788 789 return (error); 790 } 791 792 /* 793 * Global vfs data structures for isofs 794 */ 795 796 /* Global vfs data structures for cd9660. */ 797 const struct vops cd9660_vops = { 798 .vop_lookup = cd9660_lookup, 799 .vop_create = eopnotsupp, 800 .vop_mknod = eopnotsupp, 801 .vop_open = cd9660_open, 802 .vop_close = cd9660_close, 803 .vop_access = cd9660_access, 804 .vop_getattr = cd9660_getattr, 805 .vop_setattr = cd9660_setattr, 806 .vop_read = cd9660_read, 807 .vop_write = eopnotsupp, 808 .vop_ioctl = cd9660_ioctl, 809 .vop_kqfilter = cd9660_kqfilter, 810 .vop_revoke = vop_generic_revoke, 811 .vop_fsync = nullop, 812 .vop_remove = eopnotsupp, 813 .vop_link = cd9660_link, 814 .vop_rename = eopnotsupp, 815 .vop_mkdir = eopnotsupp, 816 .vop_rmdir = eopnotsupp, 817 .vop_symlink = cd9660_symlink, 818 .vop_readdir = cd9660_readdir, 819 .vop_readlink = cd9660_readlink, 820 .vop_abortop = vop_generic_abortop, 821 .vop_inactive = cd9660_inactive, 822 .vop_reclaim = cd9660_reclaim, 823 .vop_lock = cd9660_lock, 824 .vop_unlock = cd9660_unlock, 825 .vop_bmap = cd9660_bmap, 826 .vop_strategy = cd9660_strategy, 827 .vop_print = cd9660_print, 828 .vop_islocked = cd9660_islocked, 829 .vop_pathconf = cd9660_pathconf, 830 .vop_advlock = eopnotsupp, 831 .vop_bwrite = vop_generic_bwrite, 832 }; 833 834 /* Special device vnode ops */ 835 const struct vops cd9660_specvops = { 836 .vop_access = cd9660_access, 837 .vop_getattr = cd9660_getattr, 838 .vop_setattr = cd9660_setattr, 839 .vop_inactive = cd9660_inactive, 840 .vop_reclaim = cd9660_reclaim, 841 .vop_lock = cd9660_lock, 842 .vop_unlock = cd9660_unlock, 843 .vop_print = cd9660_print, 844 .vop_islocked = cd9660_islocked, 845 846 /* XXX: Keep in sync with spec_vops. */ 847 .vop_lookup = vop_generic_lookup, 848 .vop_create = vop_generic_badop, 849 .vop_mknod = vop_generic_badop, 850 .vop_open = spec_open, 851 .vop_close = spec_close, 852 .vop_read = spec_read, 853 .vop_write = spec_write, 854 .vop_ioctl = spec_ioctl, 855 .vop_kqfilter = spec_kqfilter, 856 .vop_revoke = vop_generic_revoke, 857 .vop_fsync = spec_fsync, 858 .vop_remove = vop_generic_badop, 859 .vop_link = vop_generic_badop, 860 .vop_rename = vop_generic_badop, 861 .vop_mkdir = vop_generic_badop, 862 .vop_rmdir = vop_generic_badop, 863 .vop_symlink = vop_generic_badop, 864 .vop_readdir = vop_generic_badop, 865 .vop_readlink = vop_generic_badop, 866 .vop_abortop = vop_generic_badop, 867 .vop_bmap = vop_generic_bmap, 868 .vop_strategy = spec_strategy, 869 .vop_pathconf = spec_pathconf, 870 .vop_advlock = spec_advlock, 871 .vop_bwrite = vop_generic_bwrite, 872 }; 873 874 #ifdef FIFO 875 const struct vops cd9660_fifovops = { 876 .vop_access = cd9660_access, 877 .vop_getattr = cd9660_getattr, 878 .vop_setattr = cd9660_setattr, 879 .vop_inactive = cd9660_inactive, 880 .vop_reclaim = cd9660_reclaim, 881 .vop_lock = cd9660_lock, 882 .vop_unlock = cd9660_unlock, 883 .vop_print = cd9660_print, 884 .vop_islocked = cd9660_islocked, 885 .vop_bwrite = vop_generic_bwrite, 886 887 /* XXX: Keep in sync with fifo_vops. */ 888 .vop_lookup = vop_generic_lookup, 889 .vop_create = vop_generic_badop, 890 .vop_mknod = vop_generic_badop, 891 .vop_open = fifo_open, 892 .vop_close = fifo_close, 893 .vop_read = fifo_read, 894 .vop_write = fifo_write, 895 .vop_ioctl = fifo_ioctl, 896 .vop_kqfilter = fifo_kqfilter, 897 .vop_revoke = vop_generic_revoke, 898 .vop_fsync = nullop, 899 .vop_remove = vop_generic_badop, 900 .vop_link = vop_generic_badop, 901 .vop_rename = vop_generic_badop, 902 .vop_mkdir = vop_generic_badop, 903 .vop_rmdir = vop_generic_badop, 904 .vop_symlink = vop_generic_badop, 905 .vop_readdir = vop_generic_badop, 906 .vop_readlink = vop_generic_badop, 907 .vop_abortop = vop_generic_badop, 908 .vop_bmap = vop_generic_bmap, 909 .vop_strategy = vop_generic_badop, 910 .vop_pathconf = fifo_pathconf, 911 .vop_advlock = fifo_advlock, 912 }; 913 #endif /* FIFO */ 914 915 void filt_cd9660detach(struct knote *kn); 916 int filt_cd9660read(struct knote *kn, long hint); 917 int filt_cd9660write(struct knote *kn, long hint); 918 int filt_cd9660vnode(struct knote *kn, long hint); 919 920 const struct filterops cd9660read_filtops = { 921 .f_flags = FILTEROP_ISFD, 922 .f_attach = NULL, 923 .f_detach = filt_cd9660detach, 924 .f_event = filt_cd9660read, 925 }; 926 927 const struct filterops cd9660write_filtops = { 928 .f_flags = FILTEROP_ISFD, 929 .f_attach = NULL, 930 .f_detach = filt_cd9660detach, 931 .f_event = filt_cd9660write, 932 }; 933 934 const struct filterops cd9660vnode_filtops = { 935 .f_flags = FILTEROP_ISFD, 936 .f_attach = NULL, 937 .f_detach = filt_cd9660detach, 938 .f_event = filt_cd9660vnode, 939 }; 940 941 int 942 cd9660_kqfilter(void *v) 943 { 944 struct vop_kqfilter_args *ap = v; 945 struct vnode *vp = ap->a_vp; 946 struct knote *kn = ap->a_kn; 947 948 switch (kn->kn_filter) { 949 case EVFILT_READ: 950 kn->kn_fop = &cd9660read_filtops; 951 break; 952 case EVFILT_WRITE: 953 kn->kn_fop = &cd9660write_filtops; 954 break; 955 case EVFILT_VNODE: 956 kn->kn_fop = &cd9660vnode_filtops; 957 break; 958 default: 959 return (EINVAL); 960 } 961 962 kn->kn_hook = (caddr_t)vp; 963 964 klist_insert_locked(&vp->v_klist, kn); 965 966 return (0); 967 } 968 969 void 970 filt_cd9660detach(struct knote *kn) 971 { 972 struct vnode *vp = (struct vnode *)kn->kn_hook; 973 974 klist_remove_locked(&vp->v_klist, kn); 975 } 976 977 int 978 filt_cd9660read(struct knote *kn, long hint) 979 { 980 struct vnode *vp = (struct vnode *)kn->kn_hook; 981 struct iso_node *node = VTOI(vp); 982 983 /* 984 * filesystem is gone, so set the EOF flag and schedule 985 * the knote for deletion. 986 */ 987 if (hint == NOTE_REVOKE) { 988 kn->kn_flags |= (EV_EOF | EV_ONESHOT); 989 return (1); 990 } 991 992 kn->kn_data = node->i_size - foffset(kn->kn_fp); 993 if (kn->kn_data == 0 && kn->kn_sfflags & NOTE_EOF) { 994 kn->kn_fflags |= NOTE_EOF; 995 return (1); 996 } 997 998 if (kn->kn_flags & (__EV_POLL | __EV_SELECT)) 999 return (1); 1000 1001 return (kn->kn_data != 0); 1002 } 1003 1004 int 1005 filt_cd9660write(struct knote *kn, long hint) 1006 { 1007 /* 1008 * filesystem is gone, so set the EOF flag and schedule 1009 * the knote for deletion. 1010 */ 1011 if (hint == NOTE_REVOKE) { 1012 kn->kn_flags |= (EV_EOF | EV_ONESHOT); 1013 return (1); 1014 } 1015 1016 kn->kn_data = 0; 1017 return (1); 1018 } 1019 1020 int 1021 filt_cd9660vnode(struct knote *kn, long hint) 1022 { 1023 if (kn->kn_sfflags & hint) 1024 kn->kn_fflags |= hint; 1025 if (hint == NOTE_REVOKE) { 1026 kn->kn_flags |= EV_EOF; 1027 return (1); 1028 } 1029 return (kn->kn_fflags != 0); 1030 } 1031