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