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  * %sccs.include.redist.c%
11  *
12  *	@(#)cd9660_vfsops.c	8.16 (Berkeley) 05/14/95
13  */
14 
15 #include <sys/param.h>
16 #include <sys/systm.h>
17 #include <sys/namei.h>
18 #include <sys/proc.h>
19 #include <sys/kernel.h>
20 #include <sys/vnode.h>
21 #include <miscfs/specfs/specdev.h>
22 #include <sys/mount.h>
23 #include <sys/buf.h>
24 #include <sys/file.h>
25 #include <sys/dkbad.h>
26 #include <sys/disklabel.h>
27 #include <sys/ioctl.h>
28 #include <sys/errno.h>
29 #include <sys/malloc.h>
30 #include <sys/stat.h>
31 
32 #include <isofs/cd9660/iso.h>
33 #include <isofs/cd9660/cd9660_node.h>
34 #include <isofs/cd9660/cd9660_mount.h>
35 
36 extern int enodev ();
37 
38 struct vfsops cd9660_vfsops = {
39 	cd9660_mount,
40 	cd9660_start,
41 	cd9660_unmount,
42 	cd9660_root,
43 	cd9660_quotactl,
44 	cd9660_statfs,
45 	cd9660_sync,
46 	cd9660_vget,
47 	cd9660_fhtovp,
48 	cd9660_vptofh,
49 	cd9660_init,
50 	cd9660_sysctl
51 };
52 
53 /*
54  * Called by vfs_mountroot when iso is going to be mounted as root.
55  */
56 
57 static iso_mountfs();
58 
59 cd9660_mountroot()
60 {
61 	struct mount *mp;
62 	extern struct vnode *rootvp;
63 	struct proc *p = curproc;	/* XXX */
64 	struct iso_args args;
65 	int error;
66 
67 	/*
68 	 * Get vnodes for swapdev and rootdev.
69 	 */
70 	if ((error = bdevvp(swapdev, &swapdev_vp)) ||
71 	    (error = bdevvp(rootdev, &rootvp))) {
72 		printf("cd9660_mountroot: can't setup bdevvp's");
73 		return (error);
74 	}
75 
76 	if (error = vfs_rootmountalloc("cd9660", "root_device", &mp))
77 		return (error);
78 	args.flags = ISOFSMNT_ROOT;
79 	if (error = iso_mountfs(rootvp, mp, p, &args)) {
80 		mp->mnt_vfc->vfc_refcount--;
81 		free(mp, M_MOUNT);
82 		return (error);
83 	}
84 	if (error = vfs_lock(mp)) {
85 		(void)cd9660_unmount(mp, 0, p);
86 		mp->mnt_vfc->vfc_refcount--;
87 		free(mp, M_MOUNT);
88 		return (error);
89 	}
90 	CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
91 	(void)cd9660_statfs(mp, &mp->mnt_stat, p);
92 	vfs_unlock(mp);
93 	return (0);
94 }
95 
96 /*
97  * VFS Operations.
98  *
99  * mount system call
100  */
101 cd9660_mount(mp, path, data, ndp, p)
102 	register struct mount *mp;
103 	char *path;
104 	caddr_t data;
105 	struct nameidata *ndp;
106 	struct proc *p;
107 {
108 	struct vnode *devvp;
109 	struct iso_args args;
110 	u_int size;
111 	int error;
112 	struct iso_mnt *imp;
113 
114 	if (error = copyin(data, (caddr_t)&args, sizeof (struct iso_args)))
115 		return (error);
116 
117 	if ((mp->mnt_flag & MNT_RDONLY) == 0)
118 		return (EROFS);
119 
120 	/*
121 	 * If updating, check whether changing from read-only to
122 	 * read/write; if there is no device name, that's all we do.
123 	 */
124 	if (mp->mnt_flag & MNT_UPDATE) {
125 		imp = VFSTOISOFS(mp);
126 		if (args.fspec == 0)
127 			return (vfs_export(mp, &imp->im_export, &args.export));
128 	}
129 	/*
130 	 * Not an update, or updating the name: look up the name
131 	 * and verify that it refers to a sensible block device.
132 	 */
133 	NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, p);
134 	if (error = namei(ndp))
135 		return (error);
136 	devvp = ndp->ni_vp;
137 
138 	if (devvp->v_type != VBLK) {
139 		vrele(devvp);
140 		return ENOTBLK;
141 	}
142 	if (major(devvp->v_rdev) >= nblkdev) {
143 		vrele(devvp);
144 		return ENXIO;
145 	}
146 	if ((mp->mnt_flag & MNT_UPDATE) == 0)
147 		error = iso_mountfs(devvp, mp, p, &args);
148 	else {
149 		if (devvp != imp->im_devvp)
150 			error = EINVAL;	/* needs translation */
151 		else
152 			vrele(devvp);
153 	}
154 	if (error) {
155 		vrele(devvp);
156 		return error;
157 	}
158 	imp = VFSTOISOFS(mp);
159 	(void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
160 	bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
161 	(void) copyinstr(args.fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
162 	    &size);
163 	bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
164 	(void) cd9660_statfs(mp, &mp->mnt_stat, p);
165 	return 0;
166 }
167 
168 /*
169  * Common code for mount and mountroot
170  */
171 static iso_mountfs(devvp, mp, p, argp)
172 	register struct vnode *devvp;
173 	struct mount *mp;
174 	struct proc *p;
175 	struct iso_args *argp;
176 {
177 	register struct iso_mnt *isomp = (struct iso_mnt *)0;
178 	struct buf *bp = NULL;
179 	dev_t dev = devvp->v_rdev;
180 	caddr_t base, space;
181 	int havepart = 0, blks;
182 	int error = EINVAL, i, size;
183 	int needclose = 0;
184 	int ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
185 	extern struct vnode *rootvp;
186 	int j;
187 	int iso_bsize;
188 	int iso_blknum;
189 	struct iso_volume_descriptor *vdp;
190 	struct iso_primary_descriptor *pri;
191 	struct iso_directory_record *rootp;
192 	int logical_block_size;
193 
194 	if (!ronly)
195 		return EROFS;
196 
197 	/*
198 	 * Disallow multiple mounts of the same device.
199 	 * Disallow mounting of a device that is currently in use
200 	 * (except for root, which might share swap device for miniroot).
201 	 * Flush out any old buffers remaining from a previous use.
202 	 */
203 	if (error = vfs_mountedon(devvp))
204 		return error;
205 	if (vcount(devvp) > 1 && devvp != rootvp)
206 		return EBUSY;
207 	if (error = vinvalbuf(devvp, V_SAVE, p->p_ucred, p, 0, 0))
208 		return (error);
209 
210 	if (error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, p))
211 		return error;
212 	needclose = 1;
213 
214 	/* This is the "logical sector size".  The standard says this
215 	 * should be 2048 or the physical sector size on the device,
216 	 * whichever is greater.  For now, we'll just use a constant.
217 	 */
218 	iso_bsize = ISO_DEFAULT_BLOCK_SIZE;
219 
220 	for (iso_blknum = 16; iso_blknum < 100; iso_blknum++) {
221 		if (error = bread(devvp, iso_blknum * btodb(iso_bsize),
222 				  iso_bsize, NOCRED, &bp))
223 			goto out;
224 
225 		vdp = (struct iso_volume_descriptor *)bp->b_data;
226 		if (bcmp (vdp->id, ISO_STANDARD_ID, sizeof vdp->id) != 0) {
227 			error = EINVAL;
228 			goto out;
229 		}
230 
231 		if (isonum_711 (vdp->type) == ISO_VD_END) {
232 			error = EINVAL;
233 			goto out;
234 		}
235 
236 		if (isonum_711 (vdp->type) == ISO_VD_PRIMARY)
237 			break;
238 		brelse(bp);
239 	}
240 
241 	if (isonum_711 (vdp->type) != ISO_VD_PRIMARY) {
242 		error = EINVAL;
243 		goto out;
244 	}
245 
246 	pri = (struct iso_primary_descriptor *)vdp;
247 
248 	logical_block_size = isonum_723 (pri->logical_block_size);
249 
250 	if (logical_block_size < DEV_BSIZE || logical_block_size > MAXBSIZE
251 	    || (logical_block_size & (logical_block_size - 1)) != 0) {
252 		error = EINVAL;
253 		goto out;
254 	}
255 
256 	rootp = (struct iso_directory_record *)pri->root_directory_record;
257 
258 	isomp = malloc(sizeof *isomp, M_ISOFSMNT, M_WAITOK);
259 	bzero((caddr_t)isomp, sizeof *isomp);
260 	isomp->logical_block_size = logical_block_size;
261 	isomp->volume_space_size = isonum_733 (pri->volume_space_size);
262 	bcopy (rootp, isomp->root, sizeof isomp->root);
263 	isomp->root_extent = isonum_733 (rootp->extent);
264 	isomp->root_size = isonum_733 (rootp->size);
265 
266 	isomp->im_bmask = logical_block_size - 1;
267 	isomp->im_bshift = 0;
268 	while ((1 << isomp->im_bshift) < isomp->logical_block_size)
269 		isomp->im_bshift++;
270 
271 	bp->b_flags |= B_AGE;
272 	brelse(bp);
273 	bp = NULL;
274 
275 	mp->mnt_data = (qaddr_t)isomp;
276 	mp->mnt_stat.f_fsid.val[0] = (long)dev;
277 	mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum;
278 	mp->mnt_maxsymlinklen = 0;
279 	mp->mnt_flag |= MNT_LOCAL;
280 	isomp->im_mountp = mp;
281 	isomp->im_dev = dev;
282 	isomp->im_devvp = devvp;
283 
284 	devvp->v_specflags |= SI_MOUNTEDON;
285 
286 	/* Check the Rock Ridge Extention support */
287 	if (!(argp->flags & ISOFSMNT_NORRIP)) {
288 		if (error = bread(isomp->im_devvp,
289 				  (isomp->root_extent + isonum_711(rootp->ext_attr_length)) <<
290 				  (isomp->im_bshift - DEV_BSHIFT),
291 				  isomp->logical_block_size, NOCRED, &bp))
292 		    goto out;
293 
294 		rootp = (struct iso_directory_record *)bp->b_data;
295 
296 		if ((isomp->rr_skip = cd9660_rrip_offset(rootp,isomp)) < 0) {
297 		    argp->flags  |= ISOFSMNT_NORRIP;
298 		} else {
299 		    argp->flags  &= ~ISOFSMNT_GENS;
300 		}
301 
302 		/*
303 		 * The contents are valid,
304 		 * but they will get reread as part of another vnode, so...
305 		 */
306 		bp->b_flags |= B_AGE;
307 		brelse(bp);
308 		bp = NULL;
309 	}
310 	isomp->im_flags = argp->flags&(ISOFSMNT_NORRIP|ISOFSMNT_GENS|ISOFSMNT_EXTATT);
311 	switch (isomp->im_flags&(ISOFSMNT_NORRIP|ISOFSMNT_GENS)) {
312 	default:
313 	    isomp->iso_ftype = ISO_FTYPE_DEFAULT;
314 	    break;
315 	case ISOFSMNT_GENS|ISOFSMNT_NORRIP:
316 	    isomp->iso_ftype = ISO_FTYPE_9660;
317 	    break;
318 	case 0:
319 	    isomp->iso_ftype = ISO_FTYPE_RRIP;
320 	    break;
321 	}
322 
323 	return 0;
324 out:
325 	if (bp)
326 		brelse(bp);
327 	if (needclose)
328 		(void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, p);
329 	if (isomp) {
330 		free((caddr_t)isomp, M_ISOFSMNT);
331 		mp->mnt_data = (qaddr_t)0;
332 	}
333 	return error;
334 }
335 
336 /*
337  * Make a filesystem operational.
338  * Nothing to do at the moment.
339  */
340 /* ARGSUSED */
341 cd9660_start(mp, flags, p)
342 	struct mount *mp;
343 	int flags;
344 	struct proc *p;
345 {
346 	return 0;
347 }
348 
349 /*
350  * unmount system call
351  */
352 int
353 cd9660_unmount(mp, mntflags, p)
354 	struct mount *mp;
355 	int mntflags;
356 	struct proc *p;
357 {
358 	register struct iso_mnt *isomp;
359 	int i, error, ronly, flags = 0;
360 
361 	if (mntflags & MNT_FORCE)
362 		flags |= FORCECLOSE;
363 #if 0
364 	mntflushbuf(mp, 0);
365 	if (mntinvalbuf(mp))
366 		return EBUSY;
367 #endif
368 	if (error = vflush(mp, NULLVP, flags))
369 		return (error);
370 
371 	isomp = VFSTOISOFS(mp);
372 
373 #ifdef	ISODEVMAP
374 	if (isomp->iso_ftype == ISO_FTYPE_RRIP)
375 		iso_dunmap(isomp->im_dev);
376 #endif
377 
378 	isomp->im_devvp->v_specflags &= ~SI_MOUNTEDON;
379 	error = VOP_CLOSE(isomp->im_devvp, FREAD, NOCRED, p);
380 	vrele(isomp->im_devvp);
381 	free((caddr_t)isomp, M_ISOFSMNT);
382 	mp->mnt_data = (qaddr_t)0;
383 	mp->mnt_flag &= ~MNT_LOCAL;
384 	return (error);
385 }
386 
387 /*
388  * Return root of a filesystem
389  */
390 cd9660_root(mp, vpp)
391 	struct mount *mp;
392 	struct vnode **vpp;
393 {
394 	struct iso_mnt *imp = VFSTOISOFS(mp);
395 	struct iso_directory_record *dp =
396 	    (struct iso_directory_record *)imp->root;
397 	ino_t ino = isodirino(dp, imp);
398 
399 	/*
400 	 * With RRIP we must use the `.' entry of the root directory.
401 	 * Simply tell vget, that it's a relocated directory.
402 	 */
403 	return (cd9660_vget_internal(mp, ino, vpp,
404 	    imp->iso_ftype == ISO_FTYPE_RRIP, dp));
405 }
406 
407 /*
408  * Do operations associated with quotas, not supported
409  */
410 /* ARGSUSED */
411 int
412 cd9660_quotactl(mp, cmd, uid, arg, p)
413 	struct mount *mp;
414 	int cmd;
415 	uid_t uid;
416 	caddr_t arg;
417 	struct proc *p;
418 {
419 
420 	return (EOPNOTSUPP);
421 }
422 
423 /*
424  * Get file system statistics.
425  */
426 cd9660_statfs(mp, sbp, p)
427 	struct mount *mp;
428 	register struct statfs *sbp;
429 	struct proc *p;
430 {
431 	register struct iso_mnt *isomp;
432 	register struct fs *fs;
433 
434 	isomp = VFSTOISOFS(mp);
435 
436 #ifdef COMPAT_09
437 	sbp->f_type = 5;
438 #else
439 	sbp->f_type = 0;
440 #endif
441 	sbp->f_bsize = isomp->logical_block_size;
442 	sbp->f_iosize = sbp->f_bsize;	/* XXX */
443 	sbp->f_blocks = isomp->volume_space_size;
444 	sbp->f_bfree = 0; /* total free blocks */
445 	sbp->f_bavail = 0; /* blocks free for non superuser */
446 	sbp->f_files =  0; /* total files */
447 	sbp->f_ffree = 0; /* free file nodes */
448 	if (sbp != &mp->mnt_stat) {
449 		bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
450 		bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
451 	}
452 	/* Use the first spare for flags: */
453 	sbp->f_spare[0] = isomp->im_flags;
454 	return 0;
455 }
456 
457 /* ARGSUSED */
458 int
459 cd9660_sync(mp, waitfor, cred, p)
460 	struct mount *mp;
461 	int waitfor;
462 	struct ucred *cred;
463 	struct proc *p;
464 {
465 	return (0);
466 }
467 
468 /*
469  * File handle to vnode
470  *
471  * Have to be really careful about stale file handles:
472  * - check that the inode number is in range
473  * - call iget() to get the locked inode
474  * - check for an unallocated inode (i_mode == 0)
475  * - check that the generation number matches
476  */
477 
478 struct ifid {
479 	ushort	ifid_len;
480 	ushort	ifid_pad;
481 	int	ifid_ino;
482 	long	ifid_start;
483 };
484 
485 /* ARGSUSED */
486 int
487 cd9660_fhtovp(mp, fhp, nam, vpp, exflagsp, credanonp)
488 	register struct mount *mp;
489 	struct fid *fhp;
490 	struct mbuf *nam;
491 	struct vnode **vpp;
492 	int *exflagsp;
493 	struct ucred **credanonp;
494 {
495 	struct ifid *ifhp = (struct ifid *)fhp;
496 	register struct iso_node *ip;
497 	register struct netcred *np;
498 	register struct iso_mnt *imp = VFSTOISOFS(mp);
499 	struct vnode *nvp;
500 	int error;
501 
502 #ifdef	ISOFS_DBG
503 	printf("fhtovp: ino %d, start %ld\n",
504 	       ifhp->ifid_ino, ifhp->ifid_start);
505 #endif
506 
507 	/*
508 	 * Get the export permission structure for this <mp, client> tuple.
509 	 */
510 	np = vfs_export_lookup(mp, &imp->im_export, nam);
511 	if (np == NULL)
512 		return (EACCES);
513 
514 	if (error = VFS_VGET(mp, ifhp->ifid_ino, &nvp)) {
515 		*vpp = NULLVP;
516 		return (error);
517 	}
518 	ip = VTOI(nvp);
519 	if (ip->inode.iso_mode == 0) {
520 		vput(nvp);
521 		*vpp = NULLVP;
522 		return (ESTALE);
523 	}
524 	*vpp = nvp;
525 	*exflagsp = np->netc_exflags;
526 	*credanonp = &np->netc_anon;
527 	return (0);
528 }
529 
530 int
531 cd9660_vget(mp, ino, vpp)
532 	struct mount *mp;
533 	ino_t ino;
534 	struct vnode **vpp;
535 {
536 
537 	/*
538 	 * XXXX
539 	 * It would be nice if we didn't always set the `relocated' flag
540 	 * and force the extra read, but I don't want to think about fixing
541 	 * that right now.
542 	 */
543 	return (cd9660_vget_internal(mp, ino, vpp,
544 #if 0
545 	    VFSTOISOFS(mp)->iso_ftype == ISO_FTYPE_RRIP,
546 #else
547 	    0,
548 #endif
549 	    (struct iso_directory_entry *)0));
550 }
551 
552 int
553 cd9660_vget_internal(mp, ino, vpp, relocated, isodir)
554 	struct mount *mp;
555 	ino_t ino;
556 	struct vnode **vpp;
557 	int relocated;
558 	struct iso_directory_record *isodir;
559 {
560 	struct proc *p = curproc;	/* XXX */
561 	struct iso_mnt *imp;
562 	struct iso_node *ip;
563 	struct buf *bp;
564 	struct vnode *vp, *nvp;
565 	dev_t dev;
566 	int error;
567 
568 	imp = VFSTOISOFS(mp);
569 	dev = imp->im_dev;
570 	if ((*vpp = cd9660_ihashget(dev, ino)) != NULLVP)
571 		return (0);
572 
573 	/* Allocate a new vnode/iso_node. */
574 	if (error = getnewvnode(VT_ISOFS, mp, cd9660_vnodeop_p, &vp)) {
575 		*vpp = NULLVP;
576 		return (error);
577 	}
578 	MALLOC(ip, struct iso_node *, sizeof(struct iso_node), M_ISOFSNODE,
579 	    M_WAITOK);
580 	bzero((caddr_t)ip, sizeof(struct iso_node));
581 	lockinit(&ip->i_lock, PINOD, "isonode", 0, 0);
582 	vp->v_data = ip;
583 	ip->i_vnode = vp;
584 	ip->i_dev = dev;
585 	ip->i_number = ino;
586 
587 	/*
588 	 * Put it onto its hash chain and lock it so that other requests for
589 	 * this inode will block if they arrive while we are sleeping waiting
590 	 * for old data structures to be purged or for the contents of the
591 	 * disk portion of this inode to be read.
592 	 */
593 	cd9660_ihashins(ip);
594 
595 	if (isodir == 0) {
596 		int lbn, off;
597 
598 		lbn = lblkno(imp, ino);
599 		if (lbn >= imp->volume_space_size) {
600 			vput(vp);
601 			printf("fhtovp: lbn exceed volume space %d\n", lbn);
602 			return (ESTALE);
603 		}
604 
605 		off = blkoff(imp, ino);
606 		if (off + ISO_DIRECTORY_RECORD_SIZE > imp->logical_block_size) {
607 			vput(vp);
608 			printf("fhtovp: crosses block boundary %d\n",
609 			       off + ISO_DIRECTORY_RECORD_SIZE);
610 			return (ESTALE);
611 		}
612 
613 		error = bread(imp->im_devvp,
614 			      lbn << (imp->im_bshift - DEV_BSHIFT),
615 			      imp->logical_block_size, NOCRED, &bp);
616 		if (error) {
617 			vput(vp);
618 			brelse(bp);
619 			printf("fhtovp: bread error %d\n",error);
620 			return (error);
621 		}
622 		isodir = (struct iso_directory_record *)(bp->b_data + off);
623 
624 		if (off + isonum_711(isodir->length) >
625 		    imp->logical_block_size) {
626 			vput(vp);
627 			if (bp != 0)
628 				brelse(bp);
629 			printf("fhtovp: directory crosses block boundary %d[off=%d/len=%d]\n",
630 			       off +isonum_711(isodir->length), off,
631 			       isonum_711(isodir->length));
632 			return (ESTALE);
633 		}
634 
635 #if 0
636 		if (isonum_733(isodir->extent) +
637 		    isonum_711(isodir->ext_attr_length) != ifhp->ifid_start) {
638 			if (bp != 0)
639 				brelse(bp);
640 			printf("fhtovp: file start miss %d vs %d\n",
641 			       isonum_733(isodir->extent) + isonum_711(isodir->ext_attr_length),
642 			       ifhp->ifid_start);
643 			return (ESTALE);
644 		}
645 #endif
646 	} else
647 		bp = 0;
648 
649 	ip->i_mnt = imp;
650 	ip->i_devvp = imp->im_devvp;
651 	VREF(ip->i_devvp);
652 
653 	if (relocated) {
654 		/*
655 		 * On relocated directories we must
656 		 * read the `.' entry out of a dir.
657 		 */
658 		ip->iso_start = ino >> imp->im_bshift;
659 		if (bp != 0)
660 			brelse(bp);
661 		if (error = VOP_BLKATOFF(vp, (off_t)0, NULL, &bp)) {
662 			vput(vp);
663 			return (error);
664 		}
665 		isodir = (struct iso_directory_record *)bp->b_data;
666 	}
667 
668 	ip->iso_extent = isonum_733(isodir->extent);
669 	ip->i_size = isonum_733(isodir->size);
670 	ip->iso_start = isonum_711(isodir->ext_attr_length) + ip->iso_extent;
671 
672 	/*
673 	 * Setup time stamp, attribute
674 	 */
675 	vp->v_type = VNON;
676 	switch (imp->iso_ftype) {
677 	default:	/* ISO_FTYPE_9660 */
678 	    {
679 		struct buf *bp2;
680 		int off;
681 		if ((imp->im_flags & ISOFSMNT_EXTATT)
682 		    && (off = isonum_711(isodir->ext_attr_length)))
683 			VOP_BLKATOFF(vp, (off_t)-(off << imp->im_bshift), NULL,
684 				     &bp2);
685 		else
686 			bp2 = NULL;
687 		cd9660_defattr(isodir, ip, bp2);
688 		cd9660_deftstamp(isodir, ip, bp2);
689 		if (bp2)
690 			brelse(bp2);
691 		break;
692 	    }
693 	case ISO_FTYPE_RRIP:
694 		cd9660_rrip_analyze(isodir, ip, imp);
695 		break;
696 	}
697 
698 	if (bp != 0)
699 		brelse(bp);
700 
701 	/*
702 	 * Initialize the associated vnode
703 	 */
704 	switch (vp->v_type = IFTOVT(ip->inode.iso_mode)) {
705 	case VFIFO:
706 #ifdef	FIFO
707 		vp->v_op = cd9660_fifoop_p;
708 		break;
709 #else
710 		vput(vp);
711 		return (EOPNOTSUPP);
712 #endif	/* FIFO */
713 	case VCHR:
714 	case VBLK:
715 		/*
716 		 * if device, look at device number table for translation
717 		 */
718 #ifdef	ISODEVMAP
719 		if (dp = iso_dmap(dev, ino, 0))
720 			ip->inode.iso_rdev = dp->d_dev;
721 #endif
722 		vp->v_op = cd9660_specop_p;
723 		if (nvp = checkalias(vp, ip->inode.iso_rdev, mp)) {
724 			/*
725 			 * Discard unneeded vnode, but save its iso_node.
726 			 */
727 			cd9660_ihashrem(ip);
728 			VOP_UNLOCK(vp, 0, p);
729 			nvp->v_data = vp->v_data;
730 			vp->v_data = NULL;
731 			vp->v_op = spec_vnodeop_p;
732 			vrele(vp);
733 			vgone(vp);
734 			/*
735 			 * Reinitialize aliased inode.
736 			 */
737 			vp = nvp;
738 			ip->i_vnode = vp;
739 			cd9660_ihashins(ip);
740 		}
741 		break;
742 	}
743 
744 	if (ip->iso_extent == imp->root_extent)
745 		vp->v_flag |= VROOT;
746 
747 	/*
748 	 * XXX need generation number?
749 	 */
750 
751 	*vpp = vp;
752 	return (0);
753 }
754 
755 /*
756  * Vnode pointer to File handle
757  */
758 /* ARGSUSED */
759 cd9660_vptofh(vp, fhp)
760 	struct vnode *vp;
761 	struct fid *fhp;
762 {
763 	register struct iso_node *ip = VTOI(vp);
764 	register struct ifid *ifhp;
765 	register struct iso_mnt *mp = ip->i_mnt;
766 
767 	ifhp = (struct ifid *)fhp;
768 	ifhp->ifid_len = sizeof(struct ifid);
769 
770 	ifhp->ifid_ino = ip->i_number;
771 	ifhp->ifid_start = ip->iso_start;
772 
773 #ifdef	ISOFS_DBG
774 	printf("vptofh: ino %d, start %ld\n",
775 	       ifhp->ifid_ino,ifhp->ifid_start);
776 #endif
777 	return 0;
778 }
779