Home | History | Annotate | Line # | Download | only in cd9660
cd9660_vfsops.c revision 1.7
      1 /*	$NetBSD: cd9660_vfsops.c,v 1.7 2003/06/29 18:43:23 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.7 2003/06/29 18:43:23 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 lwp *l, struct iso_args *argp));
    124 
    125 int
    126 cd9660_mountroot()
    127 {
    128 	struct mount *mp;
    129 	struct lwp *l = curlwp;	/* 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, l, &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, l);
    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, l)
    172 	struct mount *mp;
    173 	const char *path;
    174 	void *data;
    175 	struct nameidata *ndp;
    176 	struct lwp *l;
    177 {
    178 	struct vnode *devvp;
    179 	struct iso_args args;
    180 	struct proc *p;
    181 	int error;
    182 	struct iso_mnt *imp = NULL;
    183 
    184 	p = l->l_proc;
    185 	if (mp->mnt_flag & MNT_GETARGS) {
    186 		imp = VFSTOISOFS(mp);
    187 		if (imp == NULL)
    188 			return EIO;
    189 		args.fspec = NULL;
    190 		args.flags = imp->im_flags;
    191 		vfs_showexport(mp, &args.export, &imp->im_export);
    192 		return copyout(&args, data, sizeof(args));
    193 	}
    194 	error = copyin(data, &args, sizeof (struct iso_args));
    195 	if (error)
    196 		return (error);
    197 
    198 	if ((mp->mnt_flag & MNT_RDONLY) == 0)
    199 		return (EROFS);
    200 
    201 	/*
    202 	 * If updating, check whether changing from read-only to
    203 	 * read/write; if there is no device name, that's all we do.
    204 	 */
    205 	if (mp->mnt_flag & MNT_UPDATE) {
    206 		imp = VFSTOISOFS(mp);
    207 		if (args.fspec == 0)
    208 			return (vfs_export(mp, &imp->im_export, &args.export));
    209 	}
    210 	/*
    211 	 * Not an update, or updating the name: look up the name
    212 	 * and verify that it refers to a sensible block device.
    213 	 */
    214 	NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args.fspec, l);
    215 	if ((error = namei(ndp)) != 0)
    216 		return (error);
    217 	devvp = ndp->ni_vp;
    218 
    219 	if (devvp->v_type != VBLK) {
    220 		vrele(devvp);
    221 		return ENOTBLK;
    222 	}
    223 	if (bdevsw_lookup(devvp->v_rdev) == NULL) {
    224 		vrele(devvp);
    225 		return ENXIO;
    226 	}
    227 	/*
    228 	 * If mount by non-root, then verify that user has necessary
    229 	 * permissions on the device.
    230 	 */
    231 	if (p->p_ucred->cr_uid != 0) {
    232 		vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
    233 		error = VOP_ACCESS(devvp, VREAD, p->p_ucred, l);
    234 		VOP_UNLOCK(devvp, 0);
    235 		if (error) {
    236 			vrele(devvp);
    237 			return (error);
    238 		}
    239 	}
    240 	if ((mp->mnt_flag & MNT_UPDATE) == 0)
    241 		error = iso_mountfs(devvp, mp, l, &args);
    242 	else {
    243 		if (devvp != imp->im_devvp)
    244 			error = EINVAL;	/* needs translation */
    245 		else
    246 			vrele(devvp);
    247 	}
    248 	if (error) {
    249 		vrele(devvp);
    250 		return error;
    251 	}
    252 	imp = VFSTOISOFS(mp);
    253 	return set_statfs_info(path, UIO_USERSPACE, args.fspec, UIO_USERSPACE,
    254 	    mp, l);
    255 }
    256 
    257 /*
    258  * Make a mount point from a volume descriptor
    259  */
    260 static int
    261 iso_makemp(isomp, bp, ea_len)
    262 	struct iso_mnt *isomp;
    263 	struct buf *bp;
    264 	int *ea_len;
    265 {
    266 	struct iso_primary_descriptor *pri;
    267 	int logical_block_size;
    268 	struct iso_directory_record *rootp;
    269 
    270 	pri = (struct iso_primary_descriptor *)bp->b_data;
    271 
    272 	logical_block_size = isonum_723 (pri->logical_block_size);
    273 
    274 	if (logical_block_size < DEV_BSIZE || logical_block_size > MAXBSIZE
    275 	    || (logical_block_size & (logical_block_size - 1)) != 0)
    276 		return -1;
    277 
    278 	rootp = (struct iso_directory_record *)pri->root_directory_record;
    279 
    280 	isomp->logical_block_size = logical_block_size;
    281 	isomp->volume_space_size = isonum_733 (pri->volume_space_size);
    282 	memcpy(isomp->root, rootp, sizeof(isomp->root));
    283 	isomp->root_extent = isonum_733 (rootp->extent);
    284 	isomp->root_size = isonum_733 (rootp->size);
    285 	isomp->im_joliet_level = 0;
    286 
    287 	isomp->im_bmask = logical_block_size - 1;
    288 	isomp->im_bshift = 0;
    289 	while ((1 << isomp->im_bshift) < isomp->logical_block_size)
    290 		isomp->im_bshift++;
    291 
    292 	if (ea_len != NULL)
    293 		*ea_len = isonum_711(rootp->ext_attr_length);
    294 
    295 	return 0;
    296 }
    297 
    298 /*
    299  * Common code for mount and mountroot
    300  */
    301 static int
    302 iso_mountfs(devvp, mp, l, argp)
    303 	struct vnode *devvp;
    304 	struct mount *mp;
    305 	struct lwp *l;
    306 	struct iso_args *argp;
    307 {
    308 	struct iso_mnt *isomp = (struct iso_mnt *)0;
    309 	struct buf *bp = NULL, *pribp = NULL, *supbp = NULL;
    310 	dev_t dev = devvp->v_rdev;
    311 	int error = EINVAL;
    312 	int needclose = 0;
    313 	int ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
    314 	int iso_bsize;
    315 	int iso_blknum;
    316 	int joliet_level;
    317 	struct iso_volume_descriptor *vdp;
    318 	struct iso_supplementary_descriptor *sup;
    319 	int sess = 0;
    320 	int ext_attr_length;
    321 	struct disklabel label;
    322 
    323 	if (!ronly)
    324 		return EROFS;
    325 
    326 	/*
    327 	 * Disallow multiple mounts of the same device.
    328 	 * Disallow mounting of a device that is currently in use
    329 	 * (except for root, which might share swap device for miniroot).
    330 	 * Flush out any old buffers remaining from a previous use.
    331 	 */
    332 	if ((error = vfs_mountedon(devvp)) != 0)
    333 		return error;
    334 	if (vcount(devvp) > 1 && devvp != rootvp)
    335 		return EBUSY;
    336 	if ((error = vinvalbuf(devvp, V_SAVE, l->l_proc->p_ucred, l, 0, 0)) != 0)
    337 		return (error);
    338 
    339 	error = VOP_OPEN(devvp, ronly ? FREAD : FREAD|FWRITE, FSCRED, l);
    340 	if (error)
    341 		return error;
    342 	needclose = 1;
    343 
    344 	/* This is the "logical sector size".  The standard says this
    345 	 * should be 2048 or the physical sector size on the device,
    346 	 * whichever is greater.  For now, we'll just use a constant.
    347 	 */
    348 	iso_bsize = ISO_DEFAULT_BLOCK_SIZE;
    349 
    350 	error = VOP_IOCTL(devvp, DIOCGDINFO, &label, FREAD, FSCRED, l);
    351 	if (!error &&
    352 	    label.d_partitions[DISKPART(dev)].p_fstype == FS_ISO9660) {
    353 		/* XXX more sanity checks? */
    354 		sess = label.d_partitions[DISKPART(dev)].p_cdsession;
    355 	} else {
    356 		/* fallback to old method */
    357 		error = VOP_IOCTL(devvp, CDIOREADMSADDR, &sess, 0, FSCRED, l);
    358 		if (error)
    359 			sess = 0;	/* never mind */
    360 	}
    361 #ifdef ISO_DEBUG
    362 	printf("isofs: session offset (part %d) %d\n", DISKPART(dev), sess);
    363 #endif
    364 
    365 	for (iso_blknum = 16; iso_blknum < 100; iso_blknum++) {
    366 		if ((error = bread(devvp, (iso_blknum+sess) * btodb(iso_bsize),
    367 				   iso_bsize, NOCRED, &bp)) != 0)
    368 			goto out;
    369 
    370 		vdp = (struct iso_volume_descriptor *)bp->b_data;
    371 		if (memcmp(vdp->id, ISO_STANDARD_ID, sizeof(vdp->id)) != 0) {
    372 			error = EINVAL;
    373 			goto out;
    374 		}
    375 
    376 		switch (isonum_711(vdp->type)) {
    377 		case ISO_VD_PRIMARY:
    378 			if (pribp == NULL) {
    379 				pribp = bp;
    380 				bp = NULL;
    381 			}
    382 			break;
    383 
    384 		case ISO_VD_SUPPLEMENTARY:
    385 			if (supbp == NULL) {
    386 				supbp = bp;
    387 				bp = NULL;
    388 			}
    389 			break;
    390 
    391 		default:
    392 			break;
    393 		}
    394 
    395 		if (isonum_711 (vdp->type) == ISO_VD_END) {
    396 			brelse(bp);
    397 			bp = NULL;
    398 			break;
    399 		}
    400 
    401 		if (bp != NULL) {
    402 			brelse(bp);
    403 			bp = NULL;
    404 		}
    405 	}
    406 
    407 	if (pribp == NULL) {
    408 		error = EINVAL;
    409 		goto out;
    410 	}
    411 
    412 	isomp = malloc(sizeof *isomp, M_ISOFSMNT, M_WAITOK);
    413 	memset(isomp, 0, sizeof *isomp);
    414 	if (iso_makemp(isomp, pribp, &ext_attr_length) == -1) {
    415 		error = EINVAL;
    416 		goto out;
    417 	}
    418 
    419 	isomp->volume_space_size += sess;
    420 
    421 	pribp->b_flags |= B_AGE;
    422 	brelse(pribp);
    423 	pribp = NULL;
    424 
    425 	mp->mnt_data = isomp;
    426 	mp->mnt_stat.f_fsid.val[0] = (long)dev;
    427 	mp->mnt_stat.f_fsid.val[1] = makefstype(MOUNT_CD9660);
    428 	mp->mnt_maxsymlinklen = 0;
    429 	mp->mnt_flag |= MNT_LOCAL;
    430 	mp->mnt_dev_bshift = iso_bsize;
    431 	mp->mnt_fs_bshift = isomp->im_bshift;
    432 	isomp->im_mountp = mp;
    433 	isomp->im_dev = dev;
    434 	isomp->im_devvp = devvp;
    435 
    436 	devvp->v_specmountpoint = mp;
    437 
    438 	/* Check the Rock Ridge Extension support */
    439 	if (!(argp->flags & ISOFSMNT_NORRIP)) {
    440 		struct iso_directory_record *rootp;
    441 
    442 		if ((error = bread(isomp->im_devvp,
    443 				   (isomp->root_extent + ext_attr_length) <<
    444 				   (isomp->im_bshift - DEV_BSHIFT),
    445 				   isomp->logical_block_size, NOCRED,
    446 				   &bp)) != 0)
    447 		    goto out;
    448 
    449 		rootp = (struct iso_directory_record *)bp->b_data;
    450 
    451 		if ((isomp->rr_skip = cd9660_rrip_offset(rootp,isomp)) < 0) {
    452 		    argp->flags  |= ISOFSMNT_NORRIP;
    453 		} else {
    454 		    argp->flags  &= ~ISOFSMNT_GENS;
    455 		}
    456 
    457 		/*
    458 		 * The contents are valid,
    459 		 * but they will get reread as part of another vnode, so...
    460 		 */
    461 		bp->b_flags |= B_AGE;
    462 		brelse(bp);
    463 		bp = NULL;
    464 	}
    465 	isomp->im_flags = argp->flags & (ISOFSMNT_NORRIP | ISOFSMNT_GENS |
    466 		 ISOFSMNT_EXTATT | ISOFSMNT_NOJOLIET | ISOFSMNT_RRCASEINS);
    467 
    468 	if (isomp->im_flags & ISOFSMNT_GENS)
    469 		isomp->iso_ftype = ISO_FTYPE_9660;
    470 	else if (isomp->im_flags & ISOFSMNT_NORRIP) {
    471 		isomp->iso_ftype = ISO_FTYPE_DEFAULT;
    472 		if (argp->flags & ISOFSMNT_NOCASETRANS)
    473 			isomp->im_flags |= ISOFSMNT_NOCASETRANS;
    474 	} else
    475 		isomp->iso_ftype = ISO_FTYPE_RRIP;
    476 
    477 	/* Check the Joliet Extension support */
    478 	if ((argp->flags & ISOFSMNT_NORRIP) != 0 &&
    479 	    (argp->flags & ISOFSMNT_NOJOLIET) == 0 &&
    480 	    supbp != NULL) {
    481 		joliet_level = 0;
    482 		sup = (struct iso_supplementary_descriptor *)supbp->b_data;
    483 
    484 		if ((isonum_711(sup->flags) & 1) == 0) {
    485 			if (memcmp(sup->escape, "%/@", 3) == 0)
    486 				joliet_level = 1;
    487 			if (memcmp(sup->escape, "%/C", 3) == 0)
    488 				joliet_level = 2;
    489 			if (memcmp(sup->escape, "%/E", 3) == 0)
    490 				joliet_level = 3;
    491 		}
    492 		if (joliet_level != 0) {
    493 			if (iso_makemp(isomp, supbp, NULL) == -1) {
    494 				error = EINVAL;
    495 				goto out;
    496 			}
    497 			isomp->im_joliet_level = joliet_level;
    498 		}
    499 	}
    500 
    501 	if (supbp != NULL) {
    502 		brelse(supbp);
    503 		supbp = NULL;
    504 	}
    505 
    506 	return 0;
    507 out:
    508 	if (bp)
    509 		brelse(bp);
    510 	if (pribp)
    511 		brelse(pribp);
    512 	if (supbp)
    513 		brelse(supbp);
    514 	if (needclose) {
    515 		vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
    516 		(void)VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED, l);
    517 		VOP_UNLOCK(devvp, 0);
    518 	}
    519 	if (isomp) {
    520 		free(isomp, M_ISOFSMNT);
    521 		mp->mnt_data = NULL;
    522 	}
    523 	return error;
    524 }
    525 
    526 /*
    527  * Make a filesystem operational.
    528  * Nothing to do at the moment.
    529  */
    530 /* ARGSUSED */
    531 int
    532 cd9660_start(mp, flags, l)
    533 	struct mount *mp;
    534 	int flags;
    535 	struct lwp *l;
    536 {
    537 	return 0;
    538 }
    539 
    540 /*
    541  * unmount system call
    542  */
    543 int
    544 cd9660_unmount(mp, mntflags, l)
    545 	struct mount *mp;
    546 	int mntflags;
    547 	struct lwp *l;
    548 {
    549 	struct iso_mnt *isomp;
    550 	int error, flags = 0;
    551 
    552 	if (mntflags & MNT_FORCE)
    553 		flags |= FORCECLOSE;
    554 #if 0
    555 	mntflushbuf(mp, 0);
    556 	if (mntinvalbuf(mp))
    557 		return EBUSY;
    558 #endif
    559 	if ((error = vflush(mp, NULLVP, flags)) != 0)
    560 		return (error);
    561 
    562 	isomp = VFSTOISOFS(mp);
    563 
    564 #ifdef	ISODEVMAP
    565 	if (isomp->iso_ftype == ISO_FTYPE_RRIP)
    566 		iso_dunmap(isomp->im_dev);
    567 #endif
    568 
    569 	if (isomp->im_devvp->v_type != VBAD)
    570 		isomp->im_devvp->v_specmountpoint = NULL;
    571 
    572 	vn_lock(isomp->im_devvp, LK_EXCLUSIVE | LK_RETRY);
    573 	error = VOP_CLOSE(isomp->im_devvp, FREAD, NOCRED, l);
    574 	vput(isomp->im_devvp);
    575 	free(isomp, M_ISOFSMNT);
    576 	mp->mnt_data = NULL;
    577 	mp->mnt_flag &= ~MNT_LOCAL;
    578 	return (error);
    579 }
    580 
    581 /*
    582  * Return root of a filesystem
    583  */
    584 int
    585 cd9660_root(mp, vpp)
    586 	struct mount *mp;
    587 	struct vnode **vpp;
    588 {
    589 	struct iso_mnt *imp = VFSTOISOFS(mp);
    590 	struct iso_directory_record *dp =
    591 	    (struct iso_directory_record *)imp->root;
    592 	ino_t ino = isodirino(dp, imp);
    593 
    594 	/*
    595 	 * With RRIP we must use the `.' entry of the root directory.
    596 	 * Simply tell vget, that it's a relocated directory.
    597 	 */
    598 	return (cd9660_vget_internal(mp, ino, vpp,
    599 				     imp->iso_ftype == ISO_FTYPE_RRIP, dp));
    600 }
    601 
    602 /*
    603  * Do operations associated with quotas, not supported
    604  */
    605 /* ARGSUSED */
    606 int
    607 cd9660_quotactl(mp, cmd, uid, arg, l)
    608 	struct mount *mp;
    609 	int cmd;
    610 	uid_t uid;
    611 	caddr_t arg;
    612 	struct lwp *l;
    613 {
    614 
    615 	return (EOPNOTSUPP);
    616 }
    617 
    618 /*
    619  * Get file system statistics.
    620  */
    621 int
    622 cd9660_statfs(mp, sbp, l)
    623 	struct mount *mp;
    624 	struct statfs *sbp;
    625 	struct lwp *l;
    626 {
    627 	struct iso_mnt *isomp;
    628 
    629 	isomp = VFSTOISOFS(mp);
    630 
    631 #ifdef COMPAT_09
    632 	sbp->f_type = 5;
    633 #else
    634 	sbp->f_type = 0;
    635 #endif
    636 	sbp->f_bsize = isomp->logical_block_size;
    637 	sbp->f_iosize = sbp->f_bsize;	/* XXX */
    638 	sbp->f_blocks = isomp->volume_space_size;
    639 	sbp->f_bfree = 0; /* total free blocks */
    640 	sbp->f_bavail = 0; /* blocks free for non superuser */
    641 	sbp->f_files =  0; /* total files */
    642 	sbp->f_ffree = 0; /* free file nodes */
    643 	copy_statfs_info(sbp, mp);
    644 	/* Use the first spare for flags: */
    645 	sbp->f_spare[0] = isomp->im_flags;
    646 	return 0;
    647 }
    648 
    649 /* ARGSUSED */
    650 int
    651 cd9660_sync(mp, waitfor, cred, l)
    652 	struct mount *mp;
    653 	int waitfor;
    654 	struct ucred *cred;
    655 	struct lwp *l;
    656 {
    657 	return (0);
    658 }
    659 
    660 /*
    661  * File handle to vnode
    662  *
    663  * Have to be really careful about stale file handles:
    664  * - check that the inode number is in range
    665  * - call iget() to get the locked inode
    666  * - check for an unallocated inode (i_mode == 0)
    667  * - check that the generation number matches
    668  */
    669 
    670 struct ifid {
    671 	ushort	ifid_len;
    672 	ushort	ifid_pad;
    673 	int	ifid_ino;
    674 	long	ifid_start;
    675 };
    676 
    677 /* ARGSUSED */
    678 int
    679 cd9660_fhtovp(mp, fhp, vpp)
    680 	struct mount *mp;
    681 	struct fid *fhp;
    682 	struct vnode **vpp;
    683 {
    684 	struct ifid *ifhp = (struct ifid *)fhp;
    685 	struct iso_node *ip;
    686 	struct vnode *nvp;
    687 	int error;
    688 
    689 #ifdef	ISOFS_DBG
    690 	printf("fhtovp: ino %d, start %ld\n",
    691 	    ifhp->ifid_ino, ifhp->ifid_start);
    692 #endif
    693 
    694 	if ((error = VFS_VGET(mp, ifhp->ifid_ino, &nvp)) != 0) {
    695 		*vpp = NULLVP;
    696 		return (error);
    697 	}
    698 	ip = VTOI(nvp);
    699 	if (ip->inode.iso_mode == 0) {
    700 		vput(nvp);
    701 		*vpp = NULLVP;
    702 		return (ESTALE);
    703 	}
    704 	*vpp = nvp;
    705 	return (0);
    706 }
    707 
    708 /* ARGSUSED */
    709 int
    710 cd9660_check_export(mp, nam, exflagsp, credanonp)
    711 	struct mount *mp;
    712 	struct mbuf *nam;
    713 	int *exflagsp;
    714 	struct ucred **credanonp;
    715 {
    716 	struct netcred *np;
    717 	struct iso_mnt *imp = VFSTOISOFS(mp);
    718 
    719 #ifdef	ISOFS_DBG
    720 	printf("check_export: ino %d, start %ld\n",
    721 	    ifhp->ifid_ino, ifhp->ifid_start);
    722 #endif
    723 
    724 	/*
    725 	 * Get the export permission structure for this <mp, client> tuple.
    726 	 */
    727 	np = vfs_export_lookup(mp, &imp->im_export, nam);
    728 	if (np == NULL)
    729 		return (EACCES);
    730 
    731 	*exflagsp = np->netc_exflags;
    732 	*credanonp = &np->netc_anon;
    733 	return (0);
    734 }
    735 
    736 int
    737 cd9660_vget(mp, ino, vpp)
    738 	struct mount *mp;
    739 	ino_t ino;
    740 	struct vnode **vpp;
    741 {
    742 
    743 	/*
    744 	 * XXXX
    745 	 * It would be nice if we didn't always set the `relocated' flag
    746 	 * and force the extra read, but I don't want to think about fixing
    747 	 * that right now.
    748 	 */
    749 	return (cd9660_vget_internal(mp, ino, vpp,
    750 #if 0
    751 				     VFSTOISOFS(mp)->iso_ftype == ISO_FTYPE_RRIP,
    752 #else
    753 				     0,
    754 #endif
    755 				     NULL));
    756 }
    757 
    758 int
    759 cd9660_vget_internal(mp, ino, vpp, relocated, isodir)
    760 	struct mount *mp;
    761 	ino_t ino;
    762 	struct vnode **vpp;
    763 	int relocated;
    764 	struct iso_directory_record *isodir;
    765 {
    766 	struct iso_mnt *imp;
    767 	struct iso_node *ip;
    768 #ifdef ISODEVMAP
    769 	struct iso_dnode *dp;
    770 #endif
    771 	struct buf *bp;
    772 	struct vnode *vp, *nvp;
    773 	dev_t dev;
    774 	int error;
    775 
    776 	imp = VFSTOISOFS(mp);
    777 	dev = imp->im_dev;
    778 	if ((*vpp = cd9660_ihashget(dev, ino)) != NULLVP)
    779 		return (0);
    780 
    781 	/* Allocate a new vnode/iso_node. */
    782 	if ((error = getnewvnode(VT_ISOFS, mp, cd9660_vnodeop_p, &vp)) != 0) {
    783 		*vpp = NULLVP;
    784 		return (error);
    785 	}
    786 	ip = pool_get(&cd9660_node_pool, PR_WAITOK);
    787 	memset(ip, 0, sizeof(struct iso_node));
    788 	vp->v_data = ip;
    789 	ip->i_vnode = vp;
    790 	ip->i_dev = dev;
    791 	ip->i_number = ino;
    792 
    793 	/*
    794 	 * Put it onto its hash chain and lock it so that other requests for
    795 	 * this inode will block if they arrive while we are sleeping waiting
    796 	 * for old data structures to be purged or for the contents of the
    797 	 * disk portion of this inode to be read.
    798 	 */
    799 	cd9660_ihashins(ip);
    800 
    801 	if (isodir == 0) {
    802 		int lbn, off;
    803 
    804 		lbn = lblkno(imp, ino);
    805 		if (lbn >= imp->volume_space_size) {
    806 			vput(vp);
    807 			printf("fhtovp: lbn exceed volume space %d\n", lbn);
    808 			return (ESTALE);
    809 		}
    810 
    811 		off = blkoff(imp, ino);
    812 		if (off + ISO_DIRECTORY_RECORD_SIZE > imp->logical_block_size) {
    813 			vput(vp);
    814 			printf("fhtovp: crosses block boundary %d\n",
    815 			    off + ISO_DIRECTORY_RECORD_SIZE);
    816 			return (ESTALE);
    817 		}
    818 
    819 		error = bread(imp->im_devvp,
    820 			      lbn << (imp->im_bshift - DEV_BSHIFT),
    821 			      imp->logical_block_size, NOCRED, &bp);
    822 		if (error) {
    823 			vput(vp);
    824 			brelse(bp);
    825 			printf("fhtovp: bread error %d\n",error);
    826 			return (error);
    827 		}
    828 		isodir = (struct iso_directory_record *)(bp->b_data + off);
    829 
    830 		if (off + isonum_711(isodir->length) >
    831 		    imp->logical_block_size) {
    832 			vput(vp);
    833 			if (bp != 0)
    834 				brelse(bp);
    835 			printf("fhtovp: directory crosses block boundary %d[off=%d/len=%d]\n",
    836 			    off +isonum_711(isodir->length), off,
    837 			    isonum_711(isodir->length));
    838 			return (ESTALE);
    839 		}
    840 
    841 #if 0
    842 		if (isonum_733(isodir->extent) +
    843 		    isonum_711(isodir->ext_attr_length) != ifhp->ifid_start) {
    844 			if (bp != 0)
    845 				brelse(bp);
    846 			printf("fhtovp: file start miss %d vs %d\n",
    847 			    isonum_733(isodir->extent) + isonum_711(isodir->ext_attr_length),
    848 			    ifhp->ifid_start);
    849 			return (ESTALE);
    850 		}
    851 #endif
    852 	} else
    853 		bp = 0;
    854 
    855 	ip->i_mnt = imp;
    856 	ip->i_devvp = imp->im_devvp;
    857 	VREF(ip->i_devvp);
    858 
    859 	if (relocated) {
    860 		/*
    861 		 * On relocated directories we must
    862 		 * read the `.' entry out of a dir.
    863 		 */
    864 		ip->iso_start = ino >> imp->im_bshift;
    865 		if (bp != 0)
    866 			brelse(bp);
    867 		if ((error = VOP_BLKATOFF(vp, (off_t)0, NULL, &bp)) != 0) {
    868 			vput(vp);
    869 			return (error);
    870 		}
    871 		isodir = (struct iso_directory_record *)bp->b_data;
    872 	}
    873 
    874 	ip->iso_extent = isonum_733(isodir->extent);
    875 	ip->i_size = isonum_733(isodir->size);
    876 	ip->iso_start = isonum_711(isodir->ext_attr_length) + ip->iso_extent;
    877 
    878 	/*
    879 	 * Setup time stamp, attribute
    880 	 */
    881 	vp->v_type = VNON;
    882 	switch (imp->iso_ftype) {
    883 	default:	/* ISO_FTYPE_9660 */
    884 	    {
    885 		struct buf *bp2;
    886 		int off;
    887 		if ((imp->im_flags & ISOFSMNT_EXTATT)
    888 		    && (off = isonum_711(isodir->ext_attr_length)))
    889 			VOP_BLKATOFF(vp, (off_t)-(off << imp->im_bshift), NULL,
    890 				     &bp2);
    891 		else
    892 			bp2 = NULL;
    893 		cd9660_defattr(isodir, ip, bp2);
    894 		cd9660_deftstamp(isodir, ip, bp2);
    895 		if (bp2)
    896 			brelse(bp2);
    897 		break;
    898 	    }
    899 	case ISO_FTYPE_RRIP:
    900 		cd9660_rrip_analyze(isodir, ip, imp);
    901 		break;
    902 	}
    903 
    904 	if (bp != 0)
    905 		brelse(bp);
    906 
    907 	/*
    908 	 * Initialize the associated vnode
    909 	 */
    910 	switch (vp->v_type = IFTOVT(ip->inode.iso_mode)) {
    911 	case VFIFO:
    912 		vp->v_op = cd9660_fifoop_p;
    913 		break;
    914 	case VCHR:
    915 	case VBLK:
    916 		/*
    917 		 * if device, look at device number table for translation
    918 		 */
    919 #ifdef	ISODEVMAP
    920 		if ((dp = iso_dmap(dev, ino, 0)) != NULL)
    921 			ip->inode.iso_rdev = dp->d_dev;
    922 #endif
    923 		vp->v_op = cd9660_specop_p;
    924 		if ((nvp = checkalias(vp, ip->inode.iso_rdev, mp)) != NULL) {
    925 			/*
    926 			 * Discard unneeded vnode, but save its iso_node.
    927 			 * Note that the lock is carried over in the iso_node
    928 			 * to the replacement vnode.
    929 			 */
    930 			nvp->v_data = vp->v_data;
    931 			vp->v_data = NULL;
    932 			VOP_UNLOCK(vp, 0);
    933 			vp->v_op = spec_vnodeop_p;
    934 			vrele(vp);
    935 			vgone(vp);
    936 			lockmgr(&nvp->v_lock, LK_EXCLUSIVE, &nvp->v_interlock);
    937 			/*
    938 			 * Reinitialize aliased inode.
    939 			 */
    940 			vp = nvp;
    941 			ip->i_vnode = vp;
    942 		}
    943 		break;
    944 	case VLNK:
    945 	case VNON:
    946 	case VSOCK:
    947 	case VDIR:
    948 	case VBAD:
    949 		break;
    950 	case VREG:
    951 		uvm_vnp_setsize(vp, ip->i_size);
    952 		break;
    953 	}
    954 
    955 	if (ip->iso_extent == imp->root_extent)
    956 		vp->v_flag |= VROOT;
    957 
    958 	/*
    959 	 * XXX need generation number?
    960 	 */
    961 
    962 	genfs_node_init(vp, &cd9660_genfsops);
    963 	*vpp = vp;
    964 	return (0);
    965 }
    966 
    967 /*
    968  * Vnode pointer to File handle
    969  */
    970 /* ARGSUSED */
    971 int
    972 cd9660_vptofh(vp, fhp)
    973 	struct vnode *vp;
    974 	struct fid *fhp;
    975 {
    976 	struct iso_node *ip = VTOI(vp);
    977 	struct ifid *ifhp;
    978 
    979 	ifhp = (struct ifid *)fhp;
    980 	ifhp->ifid_len = sizeof(struct ifid);
    981 
    982 	ifhp->ifid_ino = ip->i_number;
    983 	ifhp->ifid_start = ip->iso_start;
    984 
    985 #ifdef	ISOFS_DBG
    986 	printf("vptofh: ino %d, start %ld\n",
    987 	    ifhp->ifid_ino,ifhp->ifid_start);
    988 #endif
    989 	return 0;
    990 }
    991 
    992 int
    993 cd9660_sysctl(name, namelen, oldp, oldlenp, newp, newlen, l)
    994 	int *name;
    995 	u_int namelen;
    996 	void *oldp;
    997 	size_t *oldlenp;
    998 	void *newp;
    999 	size_t newlen;
   1000 	struct lwp *l;
   1001 {
   1002 	return (EOPNOTSUPP);
   1003 }
   1004