1 /*- 2 * Copyright (c) 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley 6 * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension 7 * Support code is derived from software contributed to Berkeley 8 * by Atsushi Murai (amurai@spec.co.jp). 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)cd9660_vfsops.c 8.18 (Berkeley) 5/22/95 39 * $FreeBSD$ 40 */ 41 42 #include <sys/param.h> 43 #include <sys/systm.h> 44 #include <sys/namei.h> 45 #include <sys/proc.h> 46 #include <sys/kernel.h> 47 #include <sys/vnode.h> 48 #include <sys/mount.h> 49 #include <sys/bio.h> 50 #include <sys/buf.h> 51 #include <sys/cdio.h> 52 #include <sys/conf.h> 53 #include <sys/fcntl.h> 54 #include <sys/malloc.h> 55 #include <sys/stat.h> 56 #include <sys/syslog.h> 57 58 59 #include <isofs/cd9660/iso.h> 60 #include <isofs/cd9660/iso_rrip.h> 61 #include <isofs/cd9660/cd9660_node.h> 62 #include <isofs/cd9660/cd9660_mount.h> 63 64 MALLOC_DEFINE(M_ISOFSMNT, "ISOFS mount", "ISOFS mount structure"); 65 MALLOC_DEFINE(M_ISOFSNODE, "ISOFS node", "ISOFS vnode private part"); 66 67 static int cd9660_mount __P((struct mount *, 68 char *, caddr_t, struct nameidata *, struct proc *)); 69 static int cd9660_unmount __P((struct mount *, int, struct proc *)); 70 static int cd9660_root __P((struct mount *, struct vnode **)); 71 static int cd9660_statfs __P((struct mount *, struct statfs *, struct proc *)); 72 static int cd9660_vget __P((struct mount *, ino_t, struct vnode **)); 73 static int cd9660_fhtovp __P((struct mount *, struct fid *, struct vnode **)); 74 static int cd9660_checkexp __P((struct mount *, struct sockaddr *, 75 int *, struct ucred **)); 76 static int cd9660_vptofh __P((struct vnode *, struct fid *)); 77 78 static struct vfsops cd9660_vfsops = { 79 cd9660_mount, 80 vfs_stdstart, 81 cd9660_unmount, 82 cd9660_root, 83 vfs_stdquotactl, 84 cd9660_statfs, 85 vfs_stdsync, 86 cd9660_vget, 87 cd9660_fhtovp, 88 cd9660_checkexp, 89 cd9660_vptofh, 90 cd9660_init, 91 cd9660_uninit, 92 vfs_stdextattrctl, 93 }; 94 VFS_SET(cd9660_vfsops, cd9660, VFCF_READONLY); 95 96 97 /* 98 * Called by vfs_mountroot when iso is going to be mounted as root. 99 */ 100 101 static int iso_get_ssector __P((dev_t dev, struct proc *p)); 102 static int iso_mountfs __P((struct vnode *devvp, struct mount *mp, 103 struct proc *p, struct iso_args *argp)); 104 105 /* 106 * Try to find the start of the last data track on this CD-ROM. This 107 * is used to mount the last session of a multi-session CD. Bail out 108 * and return 0 if we fail, this is always a safe bet. 109 */ 110 static int 111 iso_get_ssector(dev, p) 112 dev_t dev; 113 struct proc *p; 114 { 115 struct ioc_toc_header h; 116 struct ioc_read_toc_single_entry t; 117 int i; 118 struct cdevsw *bd; 119 d_ioctl_t *ioctlp; 120 121 bd = devsw(dev); 122 ioctlp = bd->d_ioctl; 123 if (ioctlp == NULL) 124 return 0; 125 126 if (ioctlp(dev, CDIOREADTOCHEADER, (caddr_t)&h, FREAD, p) != 0) 127 return 0; 128 129 for (i = h.ending_track; i >= 0; i--) { 130 t.address_format = CD_LBA_FORMAT; 131 t.track = i; 132 if (ioctlp(dev, CDIOREADTOCENTRY, (caddr_t)&t, FREAD, p) != 0) 133 return 0; 134 if ((t.entry.control & 4) != 0) 135 /* found a data track */ 136 break; 137 } 138 139 if (i < 0) 140 return 0; 141 142 return ntohl(t.entry.addr.lba); 143 } 144 145 static int iso_mountroot __P((struct mount *mp, struct proc *p)); 146 147 static int 148 iso_mountroot(mp, p) 149 struct mount *mp; 150 struct proc *p; 151 { 152 struct iso_args args; 153 int error; 154 155 if ((error = bdevvp(rootdev, &rootvp))) { 156 printf("iso_mountroot: can't find rootvp\n"); 157 return (error); 158 } 159 args.flags = ISOFSMNT_ROOT; 160 args.ssector = iso_get_ssector(rootdev, p); 161 if (bootverbose) 162 printf("iso_mountroot(): using session at block %d\n", 163 args.ssector); 164 if ((error = iso_mountfs(rootvp, mp, p, &args)) != 0) 165 return (error); 166 167 (void)cd9660_statfs(mp, &mp->mnt_stat, p); 168 return (0); 169 } 170 171 /* 172 * VFS Operations. 173 * 174 * mount system call 175 */ 176 static int 177 cd9660_mount(mp, path, data, ndp, p) 178 register struct mount *mp; 179 char *path; 180 caddr_t data; 181 struct nameidata *ndp; 182 struct proc *p; 183 { 184 struct vnode *devvp; 185 struct iso_args args; 186 size_t size; 187 int error; 188 mode_t accessmode; 189 struct iso_mnt *imp = 0; 190 191 if ((mp->mnt_flag & MNT_ROOTFS) != 0) { 192 return (iso_mountroot(mp, p)); 193 } 194 if ((error = copyin(data, (caddr_t)&args, sizeof (struct iso_args)))) 195 return (error); 196 197 if ((mp->mnt_flag & MNT_RDONLY) == 0) 198 return (EROFS); 199 200 /* 201 * If updating, check whether changing from read-only to 202 * read/write; if there is no device name, that's all we do. 203 */ 204 if (mp->mnt_flag & MNT_UPDATE) { 205 imp = VFSTOISOFS(mp); 206 if (args.fspec == 0) 207 return (vfs_export(mp, &imp->im_export, &args.export)); 208 } 209 /* 210 * Not an update, or updating the name: look up the name 211 * and verify that it refers to a sensible block device. 212 */ 213 NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, p); 214 if ((error = namei(ndp))) 215 return (error); 216 NDFREE(ndp, NDF_ONLY_PNBUF); 217 devvp = ndp->ni_vp; 218 219 if (!vn_isdisk(devvp, &error)) { 220 vrele(devvp); 221 return (error); 222 } 223 224 /* 225 * Verify that user has necessary permissions on the device, 226 * or has superuser abilities 227 */ 228 accessmode = VREAD; 229 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p); 230 error = VOP_ACCESS(devvp, accessmode, p->p_ucred, p); 231 if (error) 232 error = suser(p); 233 if (error) { 234 vput(devvp); 235 return (error); 236 } 237 VOP_UNLOCK(devvp, 0, p); 238 239 if ((mp->mnt_flag & MNT_UPDATE) == 0) { 240 error = iso_mountfs(devvp, mp, p, &args); 241 } else { 242 if (devvp != imp->im_devvp) 243 error = EINVAL; /* needs translation */ 244 else 245 vrele(devvp); 246 } 247 if (error) { 248 vrele(devvp); 249 return error; 250 } 251 imp = VFSTOISOFS(mp); 252 (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size); 253 bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size); 254 (void) copyinstr(args.fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1, 255 &size); 256 bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size); 257 (void) cd9660_statfs(mp, &mp->mnt_stat, p); 258 return 0; 259 } 260 261 /* 262 * Common code for mount and mountroot 263 */ 264 static int 265 iso_mountfs(devvp, mp, p, argp) 266 register struct vnode *devvp; 267 struct mount *mp; 268 struct proc *p; 269 struct iso_args *argp; 270 { 271 register struct iso_mnt *isomp = (struct iso_mnt *)0; 272 struct buf *bp = NULL; 273 struct buf *pribp = NULL, *supbp = NULL; 274 dev_t dev = devvp->v_rdev; 275 int error = EINVAL; 276 int needclose = 0; 277 int high_sierra = 0; 278 int iso_bsize; 279 int iso_blknum; 280 int joliet_level; 281 struct iso_volume_descriptor *vdp = 0; 282 struct iso_primary_descriptor *pri = NULL; 283 struct iso_sierra_primary_descriptor *pri_sierra = NULL; 284 struct iso_supplementary_descriptor *sup = NULL; 285 struct iso_directory_record *rootp; 286 int logical_block_size; 287 288 if (!(mp->mnt_flag & MNT_RDONLY)) 289 return EROFS; 290 291 /* 292 * Disallow multiple mounts of the same device. 293 * Disallow mounting of a device that is currently in use 294 * (except for root, which might share swap device for miniroot). 295 * Flush out any old buffers remaining from a previous use. 296 */ 297 if ((error = vfs_mountedon(devvp))) 298 return error; 299 if (vcount(devvp) > 1 && devvp != rootvp) 300 return EBUSY; 301 if ((error = vinvalbuf(devvp, V_SAVE, p->p_ucred, p, 0, 0))) 302 return (error); 303 304 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p); 305 error = VOP_OPEN(devvp, FREAD, FSCRED, p); 306 VOP_UNLOCK(devvp, 0, p); 307 if (error) 308 return error; 309 310 needclose = 1; 311 312 /* This is the "logical sector size". The standard says this 313 * should be 2048 or the physical sector size on the device, 314 * whichever is greater. For now, we'll just use a constant. 315 */ 316 iso_bsize = ISO_DEFAULT_BLOCK_SIZE; 317 318 joliet_level = 0; 319 for (iso_blknum = 16 + argp->ssector; 320 iso_blknum < 100 + argp->ssector; 321 iso_blknum++) { 322 if ((error = bread(devvp, iso_blknum * btodb(iso_bsize), 323 iso_bsize, NOCRED, &bp)) != 0) 324 goto out; 325 326 vdp = (struct iso_volume_descriptor *)bp->b_data; 327 if (bcmp (vdp->id, ISO_STANDARD_ID, sizeof vdp->id) != 0) { 328 if (bcmp (vdp->id_sierra, ISO_SIERRA_ID, 329 sizeof vdp->id) != 0) { 330 error = EINVAL; 331 goto out; 332 } else 333 high_sierra = 1; 334 } 335 switch (isonum_711 (high_sierra? vdp->type_sierra: vdp->type)){ 336 case ISO_VD_PRIMARY: 337 if (pribp == NULL) { 338 pribp = bp; 339 bp = NULL; 340 pri = (struct iso_primary_descriptor *)vdp; 341 pri_sierra = 342 (struct iso_sierra_primary_descriptor *)vdp; 343 } 344 break; 345 346 case ISO_VD_SUPPLEMENTARY: 347 if (supbp == NULL) { 348 supbp = bp; 349 bp = NULL; 350 sup = (struct iso_supplementary_descriptor *)vdp; 351 352 if (!(argp->flags & ISOFSMNT_NOJOLIET)) { 353 if (bcmp(sup->escape, "%/@", 3) == 0) 354 joliet_level = 1; 355 if (bcmp(sup->escape, "%/C", 3) == 0) 356 joliet_level = 2; 357 if (bcmp(sup->escape, "%/E", 3) == 0) 358 joliet_level = 3; 359 360 if (isonum_711 (sup->flags) & 1) 361 joliet_level = 0; 362 } 363 } 364 break; 365 366 case ISO_VD_END: 367 goto vd_end; 368 369 default: 370 break; 371 } 372 if (bp) { 373 brelse(bp); 374 bp = NULL; 375 } 376 } 377 vd_end: 378 if (bp) { 379 brelse(bp); 380 bp = NULL; 381 } 382 383 if (pri == NULL) { 384 error = EINVAL; 385 goto out; 386 } 387 388 logical_block_size = 389 isonum_723 (high_sierra? 390 pri_sierra->logical_block_size: 391 pri->logical_block_size); 392 393 if (logical_block_size < DEV_BSIZE || logical_block_size > MAXBSIZE 394 || (logical_block_size & (logical_block_size - 1)) != 0) { 395 error = EINVAL; 396 goto out; 397 } 398 399 rootp = (struct iso_directory_record *) 400 (high_sierra? 401 pri_sierra->root_directory_record: 402 pri->root_directory_record); 403 404 isomp = malloc(sizeof *isomp, M_ISOFSMNT, M_WAITOK); 405 bzero((caddr_t)isomp, sizeof *isomp); 406 isomp->logical_block_size = logical_block_size; 407 isomp->volume_space_size = 408 isonum_733 (high_sierra? 409 pri_sierra->volume_space_size: 410 pri->volume_space_size); 411 isomp->joliet_level = 0; 412 /* 413 * Since an ISO9660 multi-session CD can also access previous 414 * sessions, we have to include them into the space consider- 415 * ations. This doesn't yield a very accurate number since 416 * parts of the old sessions might be inaccessible now, but we 417 * can't do much better. This is also important for the NFS 418 * filehandle validation. 419 */ 420 isomp->volume_space_size += argp->ssector; 421 bcopy (rootp, isomp->root, sizeof isomp->root); 422 isomp->root_extent = isonum_733 (rootp->extent); 423 isomp->root_size = isonum_733 (rootp->size); 424 425 isomp->im_bmask = logical_block_size - 1; 426 isomp->im_bshift = ffs(logical_block_size) - 1; 427 428 pribp->b_flags |= B_AGE; 429 brelse(pribp); 430 pribp = NULL; 431 432 mp->mnt_data = (qaddr_t)isomp; 433 mp->mnt_stat.f_fsid.val[0] = dev2udev(dev); 434 mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum; 435 mp->mnt_maxsymlinklen = 0; 436 mp->mnt_flag |= MNT_LOCAL; 437 isomp->im_mountp = mp; 438 isomp->im_dev = dev; 439 isomp->im_devvp = devvp; 440 441 devvp->v_specmountpoint = mp; 442 443 /* Check the Rock Ridge Extention support */ 444 if (!(argp->flags & ISOFSMNT_NORRIP)) { 445 if ((error = bread(isomp->im_devvp, 446 (isomp->root_extent + isonum_711(rootp->ext_attr_length)) << 447 (isomp->im_bshift - DEV_BSHIFT), 448 isomp->logical_block_size, NOCRED, &bp)) != 0) 449 goto out; 450 451 rootp = (struct iso_directory_record *)bp->b_data; 452 453 if ((isomp->rr_skip = cd9660_rrip_offset(rootp,isomp)) < 0) { 454 argp->flags |= ISOFSMNT_NORRIP; 455 } else { 456 argp->flags &= ~ISOFSMNT_GENS; 457 } 458 459 /* 460 * The contents are valid, 461 * but they will get reread as part of another vnode, so... 462 */ 463 bp->b_flags |= B_AGE; 464 brelse(bp); 465 bp = NULL; 466 } 467 isomp->im_flags = argp->flags & (ISOFSMNT_NORRIP | ISOFSMNT_GENS | 468 ISOFSMNT_EXTATT | ISOFSMNT_NOJOLIET); 469 470 if (high_sierra) { 471 /* this effectively ignores all the mount flags */ 472 log(LOG_INFO, "cd9660: High Sierra Format\n"); 473 isomp->iso_ftype = ISO_FTYPE_HIGH_SIERRA; 474 } else 475 switch (isomp->im_flags&(ISOFSMNT_NORRIP|ISOFSMNT_GENS)) { 476 default: 477 isomp->iso_ftype = ISO_FTYPE_DEFAULT; 478 break; 479 case ISOFSMNT_GENS|ISOFSMNT_NORRIP: 480 isomp->iso_ftype = ISO_FTYPE_9660; 481 break; 482 case 0: 483 log(LOG_INFO, "cd9660: RockRidge Extension\n"); 484 isomp->iso_ftype = ISO_FTYPE_RRIP; 485 break; 486 } 487 488 /* Decide whether to use the Joliet descriptor */ 489 490 if (isomp->iso_ftype != ISO_FTYPE_RRIP && joliet_level) { 491 log(LOG_INFO, "cd9660: Joliet Extension\n"); 492 rootp = (struct iso_directory_record *) 493 sup->root_directory_record; 494 bcopy (rootp, isomp->root, sizeof isomp->root); 495 isomp->root_extent = isonum_733 (rootp->extent); 496 isomp->root_size = isonum_733 (rootp->size); 497 isomp->joliet_level = joliet_level; 498 supbp->b_flags |= B_AGE; 499 } 500 501 if (supbp) { 502 brelse(supbp); 503 supbp = NULL; 504 } 505 506 return 0; 507 out: 508 devvp->v_specmountpoint = NULL; 509 if (bp) 510 brelse(bp); 511 if (pribp) 512 brelse(pribp); 513 if (supbp) 514 brelse(supbp); 515 if (needclose) 516 (void)VOP_CLOSE(devvp, FREAD, NOCRED, p); 517 if (isomp) { 518 free((caddr_t)isomp, M_ISOFSMNT); 519 mp->mnt_data = (qaddr_t)0; 520 } 521 return error; 522 } 523 524 /* 525 * unmount system call 526 */ 527 static int 528 cd9660_unmount(mp, mntflags, p) 529 struct mount *mp; 530 int mntflags; 531 struct proc *p; 532 { 533 register struct iso_mnt *isomp; 534 int error, flags = 0; 535 536 if (mntflags & MNT_FORCE) 537 flags |= FORCECLOSE; 538 #if 0 539 mntflushbuf(mp, 0); 540 if (mntinvalbuf(mp)) 541 return EBUSY; 542 #endif 543 if ((error = vflush(mp, NULLVP, flags))) 544 return (error); 545 546 isomp = VFSTOISOFS(mp); 547 548 isomp->im_devvp->v_specmountpoint = NULL; 549 error = VOP_CLOSE(isomp->im_devvp, FREAD, NOCRED, p); 550 vrele(isomp->im_devvp); 551 free((caddr_t)isomp, M_ISOFSMNT); 552 mp->mnt_data = (qaddr_t)0; 553 mp->mnt_flag &= ~MNT_LOCAL; 554 return (error); 555 } 556 557 /* 558 * Return root of a filesystem 559 */ 560 static int 561 cd9660_root(mp, vpp) 562 struct mount *mp; 563 struct vnode **vpp; 564 { 565 struct iso_mnt *imp = VFSTOISOFS(mp); 566 struct iso_directory_record *dp = 567 (struct iso_directory_record *)imp->root; 568 ino_t ino = isodirino(dp, imp); 569 570 /* 571 * With RRIP we must use the `.' entry of the root directory. 572 * Simply tell vget, that it's a relocated directory. 573 */ 574 return (cd9660_vget_internal(mp, ino, vpp, 575 imp->iso_ftype == ISO_FTYPE_RRIP, dp)); 576 } 577 578 /* 579 * Get file system statistics. 580 */ 581 int 582 cd9660_statfs(mp, sbp, p) 583 struct mount *mp; 584 register struct statfs *sbp; 585 struct proc *p; 586 { 587 register struct iso_mnt *isomp; 588 589 isomp = VFSTOISOFS(mp); 590 591 sbp->f_bsize = isomp->logical_block_size; 592 sbp->f_iosize = sbp->f_bsize; /* XXX */ 593 sbp->f_blocks = isomp->volume_space_size; 594 sbp->f_bfree = 0; /* total free blocks */ 595 sbp->f_bavail = 0; /* blocks free for non superuser */ 596 sbp->f_files = 0; /* total files */ 597 sbp->f_ffree = 0; /* free file nodes */ 598 if (sbp != &mp->mnt_stat) { 599 sbp->f_type = mp->mnt_vfc->vfc_typenum; 600 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN); 601 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN); 602 } 603 return 0; 604 } 605 606 /* 607 * File handle to vnode 608 * 609 * Have to be really careful about stale file handles: 610 * - check that the inode number is in range 611 * - call iget() to get the locked inode 612 * - check for an unallocated inode (i_mode == 0) 613 * - check that the generation number matches 614 */ 615 616 struct ifid { 617 ushort ifid_len; 618 ushort ifid_pad; 619 int ifid_ino; 620 long ifid_start; 621 }; 622 623 /* ARGSUSED */ 624 int 625 cd9660_fhtovp(mp, fhp, vpp) 626 register struct mount *mp; 627 struct fid *fhp; 628 struct vnode **vpp; 629 { 630 struct ifid *ifhp = (struct ifid *)fhp; 631 register struct iso_node *ip; 632 struct vnode *nvp; 633 int error; 634 635 #ifdef ISOFS_DBG 636 printf("fhtovp: ino %d, start %ld\n", 637 ifhp->ifid_ino, ifhp->ifid_start); 638 #endif 639 640 if ((error = VFS_VGET(mp, ifhp->ifid_ino, &nvp)) != 0) { 641 *vpp = NULLVP; 642 return (error); 643 } 644 ip = VTOI(nvp); 645 if (ip->inode.iso_mode == 0) { 646 vput(nvp); 647 *vpp = NULLVP; 648 return (ESTALE); 649 } 650 *vpp = nvp; 651 return (0); 652 } 653 654 int 655 cd9660_checkexp(mp, nam, exflagsp, credanonp) 656 struct mount *mp; 657 struct sockaddr *nam; 658 int *exflagsp; 659 struct ucred **credanonp; 660 { 661 register struct netcred *np; 662 register struct iso_mnt *imp; 663 664 imp = VFSTOISOFS(mp); 665 666 /* 667 * Get the export permission structure for this <mp, client> tuple. 668 */ 669 np = vfs_export_lookup(mp, &imp->im_export, nam); 670 if (np == NULL) 671 return (EACCES); 672 673 *exflagsp = np->netc_exflags; 674 *credanonp = &np->netc_anon; 675 return (0); 676 } 677 678 int 679 cd9660_vget(mp, ino, vpp) 680 struct mount *mp; 681 ino_t ino; 682 struct vnode **vpp; 683 { 684 685 /* 686 * XXXX 687 * It would be nice if we didn't always set the `relocated' flag 688 * and force the extra read, but I don't want to think about fixing 689 * that right now. 690 */ 691 return (cd9660_vget_internal(mp, ino, vpp, 692 #if 0 693 VFSTOISOFS(mp)->iso_ftype == ISO_FTYPE_RRIP, 694 #else 695 0, 696 #endif 697 (struct iso_directory_record *)0)); 698 } 699 700 int 701 cd9660_vget_internal(mp, ino, vpp, relocated, isodir) 702 struct mount *mp; 703 ino_t ino; 704 struct vnode **vpp; 705 int relocated; 706 struct iso_directory_record *isodir; 707 { 708 struct iso_mnt *imp; 709 struct iso_node *ip; 710 struct buf *bp; 711 struct vnode *vp; 712 dev_t dev; 713 int error; 714 715 imp = VFSTOISOFS(mp); 716 dev = imp->im_dev; 717 if ((*vpp = cd9660_ihashget(dev, ino)) != NULLVP) 718 return (0); 719 720 /* Allocate a new vnode/iso_node. */ 721 if ((error = getnewvnode(VT_ISOFS, mp, cd9660_vnodeop_p, &vp)) != 0) { 722 *vpp = NULLVP; 723 return (error); 724 } 725 MALLOC(ip, struct iso_node *, sizeof(struct iso_node), M_ISOFSNODE, 726 M_WAITOK); 727 bzero((caddr_t)ip, sizeof(struct iso_node)); 728 lockinit(&ip->i_lock, PINOD, "isonode", 0, 0); 729 vp->v_data = ip; 730 ip->i_vnode = vp; 731 ip->i_dev = dev; 732 ip->i_number = ino; 733 734 /* 735 * Put it onto its hash chain and lock it so that other requests for 736 * this inode will block if they arrive while we are sleeping waiting 737 * for old data structures to be purged or for the contents of the 738 * disk portion of this inode to be read. 739 */ 740 cd9660_ihashins(ip); 741 742 if (isodir == 0) { 743 int lbn, off; 744 745 lbn = lblkno(imp, ino); 746 if (lbn >= imp->volume_space_size) { 747 vput(vp); 748 printf("fhtovp: lbn exceed volume space %d\n", lbn); 749 return (ESTALE); 750 } 751 752 off = blkoff(imp, ino); 753 if (off + ISO_DIRECTORY_RECORD_SIZE > imp->logical_block_size) { 754 vput(vp); 755 printf("fhtovp: crosses block boundary %d\n", 756 off + ISO_DIRECTORY_RECORD_SIZE); 757 return (ESTALE); 758 } 759 760 error = bread(imp->im_devvp, 761 lbn << (imp->im_bshift - DEV_BSHIFT), 762 imp->logical_block_size, NOCRED, &bp); 763 if (error) { 764 vput(vp); 765 brelse(bp); 766 printf("fhtovp: bread error %d\n",error); 767 return (error); 768 } 769 isodir = (struct iso_directory_record *)(bp->b_data + off); 770 771 if (off + isonum_711(isodir->length) > 772 imp->logical_block_size) { 773 vput(vp); 774 if (bp != 0) 775 brelse(bp); 776 printf("fhtovp: directory crosses block boundary %d[off=%d/len=%d]\n", 777 off +isonum_711(isodir->length), off, 778 isonum_711(isodir->length)); 779 return (ESTALE); 780 } 781 782 #if 0 783 if (isonum_733(isodir->extent) + 784 isonum_711(isodir->ext_attr_length) != ifhp->ifid_start) { 785 if (bp != 0) 786 brelse(bp); 787 printf("fhtovp: file start miss %d vs %d\n", 788 isonum_733(isodir->extent) + isonum_711(isodir->ext_attr_length), 789 ifhp->ifid_start); 790 return (ESTALE); 791 } 792 #endif 793 } else 794 bp = 0; 795 796 ip->i_mnt = imp; 797 ip->i_devvp = imp->im_devvp; 798 VREF(ip->i_devvp); 799 800 if (relocated) { 801 /* 802 * On relocated directories we must 803 * read the `.' entry out of a dir. 804 */ 805 ip->iso_start = ino >> imp->im_bshift; 806 if (bp != 0) 807 brelse(bp); 808 if ((error = cd9660_blkatoff(vp, (off_t)0, NULL, &bp)) != 0) { 809 vput(vp); 810 return (error); 811 } 812 isodir = (struct iso_directory_record *)bp->b_data; 813 } 814 815 ip->iso_extent = isonum_733(isodir->extent); 816 ip->i_size = isonum_733(isodir->size); 817 ip->iso_start = isonum_711(isodir->ext_attr_length) + ip->iso_extent; 818 819 /* 820 * Setup time stamp, attribute 821 */ 822 vp->v_type = VNON; 823 switch (imp->iso_ftype) { 824 default: /* ISO_FTYPE_9660 */ 825 { 826 struct buf *bp2; 827 int off; 828 if ((imp->im_flags & ISOFSMNT_EXTATT) 829 && (off = isonum_711(isodir->ext_attr_length))) 830 cd9660_blkatoff(vp, (off_t)-(off << imp->im_bshift), NULL, 831 &bp2); 832 else 833 bp2 = NULL; 834 cd9660_defattr(isodir, ip, bp2, ISO_FTYPE_9660); 835 cd9660_deftstamp(isodir, ip, bp2, ISO_FTYPE_9660); 836 if (bp2) 837 brelse(bp2); 838 break; 839 } 840 case ISO_FTYPE_RRIP: 841 cd9660_rrip_analyze(isodir, ip, imp); 842 break; 843 } 844 845 if (bp != 0) 846 brelse(bp); 847 848 /* 849 * Initialize the associated vnode 850 */ 851 switch (vp->v_type = IFTOVT(ip->inode.iso_mode)) { 852 case VFIFO: 853 vp->v_op = cd9660_fifoop_p; 854 break; 855 case VCHR: 856 case VBLK: 857 vp->v_op = cd9660_specop_p; 858 addaliasu(vp, ip->inode.iso_rdev); 859 break; 860 default: 861 break; 862 } 863 864 if (ip->iso_extent == imp->root_extent) 865 vp->v_flag |= VROOT; 866 867 /* 868 * XXX need generation number? 869 */ 870 871 *vpp = vp; 872 return (0); 873 } 874 875 /* 876 * Vnode pointer to File handle 877 */ 878 /* ARGSUSED */ 879 int 880 cd9660_vptofh(vp, fhp) 881 struct vnode *vp; 882 struct fid *fhp; 883 { 884 register struct iso_node *ip = VTOI(vp); 885 register struct ifid *ifhp; 886 887 ifhp = (struct ifid *)fhp; 888 ifhp->ifid_len = sizeof(struct ifid); 889 890 ifhp->ifid_ino = ip->i_number; 891 ifhp->ifid_start = ip->iso_start; 892 893 #ifdef ISOFS_DBG 894 printf("vptofh: ino %d, start %ld\n", 895 ifhp->ifid_ino,ifhp->ifid_start); 896 #endif 897 return 0; 898 } 899