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