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