1 /* $OpenBSD: cd9660_vfsops.c,v 1.53 2009/12/19 00:27:17 krw Exp $ */ 2 /* $NetBSD: cd9660_vfsops.c,v 1.26 1997/06/13 15:38:58 pk 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_vfsops.c 8.9 (Berkeley) 12/5/94 38 */ 39 40 #include <sys/param.h> 41 #include <sys/systm.h> 42 #include <sys/namei.h> 43 #include <sys/proc.h> 44 #include <sys/kernel.h> 45 #include <sys/vnode.h> 46 #include <miscfs/specfs/specdev.h> 47 #include <sys/mount.h> 48 #include <sys/buf.h> 49 #include <sys/file.h> 50 #include <sys/disklabel.h> 51 #include <sys/ioctl.h> 52 #include <sys/cdio.h> 53 #include <sys/conf.h> 54 #include <sys/errno.h> 55 #include <sys/malloc.h> 56 #include <sys/stat.h> 57 58 #include <isofs/cd9660/iso.h> 59 #include <isofs/cd9660/cd9660_extern.h> 60 #include <isofs/cd9660/iso_rrip.h> 61 #include <isofs/cd9660/cd9660_node.h> 62 63 const struct vfsops cd9660_vfsops = { 64 cd9660_mount, 65 cd9660_start, 66 cd9660_unmount, 67 cd9660_root, 68 cd9660_quotactl, 69 cd9660_statfs, 70 cd9660_sync, 71 cd9660_vget, 72 cd9660_fhtovp, 73 cd9660_vptofh, 74 cd9660_init, 75 cd9660_sysctl, 76 cd9660_check_export 77 }; 78 79 /* 80 * Called by vfs_mountroot when iso is going to be mounted as root. 81 */ 82 83 static int iso_mountfs(struct vnode *devvp, struct mount *mp, 84 struct proc *p, struct iso_args *argp); 85 int iso_disklabelspoof(dev_t dev, void (*strat)(struct buf *), 86 struct disklabel *lp); 87 88 int 89 cd9660_mountroot() 90 { 91 struct mount *mp; 92 extern struct vnode *rootvp; 93 struct proc *p = curproc; /* XXX */ 94 int error; 95 struct iso_args args; 96 97 /* 98 * Get vnodes for swapdev and rootdev. 99 */ 100 if ((error = bdevvp(swapdev, &swapdev_vp)) || 101 (error = bdevvp(rootdev, &rootvp))) { 102 printf("cd9660_mountroot: can't setup bdevvp's"); 103 return (error); 104 } 105 106 if ((error = vfs_rootmountalloc("cd9660", "root_device", &mp)) != 0) 107 return (error); 108 args.flags = ISOFSMNT_ROOT; 109 if ((error = iso_mountfs(rootvp, mp, p, &args)) != 0) { 110 mp->mnt_vfc->vfc_refcount--; 111 vfs_unbusy(mp); 112 free(mp, M_MOUNT); 113 return (error); 114 } 115 116 CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list); 117 (void)cd9660_statfs(mp, &mp->mnt_stat, p); 118 vfs_unbusy(mp); 119 inittodr(0); 120 121 return (0); 122 } 123 124 /* 125 * VFS Operations. 126 * 127 * mount system call 128 */ 129 int 130 cd9660_mount(mp, path, data, ndp, p) 131 register struct mount *mp; 132 const char *path; 133 void *data; 134 struct nameidata *ndp; 135 struct proc *p; 136 { 137 struct vnode *devvp; 138 struct iso_args args; 139 size_t size; 140 int error; 141 struct iso_mnt *imp = NULL; 142 143 error = copyin(data, &args, sizeof (struct iso_args)); 144 if (error) 145 return (error); 146 147 if ((mp->mnt_flag & MNT_RDONLY) == 0) 148 return (EROFS); 149 150 /* 151 * If updating, check whether changing from read-only to 152 * read/write; if there is no device name, that's all we do. 153 */ 154 if (mp->mnt_flag & MNT_UPDATE) { 155 imp = VFSTOISOFS(mp); 156 if (args.fspec == 0) 157 return (vfs_export(mp, &imp->im_export, 158 &args.export_info)); 159 } 160 /* 161 * Not an update, or updating the name: look up the name 162 * and verify that it refers to a sensible block device. 163 */ 164 NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, p); 165 if ((error = namei(ndp)) != 0) 166 return (error); 167 devvp = ndp->ni_vp; 168 169 if (devvp->v_type != VBLK) { 170 vrele(devvp); 171 return (ENOTBLK); 172 } 173 if (major(devvp->v_rdev) >= nblkdev) { 174 vrele(devvp); 175 return (ENXIO); 176 } 177 /* 178 * If mount by non-root, then verify that user has necessary 179 * permissions on the device. 180 */ 181 if (suser(p, 0) != 0) { 182 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p); 183 error = VOP_ACCESS(devvp, VREAD, p->p_ucred, p); 184 if (error) { 185 vput(devvp); 186 return (error); 187 } 188 VOP_UNLOCK(devvp, 0, p); 189 } 190 if ((mp->mnt_flag & MNT_UPDATE) == 0) 191 error = iso_mountfs(devvp, mp, p, &args); 192 else { 193 if (devvp != imp->im_devvp) 194 error = EINVAL; /* needs translation */ 195 else 196 vrele(devvp); 197 } 198 if (error) { 199 vrele(devvp); 200 return (error); 201 } 202 imp = VFSTOISOFS(mp); 203 (void)copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size); 204 bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size); 205 (void)copyinstr(args.fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1, 206 &size); 207 bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size); 208 bcopy(&args, &mp->mnt_stat.mount_info.iso_args, sizeof(args)); 209 (void)cd9660_statfs(mp, &mp->mnt_stat, p); 210 return (0); 211 } 212 213 /* 214 * Common code for mount and mountroot 215 */ 216 static int 217 iso_mountfs(devvp, mp, p, argp) 218 register struct vnode *devvp; 219 struct mount *mp; 220 struct proc *p; 221 struct iso_args *argp; 222 { 223 register struct iso_mnt *isomp = (struct iso_mnt *)0; 224 struct buf *bp = NULL; 225 struct buf *pribp = NULL, *supbp = NULL; 226 dev_t dev = devvp->v_rdev; 227 int error = EINVAL; 228 int ronly = (mp->mnt_flag & MNT_RDONLY) != 0; 229 extern struct vnode *rootvp; 230 int iso_bsize; 231 int iso_blknum; 232 int joliet_level; 233 struct iso_volume_descriptor *vdp; 234 struct iso_primary_descriptor *pri = NULL; 235 struct iso_supplementary_descriptor *sup = NULL; 236 struct iso_directory_record *rootp; 237 int logical_block_size; 238 int sess; 239 240 if (!ronly) 241 return (EROFS); 242 243 /* 244 * Disallow multiple mounts of the same device. 245 * Disallow mounting of a device that is currently in use 246 * (except for root, which might share swap device for miniroot). 247 * Flush out any old buffers remaining from a previous use. 248 */ 249 if ((error = vfs_mountedon(devvp)) != 0) 250 return (error); 251 if (vcount(devvp) > 1 && devvp != rootvp) 252 return (EBUSY); 253 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p); 254 error = vinvalbuf(devvp, V_SAVE, p->p_ucred, p, 0, 0); 255 VOP_UNLOCK(devvp, 0, p); 256 if (error) 257 return (error); 258 259 error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, p); 260 if (error) 261 return (error); 262 263 /* 264 * This is the "logical sector size". The standard says this 265 * should be 2048 or the physical sector size on the device, 266 * whichever is greater. For now, we'll just use a constant. 267 */ 268 iso_bsize = ISO_DEFAULT_BLOCK_SIZE; 269 270 if (argp->flags & ISOFSMNT_SESS) { 271 sess = argp->sess; 272 if (sess < 0) 273 sess = 0; 274 } else { 275 sess = 0; 276 error = VOP_IOCTL(devvp, CDIOREADMSADDR, (caddr_t)&sess, 0, 277 FSCRED, p); 278 if (error) 279 sess = 0; 280 } 281 282 joliet_level = 0; 283 for (iso_blknum = 16; iso_blknum < 100; iso_blknum++) { 284 if ((error = bread(devvp, 285 (iso_blknum + sess) * btodb(iso_bsize), 286 iso_bsize, NOCRED, &bp)) != 0) 287 goto out; 288 289 vdp = (struct iso_volume_descriptor *)bp->b_data; 290 if (bcmp (vdp->id, ISO_STANDARD_ID, sizeof vdp->id) != 0) { 291 error = EINVAL; 292 goto out; 293 } 294 295 switch (isonum_711 (vdp->type)){ 296 case ISO_VD_PRIMARY: 297 if (pribp == NULL) { 298 pribp = bp; 299 bp = NULL; 300 pri = (struct iso_primary_descriptor *)vdp; 301 } 302 break; 303 case ISO_VD_SUPPLEMENTARY: 304 if (supbp == NULL) { 305 supbp = bp; 306 bp = NULL; 307 sup = (struct iso_supplementary_descriptor *)vdp; 308 309 if (!(argp->flags & ISOFSMNT_NOJOLIET)) { 310 if (bcmp(sup->escape, "%/@", 3) == 0) 311 joliet_level = 1; 312 if (bcmp(sup->escape, "%/C", 3) == 0) 313 joliet_level = 2; 314 if (bcmp(sup->escape, "%/E", 3) == 0) 315 joliet_level = 3; 316 317 if (isonum_711 (sup->flags) & 1) 318 joliet_level = 0; 319 } 320 } 321 break; 322 323 case ISO_VD_END: 324 goto vd_end; 325 326 default: 327 break; 328 } 329 if (bp) { 330 brelse(bp); 331 bp = NULL; 332 } 333 } 334 vd_end: 335 if (bp) { 336 brelse(bp); 337 bp = NULL; 338 } 339 340 if (pri == NULL) { 341 error = EINVAL; 342 goto out; 343 } 344 345 logical_block_size = isonum_723 (pri->logical_block_size); 346 347 if (logical_block_size < DEV_BSIZE || logical_block_size > MAXBSIZE 348 || (logical_block_size & (logical_block_size - 1)) != 0) { 349 error = EINVAL; 350 goto out; 351 } 352 353 rootp = (struct iso_directory_record *)pri->root_directory_record; 354 355 isomp = malloc(sizeof *isomp, M_ISOFSMNT, M_WAITOK); 356 bzero((caddr_t)isomp, sizeof *isomp); 357 isomp->logical_block_size = logical_block_size; 358 isomp->volume_space_size = isonum_733 (pri->volume_space_size); 359 bcopy (rootp, isomp->root, sizeof isomp->root); 360 isomp->root_extent = isonum_733 (rootp->extent); 361 isomp->root_size = isonum_733 (rootp->size); 362 isomp->joliet_level = 0; 363 /* 364 * Since an ISO9660 multi-session CD can also access previous sessions, 365 * we have to include them into the space considerations. 366 */ 367 isomp->volume_space_size += sess; 368 isomp->im_bmask = logical_block_size - 1; 369 isomp->im_bshift = ffs(logical_block_size) - 1; 370 371 pribp->b_flags |= B_AGE; 372 brelse(pribp); 373 pribp = NULL; 374 375 mp->mnt_data = (qaddr_t)isomp; 376 mp->mnt_stat.f_fsid.val[0] = (long)dev; 377 mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum; 378 mp->mnt_maxsymlinklen = 0; 379 mp->mnt_flag |= MNT_LOCAL; 380 isomp->im_mountp = mp; 381 isomp->im_dev = dev; 382 isomp->im_devvp = devvp; 383 384 /* Check the Rock Ridge Extension support */ 385 if (!(argp->flags & ISOFSMNT_NORRIP)) { 386 if ((error = bread(isomp->im_devvp, (isomp->root_extent + 387 isonum_711(rootp->ext_attr_length)) << 388 (isomp->im_bshift - DEV_BSHIFT), 389 isomp->logical_block_size, NOCRED, &bp)) != 0) 390 goto out; 391 392 rootp = (struct iso_directory_record *)bp->b_data; 393 394 if ((isomp->rr_skip = cd9660_rrip_offset(rootp,isomp)) < 0) { 395 argp->flags |= ISOFSMNT_NORRIP; 396 } else { 397 argp->flags &= ~ISOFSMNT_GENS; 398 } 399 400 /* 401 * The contents are valid, 402 * but they will get reread as part of another vnode, so... 403 */ 404 bp->b_flags |= B_AGE; 405 brelse(bp); 406 bp = NULL; 407 } 408 isomp->im_flags = argp->flags & (ISOFSMNT_NORRIP | ISOFSMNT_GENS | 409 ISOFSMNT_EXTATT | ISOFSMNT_NOJOLIET); 410 switch (isomp->im_flags & (ISOFSMNT_NORRIP | ISOFSMNT_GENS)) { 411 default: 412 isomp->iso_ftype = ISO_FTYPE_DEFAULT; 413 break; 414 case ISOFSMNT_GENS|ISOFSMNT_NORRIP: 415 isomp->iso_ftype = ISO_FTYPE_9660; 416 break; 417 case 0: 418 isomp->iso_ftype = ISO_FTYPE_RRIP; 419 break; 420 } 421 422 /* Decide whether to use the Joliet descriptor */ 423 424 if (isomp->iso_ftype != ISO_FTYPE_RRIP && joliet_level) { 425 rootp = (struct iso_directory_record *) 426 sup->root_directory_record; 427 bcopy(rootp, isomp->root, sizeof isomp->root); 428 isomp->root_extent = isonum_733(rootp->extent); 429 isomp->root_size = isonum_733(rootp->size); 430 isomp->joliet_level = joliet_level; 431 supbp->b_flags |= B_AGE; 432 } 433 434 if (supbp) { 435 brelse(supbp); 436 supbp = NULL; 437 } 438 439 devvp->v_specmountpoint = mp; 440 441 return (0); 442 out: 443 if (bp) 444 brelse(bp); 445 if (supbp) 446 brelse(supbp); 447 448 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p); 449 VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, p); 450 VOP_UNLOCK(devvp, 0, p); 451 452 if (isomp) { 453 free((caddr_t)isomp, M_ISOFSMNT); 454 mp->mnt_data = (qaddr_t)0; 455 } 456 return (error); 457 } 458 459 /* 460 * Test to see if the device is an ISOFS filesystem. 461 */ 462 int 463 iso_disklabelspoof(dev, strat, lp) 464 dev_t dev; 465 void (*strat)(struct buf *); 466 register struct disklabel *lp; 467 { 468 struct buf *bp = NULL; 469 struct iso_volume_descriptor *vdp; 470 struct iso_primary_descriptor *pri; 471 int logical_block_size; 472 int error = EINVAL; 473 int iso_blknum; 474 int i; 475 476 bp = geteblk(ISO_DEFAULT_BLOCK_SIZE); 477 bp->b_dev = dev; 478 479 for (iso_blknum = 16; iso_blknum < 100; iso_blknum++) { 480 bp->b_blkno = iso_blknum * btodb(ISO_DEFAULT_BLOCK_SIZE); 481 bp->b_bcount = ISO_DEFAULT_BLOCK_SIZE; 482 bp->b_flags = B_BUSY | B_READ | B_RAW; 483 bp->b_cylinder = bp->b_blkno / lp->d_secpercyl; 484 485 /*printf("d_secsize %d iso_blknum %d b_blkno %d bcount %d\n", 486 lp->d_secsize, iso_blknum, bp->b_blkno, bp->b_bcount);*/ 487 488 (*strat)(bp); 489 490 if (biowait(bp)) 491 goto out; 492 493 vdp = (struct iso_volume_descriptor *)bp->b_data; 494 /*printf("%2x%2x%2x type %2x\n", vdp->id[0], vdp->id[1], 495 vdp->id[2], isonum_711(vdp->type));*/ 496 if (bcmp (vdp->id, ISO_STANDARD_ID, sizeof vdp->id) != 0 || 497 isonum_711 (vdp->type) == ISO_VD_END) 498 goto out; 499 500 if (isonum_711 (vdp->type) == ISO_VD_PRIMARY) 501 break; 502 } 503 504 if (isonum_711 (vdp->type) != ISO_VD_PRIMARY) 505 goto out; 506 507 pri = (struct iso_primary_descriptor *)vdp; 508 logical_block_size = isonum_723 (pri->logical_block_size); 509 if (logical_block_size < DEV_BSIZE || logical_block_size > MAXBSIZE || 510 (logical_block_size & (logical_block_size - 1)) != 0) 511 goto out; 512 513 /* 514 * build a disklabel for the CD 515 */ 516 strncpy(lp->d_typename, pri->volume_id, sizeof lp->d_typename); 517 strncpy(lp->d_packname, pri->volume_id+16, sizeof lp->d_packname); 518 for (i = 0; i < MAXPARTITIONS; i++) { 519 DL_SETPSIZE(&lp->d_partitions[i], 0); 520 DL_SETPOFFSET(&lp->d_partitions[i], 0); 521 } 522 DL_SETPOFFSET(&lp->d_partitions[0], 0); 523 DL_SETPSIZE(&lp->d_partitions[0], DL_GETDSIZE(lp)); 524 lp->d_partitions[0].p_fstype = FS_ISO9660; 525 DL_SETPOFFSET(&lp->d_partitions[RAW_PART], 0); 526 DL_SETPSIZE(&lp->d_partitions[RAW_PART], DL_GETDSIZE(lp)); 527 lp->d_partitions[RAW_PART].p_fstype = FS_ISO9660; 528 lp->d_npartitions = MAXPARTITIONS; 529 lp->d_bbsize = 8192; /* fake */ 530 lp->d_sbsize = 64*1024; /* fake */ 531 lp->d_version = 1; 532 533 lp->d_magic = DISKMAGIC; 534 lp->d_magic2 = DISKMAGIC; 535 lp->d_checksum = dkcksum(lp); 536 error = 0; 537 out: 538 bp->b_flags |= B_INVAL; 539 brelse(bp); 540 return (error); 541 } 542 543 /* 544 * Make a filesystem operational. 545 * Nothing to do at the moment. 546 */ 547 /* ARGSUSED */ 548 int 549 cd9660_start(mp, flags, p) 550 struct mount *mp; 551 int flags; 552 struct proc *p; 553 { 554 return (0); 555 } 556 557 /* 558 * unmount system call 559 */ 560 int 561 cd9660_unmount(mp, mntflags, p) 562 struct mount *mp; 563 int mntflags; 564 struct proc *p; 565 { 566 register struct iso_mnt *isomp; 567 int error, flags = 0; 568 569 if (mntflags & MNT_FORCE) 570 flags |= FORCECLOSE; 571 #if 0 572 mntflushbuf(mp, 0); 573 if (mntinvalbuf(mp)) 574 return (EBUSY); 575 #endif 576 if ((error = vflush(mp, NULLVP, flags)) != 0) 577 return (error); 578 579 isomp = VFSTOISOFS(mp); 580 581 #ifdef ISODEVMAP 582 if (isomp->iso_ftype == ISO_FTYPE_RRIP) 583 iso_dunmap(isomp->im_dev); 584 #endif 585 586 isomp->im_devvp->v_specmountpoint = NULL; 587 vn_lock(isomp->im_devvp, LK_EXCLUSIVE | LK_RETRY, p); 588 error = VOP_CLOSE(isomp->im_devvp, FREAD, NOCRED, p); 589 vput(isomp->im_devvp); 590 free((caddr_t)isomp, M_ISOFSMNT); 591 mp->mnt_data = (qaddr_t)0; 592 mp->mnt_flag &= ~MNT_LOCAL; 593 return (error); 594 } 595 596 /* 597 * Return root of a filesystem 598 */ 599 int 600 cd9660_root(mp, vpp) 601 struct mount *mp; 602 struct vnode **vpp; 603 { 604 struct iso_mnt *imp = VFSTOISOFS(mp); 605 struct iso_directory_record *dp = 606 (struct iso_directory_record *)imp->root; 607 ino_t ino = isodirino(dp, imp); 608 609 /* 610 * With RRIP we must use the `.' entry of the root directory. 611 * Simply tell vget, that it's a relocated directory. 612 */ 613 return (cd9660_vget_internal(mp, ino, vpp, 614 imp->iso_ftype == ISO_FTYPE_RRIP, dp)); 615 } 616 617 /* 618 * Do operations associated with quotas, not supported 619 */ 620 /* ARGSUSED */ 621 int 622 cd9660_quotactl(mp, cmd, uid, arg, p) 623 struct mount *mp; 624 int cmd; 625 uid_t uid; 626 caddr_t arg; 627 struct proc *p; 628 { 629 630 return (EOPNOTSUPP); 631 } 632 633 /* 634 * Get file system statistics. 635 */ 636 int 637 cd9660_statfs(mp, sbp, p) 638 struct mount *mp; 639 register struct statfs *sbp; 640 struct proc *p; 641 { 642 register struct iso_mnt *isomp; 643 644 isomp = VFSTOISOFS(mp); 645 646 sbp->f_bsize = isomp->logical_block_size; 647 sbp->f_iosize = sbp->f_bsize; /* XXX */ 648 sbp->f_blocks = isomp->volume_space_size; 649 sbp->f_bfree = 0; /* total free blocks */ 650 sbp->f_bavail = 0; /* blocks free for non superuser */ 651 sbp->f_files = 0; /* total files */ 652 sbp->f_ffree = 0; /* free file nodes */ 653 if (sbp != &mp->mnt_stat) { 654 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN); 655 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, 656 MNAMELEN); 657 bcopy(&mp->mnt_stat.mount_info.iso_args, 658 &sbp->mount_info.iso_args, sizeof(struct iso_args)); 659 } 660 /* Use the first spare for flags: */ 661 sbp->f_spare[0] = isomp->im_flags; 662 return (0); 663 } 664 665 /* ARGSUSED */ 666 int 667 cd9660_sync(mp, waitfor, cred, p) 668 struct mount *mp; 669 int waitfor; 670 struct ucred *cred; 671 struct proc *p; 672 { 673 return (0); 674 } 675 676 /* 677 * File handle to vnode 678 * 679 * Have to be really careful about stale file handles: 680 * - check that the inode number is in range 681 * - call iget() to get the locked inode 682 * - check for an unallocated inode (i_mode == 0) 683 * - check that the generation number matches 684 */ 685 686 struct ifid { 687 ushort ifid_len; 688 ushort ifid_pad; 689 int ifid_ino; 690 long ifid_start; 691 }; 692 693 /* ARGSUSED */ 694 int 695 cd9660_fhtovp(mp, fhp, vpp) 696 register struct mount *mp; 697 struct fid *fhp; 698 struct vnode **vpp; 699 { 700 struct ifid *ifhp = (struct ifid *)fhp; 701 register struct iso_node *ip; 702 struct vnode *nvp; 703 int error; 704 705 #ifdef ISOFS_DBG 706 printf("fhtovp: ino %d, start %ld\n", ifhp->ifid_ino, 707 ifhp->ifid_start); 708 #endif 709 710 if ((error = VFS_VGET(mp, ifhp->ifid_ino, &nvp)) != 0) { 711 *vpp = NULLVP; 712 return (error); 713 } 714 ip = VTOI(nvp); 715 if (ip->inode.iso_mode == 0) { 716 vput(nvp); 717 *vpp = NULLVP; 718 return (ESTALE); 719 } 720 *vpp = nvp; 721 return (0); 722 } 723 724 int 725 cd9660_vget(mp, ino, vpp) 726 struct mount *mp; 727 ino_t ino; 728 struct vnode **vpp; 729 { 730 731 /* 732 * XXXX 733 * It would be nice if we didn't always set the `relocated' flag 734 * and force the extra read, but I don't want to think about fixing 735 * that right now. 736 */ 737 return (cd9660_vget_internal(mp, ino, vpp, 738 #if 0 739 VFSTOISOFS(mp)->iso_ftype == ISO_FTYPE_RRIP, 740 #else 741 0, 742 #endif 743 NULL)); 744 } 745 746 int 747 cd9660_vget_internal(mp, ino, vpp, relocated, isodir) 748 struct mount *mp; 749 ino_t ino; 750 struct vnode **vpp; 751 int relocated; 752 struct iso_directory_record *isodir; 753 { 754 register struct iso_mnt *imp; 755 struct iso_node *ip; 756 struct buf *bp; 757 struct vnode *vp, *nvp; 758 dev_t dev; 759 int error; 760 761 retry: 762 imp = VFSTOISOFS(mp); 763 dev = imp->im_dev; 764 if ((*vpp = cd9660_ihashget(dev, ino)) != NULLVP) 765 return (0); 766 767 /* Allocate a new vnode/iso_node. */ 768 if ((error = getnewvnode(VT_ISOFS, mp, cd9660_vnodeop_p, &vp)) != 0) { 769 *vpp = NULLVP; 770 return (error); 771 } 772 ip = malloc(sizeof(*ip), M_ISOFSNODE, M_WAITOK | M_ZERO); 773 lockinit(&ip->i_lock, PINOD, "isoinode", 0, 0); 774 vp->v_data = ip; 775 ip->i_vnode = vp; 776 ip->i_dev = dev; 777 ip->i_number = ino; 778 779 /* 780 * Put it onto its hash chain and lock it so that other requests for 781 * this inode will block if they arrive while we are sleeping waiting 782 * for old data structures to be purged or for the contents of the 783 * disk portion of this inode to be read. 784 */ 785 error = cd9660_ihashins(ip); 786 787 if (error) { 788 vrele(vp); 789 790 if (error == EEXIST) 791 goto retry; 792 793 return (error); 794 } 795 796 if (isodir == 0) { 797 int lbn, off; 798 799 lbn = lblkno(imp, ino); 800 if (lbn >= imp->volume_space_size) { 801 vput(vp); 802 printf("fhtovp: lbn exceed volume space %d\n", lbn); 803 return (ESTALE); 804 } 805 806 off = blkoff(imp, ino); 807 if (off + ISO_DIRECTORY_RECORD_SIZE > imp->logical_block_size) 808 { 809 vput(vp); 810 printf("fhtovp: crosses block boundary %d\n", 811 off + ISO_DIRECTORY_RECORD_SIZE); 812 return (ESTALE); 813 } 814 815 error = bread(imp->im_devvp, 816 lbn << (imp->im_bshift - DEV_BSHIFT), 817 imp->logical_block_size, NOCRED, &bp); 818 if (error) { 819 vput(vp); 820 brelse(bp); 821 printf("fhtovp: bread error %d\n",error); 822 return (error); 823 } 824 isodir = (struct iso_directory_record *)(bp->b_data + off); 825 826 if (off + isonum_711(isodir->length) > 827 imp->logical_block_size) { 828 vput(vp); 829 if (bp != 0) 830 brelse(bp); 831 printf("fhtovp: directory crosses block boundary %d[off=%d/len=%d]\n", 832 off +isonum_711(isodir->length), off, 833 isonum_711(isodir->length)); 834 return (ESTALE); 835 } 836 837 #if 0 838 if (isonum_733(isodir->extent) + 839 isonum_711(isodir->ext_attr_length) != ifhp->ifid_start) { 840 if (bp != 0) 841 brelse(bp); 842 printf("fhtovp: file start miss %d vs %d\n", 843 isonum_733(isodir->extent) + 844 isonum_711(isodir->ext_attr_length), 845 ifhp->ifid_start); 846 return (ESTALE); 847 } 848 #endif 849 } else 850 bp = 0; 851 852 ip->i_mnt = imp; 853 ip->i_devvp = imp->im_devvp; 854 vref(ip->i_devvp); 855 856 if (relocated) { 857 /* 858 * On relocated directories we must 859 * read the `.' entry out of a dir. 860 */ 861 ip->iso_start = ino >> imp->im_bshift; 862 if (bp != 0) 863 brelse(bp); 864 if ((error = cd9660_bufatoff(ip, (off_t)0, NULL, &bp)) != 0) { 865 vput(vp); 866 return (error); 867 } 868 isodir = (struct iso_directory_record *)bp->b_data; 869 } 870 871 ip->iso_extent = isonum_733(isodir->extent); 872 ip->i_size = (u_int32_t) isonum_733(isodir->size); 873 ip->iso_start = isonum_711(isodir->ext_attr_length) + ip->iso_extent; 874 875 /* 876 * Setup time stamp, attribute 877 */ 878 vp->v_type = VNON; 879 switch (imp->iso_ftype) { 880 default: /* ISO_FTYPE_9660 */ 881 { 882 struct buf *bp2; 883 int off; 884 if ((imp->im_flags & ISOFSMNT_EXTATT) && 885 (off = isonum_711(isodir->ext_attr_length))) 886 cd9660_bufatoff(ip, (off_t)-(off << imp->im_bshift), 887 NULL, &bp2); 888 else 889 bp2 = NULL; 890 cd9660_defattr(isodir, ip, bp2); 891 cd9660_deftstamp(isodir, ip, bp2); 892 if (bp2) 893 brelse(bp2); 894 break; 895 } 896 case ISO_FTYPE_RRIP: 897 cd9660_rrip_analyze(isodir, ip, imp); 898 break; 899 } 900 901 if (bp != 0) 902 brelse(bp); 903 904 /* 905 * Initialize the associated vnode 906 */ 907 switch (vp->v_type = IFTOVT(ip->inode.iso_mode)) { 908 case VFIFO: 909 #ifdef FIFO 910 vp->v_op = cd9660_fifoop_p; 911 break; 912 #else 913 vput(vp); 914 return (EOPNOTSUPP); 915 #endif /* FIFO */ 916 case VCHR: 917 case VBLK: 918 /* 919 * if device, look at device number table for translation 920 */ 921 #ifdef ISODEVMAP 922 if (dp = iso_dmap(dev, ino, 0)) 923 ip->inode.iso_rdev = dp->d_dev; 924 #endif 925 vp->v_op = cd9660_specop_p; 926 if ((nvp = checkalias(vp, ip->inode.iso_rdev, mp)) != NULL) { 927 /* 928 * Discard unneeded vnode, but save its iso_node. 929 * Note that the lock is carried over in the iso_node 930 */ 931 nvp->v_data = vp->v_data; 932 vp->v_data = NULL; 933 vp->v_op = spec_vnodeop_p; 934 vrele(vp); 935 vgone(vp); 936 /* 937 * Reinitialize aliased inode. 938 */ 939 vp = nvp; 940 ip->i_vnode = vp; 941 } 942 break; 943 case VLNK: 944 case VNON: 945 case VSOCK: 946 case VDIR: 947 case VBAD: 948 break; 949 case VREG: 950 uvm_vnp_setsize(vp, ip->i_size); 951 break; 952 } 953 954 if (ip->iso_extent == imp->root_extent) 955 vp->v_flag |= VROOT; 956 957 /* 958 * XXX need generation number? 959 */ 960 961 *vpp = vp; 962 return (0); 963 } 964 965 /* 966 * Vnode pointer to File handle 967 */ 968 /* ARGSUSED */ 969 int 970 cd9660_vptofh(vp, fhp) 971 struct vnode *vp; 972 struct fid *fhp; 973 { 974 register struct iso_node *ip = VTOI(vp); 975 register struct ifid *ifhp; 976 977 ifhp = (struct ifid *)fhp; 978 ifhp->ifid_len = sizeof(struct ifid); 979 980 ifhp->ifid_ino = ip->i_number; 981 ifhp->ifid_start = ip->iso_start; 982 983 #ifdef ISOFS_DBG 984 printf("vptofh: ino %d, start %ld\n", 985 ifhp->ifid_ino,ifhp->ifid_start); 986 #endif 987 return (0); 988 } 989 990 /* 991 * Verify a remote client has export rights and return these rights via 992 * exflagsp and credanonp. 993 */ 994 int 995 cd9660_check_export(mp, nam, exflagsp, credanonp) 996 register struct mount *mp; 997 struct mbuf *nam; 998 int *exflagsp; 999 struct ucred **credanonp; 1000 { 1001 register struct netcred *np; 1002 register struct iso_mnt *imp = VFSTOISOFS(mp); 1003 1004 /* 1005 * Get the export permission structure for this <mp, client> tuple. 1006 */ 1007 np = vfs_export_lookup(mp, &imp->im_export, nam); 1008 if (np == NULL) 1009 return (EACCES); 1010 1011 *exflagsp = np->netc_exflags; 1012 *credanonp = &np->netc_anon; 1013 return (0); 1014 } 1015