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