Home | History | Annotate | Line # | Download | only in cd9660
cd9660_vfsops.c revision 1.2
      1 /*	$NetBSD: cd9660_vfsops.c,v 1.2 2003/02/01 06:23:41 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1994
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This code is derived from software contributed to Berkeley
      8  * by Pace Willisson (pace (at) blitz.com).  The Rock Ridge Extension
      9  * Support code is derived from software contributed to Berkeley
     10  * by Atsushi Murai (amurai (at) spec.co.jp).
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions and the following disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  * 3. All advertising materials mentioning features or use of this software
     21  *    must display the following acknowledgement:
     22  *	This product includes software developed by the University of
     23  *	California, Berkeley and its contributors.
     24  * 4. Neither the name of the University nor the names of its contributors
     25  *    may be used to endorse or promote products derived from this software
     26  *    without specific prior written permission.
     27  *
     28  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     38  * SUCH DAMAGE.
     39  *
     40  *	@(#)cd9660_vfsops.c	8.18 (Berkeley) 5/22/95
     41  */
     42 
     43 #include <sys/cdefs.h>
     44 __KERNEL_RCSID(0, "$NetBSD: cd9660_vfsops.c,v 1.2 2003/02/01 06:23:41 thorpej Exp $");
     45 
     46 #if defined(_KERNEL_OPT)
     47 #include "opt_compat_netbsd.h"
     48 #endif
     49 
     50 #include <sys/param.h>
     51 #include <sys/systm.h>
     52 #include <sys/namei.h>
     53 #include <sys/proc.h>
     54 #include <sys/kernel.h>
     55 #include <sys/vnode.h>
     56 #include <miscfs/specfs/specdev.h>
     57 #include <sys/mount.h>
     58 #include <sys/buf.h>
     59 #include <sys/file.h>
     60 #include <sys/disklabel.h>
     61 #include <sys/device.h>
     62 #include <sys/ioctl.h>
     63 #include <sys/cdio.h>
     64 #include <sys/errno.h>
     65 #include <sys/malloc.h>
     66 #include <sys/pool.h>
     67 #include <sys/stat.h>
     68 #include <sys/conf.h>
     69 
     70 #include <fs/cd9660/iso.h>
     71 #include <fs/cd9660/cd9660_extern.h>
     72 #include <fs/cd9660/iso_rrip.h>
     73 #include <fs/cd9660/cd9660_node.h>
     74 #include <fs/cd9660/cd9660_mount.h>
     75 
     76 MALLOC_DEFINE(M_ISOFSMNT, "ISOFS mount", "ISOFS mount structure");
     77 
     78 extern const struct vnodeopv_desc cd9660_vnodeop_opv_desc;
     79 extern const struct vnodeopv_desc cd9660_specop_opv_desc;
     80 extern const struct vnodeopv_desc cd9660_fifoop_opv_desc;
     81 
     82 const struct vnodeopv_desc * const cd9660_vnodeopv_descs[] = {
     83 	&cd9660_vnodeop_opv_desc,
     84 	&cd9660_specop_opv_desc,
     85 	&cd9660_fifoop_opv_desc,
     86 	NULL,
     87 };
     88 
     89 struct vfsops cd9660_vfsops = {
     90 	MOUNT_CD9660,
     91 	cd9660_mount,
     92 	cd9660_start,
     93 	cd9660_unmount,
     94 	cd9660_root,
     95 	cd9660_quotactl,
     96 	cd9660_statfs,
     97 	cd9660_sync,
     98 	cd9660_vget,
     99 	cd9660_fhtovp,
    100 	cd9660_vptofh,
    101 	cd9660_init,
    102 	cd9660_reinit,
    103 	cd9660_done,
    104 	cd9660_sysctl,
    105 	cd9660_mountroot,
    106 	cd9660_check_export,
    107 	cd9660_vnodeopv_descs,
    108 };
    109 
    110 struct genfs_ops cd9660_genfsops = {
    111 	genfs_size,
    112 };
    113 
    114 /*
    115  * Called by vfs_mountroot when iso is going to be mounted as root.
    116  *
    117  * Name is updated by mount(8) after booting.
    118  */
    119 #define ROOTNAME	"root_device"
    120 
    121 static int iso_makemp __P((struct iso_mnt *isomp, struct buf *bp, int *ea_len));
    122 static int iso_mountfs __P((struct vnode *devvp, struct mount *mp,
    123 		struct proc *p, struct iso_args *argp));
    124 
    125 int
    126 cd9660_mountroot()
    127 {
    128 	struct mount *mp;
    129 	struct proc *p = curproc;	/* XXX */
    130 	int error;
    131 	struct iso_args args;
    132 
    133 	if (root_device->dv_class != DV_DISK)
    134 		return (ENODEV);
    135 
    136 	/*
    137 	 * Get vnodes for swapdev and rootdev.
    138 	 */
    139 	if (bdevvp(rootdev, &rootvp))
    140 		panic("cd9660_mountroot: can't setup rootvp");
    141 
    142 	if ((error = vfs_rootmountalloc(MOUNT_CD9660, "root_device", &mp))
    143 			!= 0) {
    144 		vrele(rootvp);
    145 		return (error);
    146 	}
    147 
    148 	args.flags = ISOFSMNT_ROOT;
    149 	if ((error = iso_mountfs(rootvp, mp, p, &args)) != 0) {
    150 		mp->mnt_op->vfs_refcount--;
    151 		vfs_unbusy(mp);
    152 		free(mp, M_MOUNT);
    153 		vrele(rootvp);
    154 		return (error);
    155 	}
    156 	simple_lock(&mountlist_slock);
    157 	CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
    158 	simple_unlock(&mountlist_slock);
    159 	(void)cd9660_statfs(mp, &mp->mnt_stat, p);
    160 	vfs_unbusy(mp);
    161 	inittodr(0);
    162 	return (0);
    163 }
    164 
    165 /*
    166  * VFS Operations.
    167  *
    168  * mount system call
    169  */
    170 int
    171 cd9660_mount(mp, path, data, ndp, p)
    172 	struct mount *mp;
    173 	const char *path;
    174 	void *data;
    175 	struct nameidata *ndp;
    176 	struct proc *p;
    177 {
    178 	struct vnode *devvp;
    179 	struct iso_args args;
    180 	size_t size;
    181 	int error;
    182 	struct iso_mnt *imp = NULL;
    183 
    184 	if (mp->mnt_flag & MNT_GETARGS) {
    185 		imp = VFSTOISOFS(mp);
    186 		if (imp == NULL)
    187 			return EIO;
    188 		args.fspec = NULL;
    189 		args.flags = imp->im_flags;
    190 		vfs_showexport(mp, &args.export, &imp->im_export);
    191 		return copyout(&args, data, sizeof(args));
    192 	}
    193 	error = copyin(data, (caddr_t)&args, sizeof (struct iso_args));
    194 	if (error)
    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)) != 0)
    215 		return (error);
    216 	devvp = ndp->ni_vp;
    217 
    218 	if (devvp->v_type != VBLK) {
    219 		vrele(devvp);
    220 		return ENOTBLK;
    221 	}
    222 	if (bdevsw_lookup(devvp->v_rdev) == NULL) {
    223 		vrele(devvp);
    224 		return ENXIO;
    225 	}
    226 	/*
    227 	 * If mount by non-root, then verify that user has necessary
    228 	 * permissions on the device.
    229 	 */
    230 	if (p->p_ucred->cr_uid != 0) {
    231 		vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
    232 		error = VOP_ACCESS(devvp, VREAD, p->p_ucred, p);
    233 		VOP_UNLOCK(devvp, 0);
    234 		if (error) {
    235 			vrele(devvp);
    236 			return (error);
    237 		}
    238 	}
    239 	if ((mp->mnt_flag & MNT_UPDATE) == 0)
    240 		error = iso_mountfs(devvp, mp, p, &args);
    241 	else {
    242 		if (devvp != imp->im_devvp)
    243 			error = EINVAL;	/* needs translation */
    244 		else
    245 			vrele(devvp);
    246 	}
    247 	if (error) {
    248 		vrele(devvp);
    249 		return error;
    250 	}
    251 	imp = VFSTOISOFS(mp);
    252 	(void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
    253 	memset(mp->mnt_stat.f_mntonname + size, 0, MNAMELEN - size);
    254 	(void) copyinstr(args.fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
    255 	    &size);
    256 	memset(mp->mnt_stat.f_mntfromname + size, 0, MNAMELEN - size);
    257 	return 0;
    258 }
    259 
    260 /*
    261  * Make a mount point from a volume descriptor
    262  */
    263 static int
    264 iso_makemp(isomp, bp, ea_len)
    265 	struct iso_mnt *isomp;
    266 	struct buf *bp;
    267 	int *ea_len;
    268 {
    269 	struct iso_primary_descriptor *pri;
    270 	int logical_block_size;
    271 	struct iso_directory_record *rootp;
    272 
    273 	pri = (struct iso_primary_descriptor *)bp->b_data;
    274 
    275 	logical_block_size = isonum_723 (pri->logical_block_size);
    276 
    277 	if (logical_block_size < DEV_BSIZE || logical_block_size > MAXBSIZE
    278 	    || (logical_block_size & (logical_block_size - 1)) != 0)
    279 		return -1;
    280 
    281 	rootp = (struct iso_directory_record *)pri->root_directory_record;
    282 
    283 	isomp->logical_block_size = logical_block_size;
    284 	isomp->volume_space_size = isonum_733 (pri->volume_space_size);
    285 	memcpy(isomp->root, rootp, sizeof(isomp->root));
    286 	isomp->root_extent = isonum_733 (rootp->extent);
    287 	isomp->root_size = isonum_733 (rootp->size);
    288 	isomp->im_joliet_level = 0;
    289 
    290 	isomp->im_bmask = logical_block_size - 1;
    291 	isomp->im_bshift = 0;
    292 	while ((1 << isomp->im_bshift) < isomp->logical_block_size)
    293 		isomp->im_bshift++;
    294 
    295 	if (ea_len != NULL)
    296 		*ea_len = isonum_711(rootp->ext_attr_length);
    297 
    298 	return 0;
    299 }
    300 
    301 /*
    302  * Common code for mount and mountroot
    303  */
    304 static int
    305 iso_mountfs(devvp, mp, p, argp)
    306 	struct vnode *devvp;
    307 	struct mount *mp;
    308 	struct proc *p;
    309 	struct iso_args *argp;
    310 {
    311 	struct iso_mnt *isomp = (struct iso_mnt *)0;
    312 	struct buf *bp = NULL, *pribp = NULL, *supbp = NULL;
    313 	dev_t dev = devvp->v_rdev;
    314 	int error = EINVAL;
    315 	int needclose = 0;
    316 	int ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
    317 	int iso_bsize;
    318 	int iso_blknum;
    319 	int joliet_level;
    320 	struct iso_volume_descriptor *vdp;
    321 	struct iso_supplementary_descriptor *sup;
    322 	int sess = 0;
    323 	int ext_attr_length;
    324 	struct disklabel label;
    325 
    326 	if (!ronly)
    327 		return EROFS;
    328 
    329 	/*
    330 	 * Disallow multiple mounts of the same device.
    331 	 * Disallow mounting of a device that is currently in use
    332 	 * (except for root, which might share swap device for miniroot).
    333 	 * Flush out any old buffers remaining from a previous use.
    334 	 */
    335 	if ((error = vfs_mountedon(devvp)) != 0)
    336 		return error;
    337 	if (vcount(devvp) > 1 && devvp != rootvp)
    338 		return EBUSY;
    339 	if ((error = vinvalbuf(devvp, V_SAVE, p->p_ucred, p, 0, 0)) != 0)
    340 		return (error);
    341 
    342 	error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, p);
    343 	if (error)
    344 		return error;
    345 	needclose = 1;
    346 
    347 	/* This is the "logical sector size".  The standard says this
    348 	 * should be 2048 or the physical sector size on the device,
    349 	 * whichever is greater.  For now, we'll just use a constant.
    350 	 */
    351 	iso_bsize = ISO_DEFAULT_BLOCK_SIZE;
    352 
    353 	error = VOP_IOCTL(devvp, DIOCGDINFO, (caddr_t)&label, FREAD, FSCRED, p);
    354 	if (!error &&
    355 	    label.d_partitions[DISKPART(dev)].p_fstype == FS_ISO9660) {
    356 		/* XXX more sanity checks? */
    357 		sess = label.d_partitions[DISKPART(dev)].p_cdsession;
    358 	} else {
    359 		/* fallback to old method */
    360 		error = VOP_IOCTL(devvp, CDIOREADMSADDR, (caddr_t)&sess, 0,
    361 				  FSCRED, p);
    362 		if (error)
    363 			sess = 0;	/* never mind */
    364 	}
    365 #ifdef DEBUG
    366 	printf("isofs: session offset (part %d) %d\n", DISKPART(dev), sess);
    367 #endif
    368 
    369 	for (iso_blknum = 16; iso_blknum < 100; iso_blknum++) {
    370 		if ((error = bread(devvp, (iso_blknum+sess) * btodb(iso_bsize),
    371 				   iso_bsize, NOCRED, &bp)) != 0)
    372 			goto out;
    373 
    374 		vdp = (struct iso_volume_descriptor *)bp->b_data;
    375 		if (memcmp(vdp->id, ISO_STANDARD_ID, sizeof(vdp->id)) != 0) {
    376 			error = EINVAL;
    377 			goto out;
    378 		}
    379 
    380 		switch (isonum_711(vdp->type)) {
    381 		case ISO_VD_PRIMARY:
    382 			if (pribp == NULL) {
    383 				pribp = bp;
    384 				bp = NULL;
    385 			}
    386 			break;
    387 
    388 		case ISO_VD_SUPPLEMENTARY:
    389 			if (supbp == NULL) {
    390 				supbp = bp;
    391 				bp = NULL;
    392 			}
    393 			break;
    394 
    395 		default:
    396 			break;
    397 		}
    398 
    399 		if (isonum_711 (vdp->type) == ISO_VD_END) {
    400 			brelse(bp);
    401 			bp = NULL;
    402 			break;
    403 		}
    404 
    405 		if (bp != NULL) {
    406 			brelse(bp);
    407 			bp = NULL;
    408 		}
    409 	}
    410 
    411 	if (pribp == NULL) {
    412 		error = EINVAL;
    413 		goto out;
    414 	}
    415 
    416 	isomp = malloc(sizeof *isomp, M_ISOFSMNT, M_WAITOK);
    417 	memset((caddr_t)isomp, 0, sizeof *isomp);
    418 	if (iso_makemp(isomp, pribp, &ext_attr_length) == -1) {
    419 		error = EINVAL;
    420 		goto out;
    421 	}
    422 
    423 	isomp->volume_space_size += sess;
    424 
    425 	pribp->b_flags |= B_AGE;
    426 	brelse(pribp);
    427 	pribp = NULL;
    428 
    429 	mp->mnt_data = isomp;
    430 	mp->mnt_stat.f_fsid.val[0] = (long)dev;
    431 	mp->mnt_stat.f_fsid.val[1] = makefstype(MOUNT_CD9660);
    432 	mp->mnt_maxsymlinklen = 0;
    433 	mp->mnt_flag |= MNT_LOCAL;
    434 	mp->mnt_dev_bshift = iso_bsize;
    435 	mp->mnt_fs_bshift = isomp->im_bshift;
    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 Extension support */
    443 	if (!(argp->flags & ISOFSMNT_NORRIP)) {
    444 		struct iso_directory_record *rootp;
    445 
    446 		if ((error = bread(isomp->im_devvp,
    447 				   (isomp->root_extent + ext_attr_length) <<
    448 				   (isomp->im_bshift - DEV_BSHIFT),
    449 				   isomp->logical_block_size, NOCRED,
    450 				   &bp)) != 0)
    451 		    goto out;
    452 
    453 		rootp = (struct iso_directory_record *)bp->b_data;
    454 
    455 		if ((isomp->rr_skip = cd9660_rrip_offset(rootp,isomp)) < 0) {
    456 		    argp->flags  |= ISOFSMNT_NORRIP;
    457 		} else {
    458 		    argp->flags  &= ~ISOFSMNT_GENS;
    459 		}
    460 
    461 		/*
    462 		 * The contents are valid,
    463 		 * but they will get reread as part of another vnode, so...
    464 		 */
    465 		bp->b_flags |= B_AGE;
    466 		brelse(bp);
    467 		bp = NULL;
    468 	}
    469 	isomp->im_flags = argp->flags & (ISOFSMNT_NORRIP | ISOFSMNT_GENS |
    470 		 ISOFSMNT_EXTATT | ISOFSMNT_NOJOLIET | ISOFSMNT_RRCASEINS);
    471 
    472 	if (isomp->im_flags & ISOFSMNT_GENS)
    473 		isomp->iso_ftype = ISO_FTYPE_9660;
    474 	else if (isomp->im_flags & ISOFSMNT_NORRIP) {
    475 		isomp->iso_ftype = ISO_FTYPE_DEFAULT;
    476 		if (argp->flags & ISOFSMNT_NOCASETRANS)
    477 			isomp->im_flags |= ISOFSMNT_NOCASETRANS;
    478 	} else
    479 		isomp->iso_ftype = ISO_FTYPE_RRIP;
    480 
    481 	/* Check the Joliet Extension support */
    482 	if ((argp->flags & ISOFSMNT_NORRIP) != 0 &&
    483 	    (argp->flags & ISOFSMNT_NOJOLIET) == 0 &&
    484 	    supbp != NULL) {
    485 		joliet_level = 0;
    486 		sup = (struct iso_supplementary_descriptor *)supbp->b_data;
    487 
    488 		if ((isonum_711(sup->flags) & 1) == 0) {
    489 			if (memcmp(sup->escape, "%/@", 3) == 0)
    490 				joliet_level = 1;
    491 			if (memcmp(sup->escape, "%/C", 3) == 0)
    492 				joliet_level = 2;
    493 			if (memcmp(sup->escape, "%/E", 3) == 0)
    494 				joliet_level = 3;
    495 		}
    496 		if (joliet_level != 0) {
    497 			if (iso_makemp(isomp, supbp, NULL) == -1) {
    498 				error = EINVAL;
    499 				goto out;
    500 			}
    501 			isomp->im_joliet_level = joliet_level;
    502 		}
    503 	}
    504 
    505 	if (supbp != NULL) {
    506 		brelse(supbp);
    507 		supbp = NULL;
    508 	}
    509 
    510 	return 0;
    511 out:
    512 	if (bp)
    513 		brelse(bp);
    514 	if (pribp)
    515 		brelse(pribp);
    516 	if (supbp)
    517 		brelse(supbp);
    518 	if (needclose) {
    519 		vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
    520 		(void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, p);
    521 		VOP_UNLOCK(devvp, 0);
    522 	}
    523 	if (isomp) {
    524 		free((caddr_t)isomp, M_ISOFSMNT);
    525 		mp->mnt_data = NULL;
    526 	}
    527 	return error;
    528 }
    529 
    530 /*
    531  * Make a filesystem operational.
    532  * Nothing to do at the moment.
    533  */
    534 /* ARGSUSED */
    535 int
    536 cd9660_start(mp, flags, p)
    537 	struct mount *mp;
    538 	int flags;
    539 	struct proc *p;
    540 {
    541 	return 0;
    542 }
    543 
    544 /*
    545  * unmount system call
    546  */
    547 int
    548 cd9660_unmount(mp, mntflags, p)
    549 	struct mount *mp;
    550 	int mntflags;
    551 	struct proc *p;
    552 {
    553 	struct iso_mnt *isomp;
    554 	int error, flags = 0;
    555 
    556 	if (mntflags & MNT_FORCE)
    557 		flags |= FORCECLOSE;
    558 #if 0
    559 	mntflushbuf(mp, 0);
    560 	if (mntinvalbuf(mp))
    561 		return EBUSY;
    562 #endif
    563 	if ((error = vflush(mp, NULLVP, flags)) != 0)
    564 		return (error);
    565 
    566 	isomp = VFSTOISOFS(mp);
    567 
    568 #ifdef	ISODEVMAP
    569 	if (isomp->iso_ftype == ISO_FTYPE_RRIP)
    570 		iso_dunmap(isomp->im_dev);
    571 #endif
    572 
    573 	if (isomp->im_devvp->v_type != VBAD)
    574 		isomp->im_devvp->v_specmountpoint = NULL;
    575 
    576 	vn_lock(isomp->im_devvp, LK_EXCLUSIVE | LK_RETRY);
    577 	error = VOP_CLOSE(isomp->im_devvp, FREAD, NOCRED, p);
    578 	vput(isomp->im_devvp);
    579 	free((caddr_t)isomp, M_ISOFSMNT);
    580 	mp->mnt_data = NULL;
    581 	mp->mnt_flag &= ~MNT_LOCAL;
    582 	return (error);
    583 }
    584 
    585 /*
    586  * Return root of a filesystem
    587  */
    588 int
    589 cd9660_root(mp, vpp)
    590 	struct mount *mp;
    591 	struct vnode **vpp;
    592 {
    593 	struct iso_mnt *imp = VFSTOISOFS(mp);
    594 	struct iso_directory_record *dp =
    595 	    (struct iso_directory_record *)imp->root;
    596 	ino_t ino = isodirino(dp, imp);
    597 
    598 	/*
    599 	 * With RRIP we must use the `.' entry of the root directory.
    600 	 * Simply tell vget, that it's a relocated directory.
    601 	 */
    602 	return (cd9660_vget_internal(mp, ino, vpp,
    603 				     imp->iso_ftype == ISO_FTYPE_RRIP, dp));
    604 }
    605 
    606 /*
    607  * Do operations associated with quotas, not supported
    608  */
    609 /* ARGSUSED */
    610 int
    611 cd9660_quotactl(mp, cmd, uid, arg, p)
    612 	struct mount *mp;
    613 	int cmd;
    614 	uid_t uid;
    615 	caddr_t arg;
    616 	struct proc *p;
    617 {
    618 
    619 	return (EOPNOTSUPP);
    620 }
    621 
    622 /*
    623  * Get file system statistics.
    624  */
    625 int
    626 cd9660_statfs(mp, sbp, p)
    627 	struct mount *mp;
    628 	struct statfs *sbp;
    629 	struct proc *p;
    630 {
    631 	struct iso_mnt *isomp;
    632 
    633 	isomp = VFSTOISOFS(mp);
    634 
    635 #ifdef COMPAT_09
    636 	sbp->f_type = 5;
    637 #else
    638 	sbp->f_type = 0;
    639 #endif
    640 	sbp->f_bsize = isomp->logical_block_size;
    641 	sbp->f_iosize = sbp->f_bsize;	/* XXX */
    642 	sbp->f_blocks = isomp->volume_space_size;
    643 	sbp->f_bfree = 0; /* total free blocks */
    644 	sbp->f_bavail = 0; /* blocks free for non superuser */
    645 	sbp->f_files =  0; /* total files */
    646 	sbp->f_ffree = 0; /* free file nodes */
    647 	if (sbp != &mp->mnt_stat) {
    648 		memcpy(sbp->f_mntonname, mp->mnt_stat.f_mntonname, MNAMELEN);
    649 		memcpy(sbp->f_mntfromname, mp->mnt_stat.f_mntfromname, MNAMELEN);
    650 	}
    651 	strncpy(sbp->f_fstypename, mp->mnt_op->vfs_name, MFSNAMELEN);
    652 	/* Use the first spare for flags: */
    653 	sbp->f_spare[0] = isomp->im_flags;
    654 	return 0;
    655 }
    656 
    657 /* ARGSUSED */
    658 int
    659 cd9660_sync(mp, waitfor, cred, p)
    660 	struct mount *mp;
    661 	int waitfor;
    662 	struct ucred *cred;
    663 	struct proc *p;
    664 {
    665 	return (0);
    666 }
    667 
    668 /*
    669  * File handle to vnode
    670  *
    671  * Have to be really careful about stale file handles:
    672  * - check that the inode number is in range
    673  * - call iget() to get the locked inode
    674  * - check for an unallocated inode (i_mode == 0)
    675  * - check that the generation number matches
    676  */
    677 
    678 struct ifid {
    679 	ushort	ifid_len;
    680 	ushort	ifid_pad;
    681 	int	ifid_ino;
    682 	long	ifid_start;
    683 };
    684 
    685 /* ARGSUSED */
    686 int
    687 cd9660_fhtovp(mp, fhp, vpp)
    688 	struct mount *mp;
    689 	struct fid *fhp;
    690 	struct vnode **vpp;
    691 {
    692 	struct ifid *ifhp = (struct ifid *)fhp;
    693 	struct iso_node *ip;
    694 	struct vnode *nvp;
    695 	int error;
    696 
    697 #ifdef	ISOFS_DBG
    698 	printf("fhtovp: ino %d, start %ld\n",
    699 	    ifhp->ifid_ino, ifhp->ifid_start);
    700 #endif
    701 
    702 	if ((error = VFS_VGET(mp, ifhp->ifid_ino, &nvp)) != 0) {
    703 		*vpp = NULLVP;
    704 		return (error);
    705 	}
    706 	ip = VTOI(nvp);
    707 	if (ip->inode.iso_mode == 0) {
    708 		vput(nvp);
    709 		*vpp = NULLVP;
    710 		return (ESTALE);
    711 	}
    712 	*vpp = nvp;
    713 	return (0);
    714 }
    715 
    716 /* ARGSUSED */
    717 int
    718 cd9660_check_export(mp, nam, exflagsp, credanonp)
    719 	struct mount *mp;
    720 	struct mbuf *nam;
    721 	int *exflagsp;
    722 	struct ucred **credanonp;
    723 {
    724 	struct netcred *np;
    725 	struct iso_mnt *imp = VFSTOISOFS(mp);
    726 
    727 #ifdef	ISOFS_DBG
    728 	printf("check_export: ino %d, start %ld\n",
    729 	    ifhp->ifid_ino, ifhp->ifid_start);
    730 #endif
    731 
    732 	/*
    733 	 * Get the export permission structure for this <mp, client> tuple.
    734 	 */
    735 	np = vfs_export_lookup(mp, &imp->im_export, nam);
    736 	if (np == NULL)
    737 		return (EACCES);
    738 
    739 	*exflagsp = np->netc_exflags;
    740 	*credanonp = &np->netc_anon;
    741 	return (0);
    742 }
    743 
    744 int
    745 cd9660_vget(mp, ino, vpp)
    746 	struct mount *mp;
    747 	ino_t ino;
    748 	struct vnode **vpp;
    749 {
    750 
    751 	/*
    752 	 * XXXX
    753 	 * It would be nice if we didn't always set the `relocated' flag
    754 	 * and force the extra read, but I don't want to think about fixing
    755 	 * that right now.
    756 	 */
    757 	return (cd9660_vget_internal(mp, ino, vpp,
    758 #if 0
    759 				     VFSTOISOFS(mp)->iso_ftype == ISO_FTYPE_RRIP,
    760 #else
    761 				     0,
    762 #endif
    763 				     NULL));
    764 }
    765 
    766 int
    767 cd9660_vget_internal(mp, ino, vpp, relocated, isodir)
    768 	struct mount *mp;
    769 	ino_t ino;
    770 	struct vnode **vpp;
    771 	int relocated;
    772 	struct iso_directory_record *isodir;
    773 {
    774 	struct iso_mnt *imp;
    775 	struct iso_node *ip;
    776 #ifdef ISODEVMAP
    777 	struct iso_dnode *dp;
    778 #endif
    779 	struct buf *bp;
    780 	struct vnode *vp, *nvp;
    781 	dev_t dev;
    782 	int error;
    783 
    784 	imp = VFSTOISOFS(mp);
    785 	dev = imp->im_dev;
    786 	if ((*vpp = cd9660_ihashget(dev, ino)) != NULLVP)
    787 		return (0);
    788 
    789 	/* Allocate a new vnode/iso_node. */
    790 	if ((error = getnewvnode(VT_ISOFS, mp, cd9660_vnodeop_p, &vp)) != 0) {
    791 		*vpp = NULLVP;
    792 		return (error);
    793 	}
    794 	ip = pool_get(&cd9660_node_pool, PR_WAITOK);
    795 	memset((caddr_t)ip, 0, sizeof(struct iso_node));
    796 	vp->v_data = ip;
    797 	ip->i_vnode = vp;
    798 	ip->i_dev = dev;
    799 	ip->i_number = ino;
    800 
    801 	/*
    802 	 * Put it onto its hash chain and lock it so that other requests for
    803 	 * this inode will block if they arrive while we are sleeping waiting
    804 	 * for old data structures to be purged or for the contents of the
    805 	 * disk portion of this inode to be read.
    806 	 */
    807 	cd9660_ihashins(ip);
    808 
    809 	if (isodir == 0) {
    810 		int lbn, off;
    811 
    812 		lbn = lblkno(imp, ino);
    813 		if (lbn >= imp->volume_space_size) {
    814 			vput(vp);
    815 			printf("fhtovp: lbn exceed volume space %d\n", lbn);
    816 			return (ESTALE);
    817 		}
    818 
    819 		off = blkoff(imp, ino);
    820 		if (off + ISO_DIRECTORY_RECORD_SIZE > imp->logical_block_size) {
    821 			vput(vp);
    822 			printf("fhtovp: crosses block boundary %d\n",
    823 			    off + ISO_DIRECTORY_RECORD_SIZE);
    824 			return (ESTALE);
    825 		}
    826 
    827 		error = bread(imp->im_devvp,
    828 			      lbn << (imp->im_bshift - DEV_BSHIFT),
    829 			      imp->logical_block_size, NOCRED, &bp);
    830 		if (error) {
    831 			vput(vp);
    832 			brelse(bp);
    833 			printf("fhtovp: bread error %d\n",error);
    834 			return (error);
    835 		}
    836 		isodir = (struct iso_directory_record *)(bp->b_data + off);
    837 
    838 		if (off + isonum_711(isodir->length) >
    839 		    imp->logical_block_size) {
    840 			vput(vp);
    841 			if (bp != 0)
    842 				brelse(bp);
    843 			printf("fhtovp: directory crosses block boundary %d[off=%d/len=%d]\n",
    844 			    off +isonum_711(isodir->length), off,
    845 			    isonum_711(isodir->length));
    846 			return (ESTALE);
    847 		}
    848 
    849 #if 0
    850 		if (isonum_733(isodir->extent) +
    851 		    isonum_711(isodir->ext_attr_length) != ifhp->ifid_start) {
    852 			if (bp != 0)
    853 				brelse(bp);
    854 			printf("fhtovp: file start miss %d vs %d\n",
    855 			    isonum_733(isodir->extent) + isonum_711(isodir->ext_attr_length),
    856 			    ifhp->ifid_start);
    857 			return (ESTALE);
    858 		}
    859 #endif
    860 	} else
    861 		bp = 0;
    862 
    863 	ip->i_mnt = imp;
    864 	ip->i_devvp = imp->im_devvp;
    865 	VREF(ip->i_devvp);
    866 
    867 	if (relocated) {
    868 		/*
    869 		 * On relocated directories we must
    870 		 * read the `.' entry out of a dir.
    871 		 */
    872 		ip->iso_start = ino >> imp->im_bshift;
    873 		if (bp != 0)
    874 			brelse(bp);
    875 		if ((error = VOP_BLKATOFF(vp, (off_t)0, NULL, &bp)) != 0) {
    876 			vput(vp);
    877 			return (error);
    878 		}
    879 		isodir = (struct iso_directory_record *)bp->b_data;
    880 	}
    881 
    882 	ip->iso_extent = isonum_733(isodir->extent);
    883 	ip->i_size = isonum_733(isodir->size);
    884 	ip->iso_start = isonum_711(isodir->ext_attr_length) + ip->iso_extent;
    885 
    886 	/*
    887 	 * Setup time stamp, attribute
    888 	 */
    889 	vp->v_type = VNON;
    890 	switch (imp->iso_ftype) {
    891 	default:	/* ISO_FTYPE_9660 */
    892 	    {
    893 		struct buf *bp2;
    894 		int off;
    895 		if ((imp->im_flags & ISOFSMNT_EXTATT)
    896 		    && (off = isonum_711(isodir->ext_attr_length)))
    897 			VOP_BLKATOFF(vp, (off_t)-(off << imp->im_bshift), NULL,
    898 				     &bp2);
    899 		else
    900 			bp2 = NULL;
    901 		cd9660_defattr(isodir, ip, bp2);
    902 		cd9660_deftstamp(isodir, ip, bp2);
    903 		if (bp2)
    904 			brelse(bp2);
    905 		break;
    906 	    }
    907 	case ISO_FTYPE_RRIP:
    908 		cd9660_rrip_analyze(isodir, ip, imp);
    909 		break;
    910 	}
    911 
    912 	if (bp != 0)
    913 		brelse(bp);
    914 
    915 	/*
    916 	 * Initialize the associated vnode
    917 	 */
    918 	switch (vp->v_type = IFTOVT(ip->inode.iso_mode)) {
    919 	case VFIFO:
    920 		vp->v_op = cd9660_fifoop_p;
    921 		break;
    922 	case VCHR:
    923 	case VBLK:
    924 		/*
    925 		 * if device, look at device number table for translation
    926 		 */
    927 #ifdef	ISODEVMAP
    928 		if ((dp = iso_dmap(dev, ino, 0)) != NULL)
    929 			ip->inode.iso_rdev = dp->d_dev;
    930 #endif
    931 		vp->v_op = cd9660_specop_p;
    932 		if ((nvp = checkalias(vp, ip->inode.iso_rdev, mp)) != NULL) {
    933 			/*
    934 			 * Discard unneeded vnode, but save its iso_node.
    935 			 * Note that the lock is carried over in the iso_node
    936 			 * to the replacement vnode.
    937 			 */
    938 			nvp->v_data = vp->v_data;
    939 			vp->v_data = NULL;
    940 			VOP_UNLOCK(vp, 0);
    941 			vp->v_op = spec_vnodeop_p;
    942 			vrele(vp);
    943 			vgone(vp);
    944 			lockmgr(&nvp->v_lock, LK_EXCLUSIVE, &nvp->v_interlock);
    945 			/*
    946 			 * Reinitialize aliased inode.
    947 			 */
    948 			vp = nvp;
    949 			ip->i_vnode = vp;
    950 		}
    951 		break;
    952 	case VLNK:
    953 	case VNON:
    954 	case VSOCK:
    955 	case VDIR:
    956 	case VBAD:
    957 		break;
    958 	case VREG:
    959 		uvm_vnp_setsize(vp, ip->i_size);
    960 		break;
    961 	}
    962 
    963 	if (ip->iso_extent == imp->root_extent)
    964 		vp->v_flag |= VROOT;
    965 
    966 	/*
    967 	 * XXX need generation number?
    968 	 */
    969 
    970 	genfs_node_init(vp, &cd9660_genfsops);
    971 	*vpp = vp;
    972 	return (0);
    973 }
    974 
    975 /*
    976  * Vnode pointer to File handle
    977  */
    978 /* ARGSUSED */
    979 int
    980 cd9660_vptofh(vp, fhp)
    981 	struct vnode *vp;
    982 	struct fid *fhp;
    983 {
    984 	struct iso_node *ip = VTOI(vp);
    985 	struct ifid *ifhp;
    986 
    987 	ifhp = (struct ifid *)fhp;
    988 	ifhp->ifid_len = sizeof(struct ifid);
    989 
    990 	ifhp->ifid_ino = ip->i_number;
    991 	ifhp->ifid_start = ip->iso_start;
    992 
    993 #ifdef	ISOFS_DBG
    994 	printf("vptofh: ino %d, start %ld\n",
    995 	    ifhp->ifid_ino,ifhp->ifid_start);
    996 #endif
    997 	return 0;
    998 }
    999 
   1000 int
   1001 cd9660_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
   1002 	int *name;
   1003 	u_int namelen;
   1004 	void *oldp;
   1005 	size_t *oldlenp;
   1006 	void *newp;
   1007 	size_t newlen;
   1008 	struct proc *p;
   1009 {
   1010 	return (EOPNOTSUPP);
   1011 }
   1012