xref: /onnv-gate/usr/src/uts/common/fs/hsfs/hsfs_vfsops.c (revision 2904:6c8662f98a22)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51025Sfrankho  * Common Development and Distribution License (the "License").
61025Sfrankho  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
221488Srsb  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate  * VFS operations for High Sierra filesystem
300Sstevel@tonic-gate  */
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <sys/types.h>
330Sstevel@tonic-gate #include <sys/isa_defs.h>
340Sstevel@tonic-gate #include <sys/t_lock.h>
350Sstevel@tonic-gate #include <sys/param.h>
360Sstevel@tonic-gate #include <sys/systm.h>
370Sstevel@tonic-gate #include <sys/sysmacros.h>
380Sstevel@tonic-gate #include <sys/kmem.h>
390Sstevel@tonic-gate #include <sys/signal.h>
400Sstevel@tonic-gate #include <sys/user.h>
410Sstevel@tonic-gate #include <sys/proc.h>
420Sstevel@tonic-gate #include <sys/disp.h>
430Sstevel@tonic-gate #include <sys/buf.h>
440Sstevel@tonic-gate #include <sys/pathname.h>
450Sstevel@tonic-gate #include <sys/vfs.h>
460Sstevel@tonic-gate #include <sys/vnode.h>
470Sstevel@tonic-gate #include <sys/file.h>
480Sstevel@tonic-gate #include <sys/uio.h>
490Sstevel@tonic-gate #include <sys/conf.h>
500Sstevel@tonic-gate #include <sys/policy.h>
510Sstevel@tonic-gate 
520Sstevel@tonic-gate #include <vm/page.h>
530Sstevel@tonic-gate 
540Sstevel@tonic-gate #include <sys/fs/snode.h>
550Sstevel@tonic-gate #include <sys/fs/hsfs_spec.h>
560Sstevel@tonic-gate #include <sys/fs/hsfs_isospec.h>
570Sstevel@tonic-gate #include <sys/fs/hsfs_node.h>
580Sstevel@tonic-gate #include <sys/fs/hsfs_impl.h>
590Sstevel@tonic-gate #include <sys/fs/hsfs_susp.h>
600Sstevel@tonic-gate #include <sys/fs/hsfs_rrip.h>
610Sstevel@tonic-gate 
620Sstevel@tonic-gate #include <sys/statvfs.h>
630Sstevel@tonic-gate #include <sys/mount.h>
640Sstevel@tonic-gate #include <sys/mntent.h>
650Sstevel@tonic-gate #include <sys/swap.h>
660Sstevel@tonic-gate #include <sys/errno.h>
670Sstevel@tonic-gate #include <sys/debug.h>
680Sstevel@tonic-gate #include "fs/fs_subr.h"
690Sstevel@tonic-gate #include <sys/cmn_err.h>
700Sstevel@tonic-gate #include <sys/bootconf.h>
710Sstevel@tonic-gate 
722900Sfrankho #include <sys/sdt.h>
732900Sfrankho 
740Sstevel@tonic-gate /*
750Sstevel@tonic-gate  * These are needed for the CDROMREADOFFSET Code
760Sstevel@tonic-gate  */
770Sstevel@tonic-gate #include <sys/cdio.h>
780Sstevel@tonic-gate #include <sys/sunddi.h>
790Sstevel@tonic-gate 
800Sstevel@tonic-gate #define	HSFS_CLKSET
810Sstevel@tonic-gate 
820Sstevel@tonic-gate #include <sys/modctl.h>
830Sstevel@tonic-gate 
840Sstevel@tonic-gate /*
850Sstevel@tonic-gate  * Options for mount.
860Sstevel@tonic-gate  */
870Sstevel@tonic-gate #define	HOPT_GLOBAL	MNTOPT_GLOBAL
880Sstevel@tonic-gate #define	HOPT_NOGLOBAL	MNTOPT_NOGLOBAL
890Sstevel@tonic-gate #define	HOPT_MAPLCASE	"maplcase"
900Sstevel@tonic-gate #define	HOPT_NOMAPLCASE	"nomaplcase"
910Sstevel@tonic-gate #define	HOPT_NOTRAILDOT	"notraildot"
920Sstevel@tonic-gate #define	HOPT_TRAILDOT	"traildot"
930Sstevel@tonic-gate #define	HOPT_NRR	"nrr"
940Sstevel@tonic-gate #define	HOPT_RR		"rr"
952900Sfrankho #define	HOPT_JOLIET	"joliet"
962900Sfrankho #define	HOPT_NOJOLIET	"nojoliet"
972900Sfrankho #define	HOPT_JOLIETLONG	"jolietlong"
982900Sfrankho #define	HOPT_VERS2	"vers2"
992900Sfrankho #define	HOPT_NOVERS2	"novers2"
1000Sstevel@tonic-gate #define	HOPT_RO		MNTOPT_RO
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate static char *global_cancel[] = { HOPT_NOGLOBAL, NULL };
1030Sstevel@tonic-gate static char *noglobal_cancel[] = { HOPT_GLOBAL, NULL };
1040Sstevel@tonic-gate static char *mapl_cancel[] = { HOPT_NOMAPLCASE, NULL };
1050Sstevel@tonic-gate static char *nomapl_cancel[] = { HOPT_MAPLCASE, NULL };
1060Sstevel@tonic-gate static char *ro_cancel[] = { MNTOPT_RW, NULL };
1070Sstevel@tonic-gate static char *rr_cancel[] = { HOPT_NRR, NULL };
1080Sstevel@tonic-gate static char *nrr_cancel[] = { HOPT_RR, NULL };
1092900Sfrankho static char *joliet_cancel[] = { HOPT_NOJOLIET, NULL };
1102900Sfrankho static char *nojoliet_cancel[] = { HOPT_JOLIET, NULL };
1112900Sfrankho static char *vers2_cancel[] = { HOPT_NOVERS2, NULL };
1122900Sfrankho static char *novers2_cancel[] = { HOPT_VERS2, NULL };
1130Sstevel@tonic-gate static char *trail_cancel[] = { HOPT_NOTRAILDOT, NULL };
1140Sstevel@tonic-gate static char *notrail_cancel[] = { HOPT_TRAILDOT, NULL };
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate static mntopt_t hsfs_options[] = {
1170Sstevel@tonic-gate 	{ HOPT_GLOBAL, global_cancel, NULL, 0, NULL },
1180Sstevel@tonic-gate 	{ HOPT_NOGLOBAL, noglobal_cancel, NULL, MO_DEFAULT, NULL },
1190Sstevel@tonic-gate 	{ HOPT_MAPLCASE, mapl_cancel, NULL, MO_DEFAULT, NULL },
1200Sstevel@tonic-gate 	{ HOPT_NOMAPLCASE, nomapl_cancel, NULL, 0, NULL },
1210Sstevel@tonic-gate 	{ HOPT_RO, ro_cancel, NULL, MO_DEFAULT, NULL },
1220Sstevel@tonic-gate 	{ HOPT_RR, rr_cancel, NULL, MO_DEFAULT, NULL },
1230Sstevel@tonic-gate 	{ HOPT_NRR, nrr_cancel, NULL, 0, NULL },
1242900Sfrankho 	{ HOPT_JOLIET, joliet_cancel, NULL, 0, NULL },
1252900Sfrankho 	{ HOPT_NOJOLIET, nojoliet_cancel, NULL, 0, NULL },
1262900Sfrankho 	{ HOPT_JOLIETLONG, NULL, NULL, 0, NULL },
1272900Sfrankho 	{ HOPT_VERS2, vers2_cancel, NULL, 0, NULL },
1282900Sfrankho 	{ HOPT_NOVERS2, novers2_cancel, NULL, 0, NULL },
1290Sstevel@tonic-gate 	{ HOPT_TRAILDOT, trail_cancel, NULL, MO_DEFAULT, NULL },
1300Sstevel@tonic-gate 	{ HOPT_NOTRAILDOT, notrail_cancel, NULL, 0, NULL },
1312900Sfrankho 	{ "sector", NULL, "0", MO_HASVALUE, NULL},
1320Sstevel@tonic-gate };
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate static mntopts_t hsfs_proto_opttbl = {
1350Sstevel@tonic-gate 	sizeof (hsfs_options) / sizeof (mntopt_t),
1360Sstevel@tonic-gate 	hsfs_options
1370Sstevel@tonic-gate };
1380Sstevel@tonic-gate 
1392900Sfrankho static int hsfsfstype;
1400Sstevel@tonic-gate static int hsfsinit(int, char *);
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate static vfsdef_t vfw = {
1430Sstevel@tonic-gate 	VFSDEF_VERSION,
1440Sstevel@tonic-gate 	"hsfs",
1450Sstevel@tonic-gate 	hsfsinit,
1461488Srsb 	VSW_HASPROTO|VSW_STATS,	/* We don't suppport remounting */
1470Sstevel@tonic-gate 	&hsfs_proto_opttbl
1480Sstevel@tonic-gate };
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate static struct modlfs modlfs = {
1510Sstevel@tonic-gate 	&mod_fsops, "filesystem for HSFS", &vfw
1520Sstevel@tonic-gate };
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate static struct modlinkage modlinkage = {
1550Sstevel@tonic-gate 	MODREV_1, (void *)&modlfs, NULL
1560Sstevel@tonic-gate };
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate char _depends_on[] = "fs/specfs";
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate int
1612900Sfrankho _init(void)
1620Sstevel@tonic-gate {
1630Sstevel@tonic-gate 	return (mod_install(&modlinkage));
1640Sstevel@tonic-gate }
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate int
1672900Sfrankho _fini(void)
1680Sstevel@tonic-gate {
1692900Sfrankho 	int	error;
1702900Sfrankho 
1712900Sfrankho 	error = mod_remove(&modlinkage);
1722900Sfrankho 
1732900Sfrankho 	DTRACE_PROBE1(mod_remove, int, error);
1742900Sfrankho 
1752900Sfrankho 	if (error)
1762900Sfrankho 		return (error);
1772900Sfrankho 
1782900Sfrankho 	mutex_destroy(&hs_mounttab_lock);
1792900Sfrankho 
1802900Sfrankho 	/*
1812900Sfrankho 	 * Tear down the operations vectors
1822900Sfrankho 	 */
1832900Sfrankho 	(void) vfs_freevfsops_by_type(hsfsfstype);
1842900Sfrankho 	vn_freevnodeops(hsfs_vnodeops);
1852900Sfrankho 
1862900Sfrankho 	hs_fini_hsnode_cache();
1872900Sfrankho 	return (0);
1880Sstevel@tonic-gate }
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate int
1910Sstevel@tonic-gate _info(struct modinfo *modinfop)
1920Sstevel@tonic-gate {
1930Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
1940Sstevel@tonic-gate }
1950Sstevel@tonic-gate 
1960Sstevel@tonic-gate #define	BDEVFLAG(dev)	((devopsp[getmajor(dev)])->devo_cb_ops->cb_flag)
1970Sstevel@tonic-gate 
1980Sstevel@tonic-gate kmutex_t hs_mounttab_lock;
1990Sstevel@tonic-gate struct hsfs *hs_mounttab = NULL;
2000Sstevel@tonic-gate 
2010Sstevel@tonic-gate /* default mode, uid, gid */
2020Sstevel@tonic-gate mode_t hsfs_default_mode = 0555;
2030Sstevel@tonic-gate uid_t hsfs_default_uid = 0;
2040Sstevel@tonic-gate gid_t hsfs_default_gid = 3;
2050Sstevel@tonic-gate 
2060Sstevel@tonic-gate static int hsfs_mount(struct vfs *vfsp, struct vnode *mvp,
2070Sstevel@tonic-gate 	struct mounta *uap, struct cred *cr);
2080Sstevel@tonic-gate static int hsfs_unmount(struct vfs *vfsp, int, struct cred *cr);
2090Sstevel@tonic-gate static int hsfs_root(struct vfs *vfsp, struct vnode **vpp);
2100Sstevel@tonic-gate static int hsfs_statvfs(struct vfs *vfsp, struct statvfs64 *sbp);
2110Sstevel@tonic-gate static int hsfs_vget(struct vfs *vfsp, struct vnode **vpp, struct fid *fidp);
2120Sstevel@tonic-gate static int hsfs_mountroot(struct vfs *, enum whymountroot);
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate static int hs_mountfs(struct vfs *vfsp, dev_t dev, char *path,
2150Sstevel@tonic-gate 	mode_t mode, int flags, struct cred *cr, int isroot);
2162900Sfrankho static int hs_getrootvp(struct vfs *vfsp, struct hsfs *fsp, size_t pathsize);
2170Sstevel@tonic-gate static int hs_findhsvol(struct hsfs *fsp, struct vnode *vp,
2180Sstevel@tonic-gate 	struct hs_volume *hvp);
2190Sstevel@tonic-gate static int hs_parsehsvol(struct hsfs *fsp, uchar_t *volp,
2200Sstevel@tonic-gate 	struct hs_volume *hvp);
2210Sstevel@tonic-gate static int hs_findisovol(struct hsfs *fsp, struct vnode *vp,
2222900Sfrankho 	struct hs_volume *hvp,
2232900Sfrankho 	struct hs_volume *svp,
2242900Sfrankho 	struct hs_volume *jvp);
2252900Sfrankho static int hs_joliet_level(uchar_t *volp);
2260Sstevel@tonic-gate static int hs_parseisovol(struct hsfs *fsp, uchar_t *volp,
2270Sstevel@tonic-gate 	struct hs_volume *hvp);
2282900Sfrankho static void hs_copylabel(struct hs_volume *, unsigned char *, int);
2290Sstevel@tonic-gate static int hs_getmdev(struct vfs *, char *fspec, int flags, dev_t *pdev,
2300Sstevel@tonic-gate 	mode_t *mode, cred_t *cr);
2310Sstevel@tonic-gate static int hs_findvoldesc(dev_t rdev, int desc_sec);
2320Sstevel@tonic-gate 
2330Sstevel@tonic-gate static int
2340Sstevel@tonic-gate hsfsinit(int fstype, char *name)
2350Sstevel@tonic-gate {
2360Sstevel@tonic-gate 	static const fs_operation_def_t hsfs_vfsops_template[] = {
2370Sstevel@tonic-gate 		VFSNAME_MOUNT, hsfs_mount,
2380Sstevel@tonic-gate 		VFSNAME_UNMOUNT, hsfs_unmount,
2390Sstevel@tonic-gate 		VFSNAME_ROOT, hsfs_root,
2400Sstevel@tonic-gate 		VFSNAME_STATVFS, hsfs_statvfs,
2410Sstevel@tonic-gate 		VFSNAME_VGET, hsfs_vget,
2420Sstevel@tonic-gate 		VFSNAME_MOUNTROOT, hsfs_mountroot,
2430Sstevel@tonic-gate 		NULL, NULL
2440Sstevel@tonic-gate 	};
2450Sstevel@tonic-gate 	int error;
2460Sstevel@tonic-gate 
2470Sstevel@tonic-gate 	error = vfs_setfsops(fstype, hsfs_vfsops_template, NULL);
2480Sstevel@tonic-gate 	if (error != 0) {
2490Sstevel@tonic-gate 		cmn_err(CE_WARN, "hsfsinit: bad vfs ops template");
2500Sstevel@tonic-gate 		return (error);
2510Sstevel@tonic-gate 	}
2520Sstevel@tonic-gate 
2530Sstevel@tonic-gate 	error = vn_make_ops(name, hsfs_vnodeops_template, &hsfs_vnodeops);
2540Sstevel@tonic-gate 	if (error != 0) {
2550Sstevel@tonic-gate 		(void) vfs_freevfsops_by_type(fstype);
2560Sstevel@tonic-gate 		cmn_err(CE_WARN, "hsfsinit: bad vnode ops template");
2570Sstevel@tonic-gate 		return (error);
2580Sstevel@tonic-gate 	}
2590Sstevel@tonic-gate 
2600Sstevel@tonic-gate 	hsfsfstype = fstype;
2610Sstevel@tonic-gate 	mutex_init(&hs_mounttab_lock, NULL, MUTEX_DEFAULT, NULL);
2620Sstevel@tonic-gate 	hs_init_hsnode_cache();
2630Sstevel@tonic-gate 	return (0);
2640Sstevel@tonic-gate }
2650Sstevel@tonic-gate 
2660Sstevel@tonic-gate /*ARGSUSED*/
2670Sstevel@tonic-gate static int
2680Sstevel@tonic-gate hsfs_mount(struct vfs *vfsp, struct vnode *mvp,
2690Sstevel@tonic-gate     struct mounta *uap, struct cred *cr)
2700Sstevel@tonic-gate {
2710Sstevel@tonic-gate 	int		vnode_busy;
2720Sstevel@tonic-gate 	dev_t		dev;
2730Sstevel@tonic-gate 	struct pathname dpn;
2740Sstevel@tonic-gate 	int		error;
2750Sstevel@tonic-gate 	mode_t		mode;
2760Sstevel@tonic-gate 	int		flags;	/* this will hold the mount specific data */
2770Sstevel@tonic-gate 
2780Sstevel@tonic-gate 	if ((error = secpolicy_fs_mount(cr, mvp, vfsp)) != 0)
2790Sstevel@tonic-gate 		return (error);
2800Sstevel@tonic-gate 
2810Sstevel@tonic-gate 	if (mvp->v_type != VDIR)
2820Sstevel@tonic-gate 		return (ENOTDIR);
2830Sstevel@tonic-gate 
2840Sstevel@tonic-gate 	/* mount option must be read only, else mount will be rejected */
2850Sstevel@tonic-gate 	if (!(uap->flags & MS_RDONLY))
2860Sstevel@tonic-gate 		return (EROFS);
2870Sstevel@tonic-gate 
2880Sstevel@tonic-gate 	/*
2890Sstevel@tonic-gate 	 * We already told the framework that we don't support remounting.
2900Sstevel@tonic-gate 	 */
2910Sstevel@tonic-gate 	ASSERT(!(uap->flags & MS_REMOUNT));
2920Sstevel@tonic-gate 
2930Sstevel@tonic-gate 	mutex_enter(&mvp->v_lock);
2940Sstevel@tonic-gate 	vnode_busy = (mvp->v_count != 1) || (mvp->v_flag & VROOT);
2950Sstevel@tonic-gate 	mutex_exit(&mvp->v_lock);
2960Sstevel@tonic-gate 
2970Sstevel@tonic-gate 	if ((uap->flags & MS_OVERLAY) == 0 && vnode_busy) {
2980Sstevel@tonic-gate 		return (EBUSY);
2990Sstevel@tonic-gate 	}
3000Sstevel@tonic-gate 
3010Sstevel@tonic-gate 	/*
3020Sstevel@tonic-gate 	 * Check for the options that actually affect things
3030Sstevel@tonic-gate 	 * at our level.
3040Sstevel@tonic-gate 	 */
3050Sstevel@tonic-gate 	flags = 0;
3060Sstevel@tonic-gate 	if (vfs_optionisset(vfsp, HOPT_NOMAPLCASE, NULL))
3070Sstevel@tonic-gate 	    flags |= HSFSMNT_NOMAPLCASE;
3080Sstevel@tonic-gate 	if (vfs_optionisset(vfsp, HOPT_NOTRAILDOT, NULL))
3090Sstevel@tonic-gate 	    flags |= HSFSMNT_NOTRAILDOT;
3100Sstevel@tonic-gate 	if (vfs_optionisset(vfsp, HOPT_NRR, NULL))
3110Sstevel@tonic-gate 	    flags |= HSFSMNT_NORRIP;
3122900Sfrankho 	if (vfs_optionisset(vfsp, HOPT_NOJOLIET, NULL))
3132900Sfrankho 	    flags |= HSFSMNT_NOJOLIET;
3142900Sfrankho 	if (vfs_optionisset(vfsp, HOPT_JOLIETLONG, NULL))
3152900Sfrankho 	    flags |= HSFSMNT_JOLIETLONG;
3162900Sfrankho 	if (vfs_optionisset(vfsp, HOPT_NOVERS2, NULL))
3172900Sfrankho 	    flags |= HSFSMNT_NOVERS2;
3180Sstevel@tonic-gate 
3190Sstevel@tonic-gate 	error = pn_get(uap->dir, (uap->flags & MS_SYSSPACE) ?
3200Sstevel@tonic-gate 	    UIO_SYSSPACE : UIO_USERSPACE, &dpn);
3210Sstevel@tonic-gate 	if (error)
3220Sstevel@tonic-gate 		return (error);
3230Sstevel@tonic-gate 
3240Sstevel@tonic-gate 	if ((error = hs_getmdev(vfsp, uap->spec, uap->flags, &dev,
3250Sstevel@tonic-gate 		&mode, cr)) != 0) {
3260Sstevel@tonic-gate 		pn_free(&dpn);
3270Sstevel@tonic-gate 		return (error);
3280Sstevel@tonic-gate 	}
3290Sstevel@tonic-gate 
3300Sstevel@tonic-gate 	/*
3310Sstevel@tonic-gate 	 * If the device is a tape, return error
3320Sstevel@tonic-gate 	 */
3330Sstevel@tonic-gate 	if ((BDEVFLAG(dev) & D_TAPE) == D_TAPE)  {
3340Sstevel@tonic-gate 		pn_free(&dpn);
3350Sstevel@tonic-gate 		return (ENOTBLK);
3360Sstevel@tonic-gate 	}
3370Sstevel@tonic-gate 
3380Sstevel@tonic-gate 	/*
3390Sstevel@tonic-gate 	 * Mount the filesystem.
3400Sstevel@tonic-gate 	 */
3410Sstevel@tonic-gate 	error = hs_mountfs(vfsp, dev, dpn.pn_path, mode, flags, cr, 0);
3420Sstevel@tonic-gate 	pn_free(&dpn);
3430Sstevel@tonic-gate 	return (error);
3440Sstevel@tonic-gate }
3450Sstevel@tonic-gate 
3460Sstevel@tonic-gate /*ARGSUSED*/
3470Sstevel@tonic-gate static int
3480Sstevel@tonic-gate hsfs_unmount(
3490Sstevel@tonic-gate 	struct vfs *vfsp,
3500Sstevel@tonic-gate 	int flag,
3510Sstevel@tonic-gate 	struct cred *cr)
3520Sstevel@tonic-gate {
3530Sstevel@tonic-gate 	struct hsfs **tspp;
3540Sstevel@tonic-gate 	struct hsfs *fsp;
3550Sstevel@tonic-gate 
3560Sstevel@tonic-gate 	if (secpolicy_fs_unmount(cr, vfsp) != 0)
3570Sstevel@tonic-gate 		return (EPERM);
3580Sstevel@tonic-gate 
3590Sstevel@tonic-gate 	/*
3600Sstevel@tonic-gate 	 * forced unmount is not supported by this file system
3610Sstevel@tonic-gate 	 * and thus, ENOTSUP is being returned.
3620Sstevel@tonic-gate 	 */
3630Sstevel@tonic-gate 	if (flag & MS_FORCE)
3640Sstevel@tonic-gate 		return (ENOTSUP);
3650Sstevel@tonic-gate 
3660Sstevel@tonic-gate 	fsp = VFS_TO_HSFS(vfsp);
3670Sstevel@tonic-gate 
3680Sstevel@tonic-gate 	if (fsp->hsfs_rootvp->v_count != 1)
3690Sstevel@tonic-gate 		return (EBUSY);
3700Sstevel@tonic-gate 
3710Sstevel@tonic-gate 	/* destroy all old pages and hsnodes for this vfs */
3720Sstevel@tonic-gate 	if (hs_synchash(vfsp))
3730Sstevel@tonic-gate 		return (EBUSY);
3740Sstevel@tonic-gate 
3750Sstevel@tonic-gate 	mutex_enter(&hs_mounttab_lock);
3760Sstevel@tonic-gate 	for (tspp = &hs_mounttab; *tspp != NULL; tspp = &(*tspp)->hsfs_next) {
3770Sstevel@tonic-gate 		if (*tspp == fsp)
3780Sstevel@tonic-gate 			break;
3790Sstevel@tonic-gate 	}
3800Sstevel@tonic-gate 	if (*tspp == NULL) {
3810Sstevel@tonic-gate 		mutex_exit(&hs_mounttab_lock);
3820Sstevel@tonic-gate 		panic("hsfs_unmount: vfs not mounted?");
3830Sstevel@tonic-gate 		/*NOTREACHED*/
3840Sstevel@tonic-gate 	}
3850Sstevel@tonic-gate 
3860Sstevel@tonic-gate 	*tspp = fsp->hsfs_next;
3870Sstevel@tonic-gate 
3880Sstevel@tonic-gate 	mutex_exit(&hs_mounttab_lock);
3890Sstevel@tonic-gate 
3900Sstevel@tonic-gate 	(void) VOP_CLOSE(fsp->hsfs_devvp, FREAD, 1, (offset_t)0, cr);
3910Sstevel@tonic-gate 	VN_RELE(fsp->hsfs_devvp);
3920Sstevel@tonic-gate 	/* free path table space */
3930Sstevel@tonic-gate 	if (fsp->hsfs_ptbl != NULL)
3940Sstevel@tonic-gate 		kmem_free(fsp->hsfs_ptbl,
3950Sstevel@tonic-gate 			(size_t)fsp->hsfs_vol.ptbl_len);
3960Sstevel@tonic-gate 	/* free path table index table */
3970Sstevel@tonic-gate 	if (fsp->hsfs_ptbl_idx != NULL)
3980Sstevel@tonic-gate 		kmem_free(fsp->hsfs_ptbl_idx, (size_t)
3990Sstevel@tonic-gate 			(fsp->hsfs_ptbl_idx_size * sizeof (struct ptable_idx)));
4000Sstevel@tonic-gate 
4010Sstevel@tonic-gate 	/* free "mounted on" pathame */
4020Sstevel@tonic-gate 	if (fsp->hsfs_fsmnt != NULL)
4030Sstevel@tonic-gate 		kmem_free(fsp->hsfs_fsmnt, strlen(fsp->hsfs_fsmnt) + 1);
4040Sstevel@tonic-gate 
4050Sstevel@tonic-gate 	mutex_destroy(&fsp->hsfs_free_lock);
4060Sstevel@tonic-gate 	rw_destroy(&fsp->hsfs_hash_lock);
4070Sstevel@tonic-gate 
4080Sstevel@tonic-gate 	kmem_free(fsp, sizeof (*fsp));
4090Sstevel@tonic-gate 	return (0);
4100Sstevel@tonic-gate }
4110Sstevel@tonic-gate 
4120Sstevel@tonic-gate /*ARGSUSED*/
4130Sstevel@tonic-gate static int
4140Sstevel@tonic-gate hsfs_root(struct vfs *vfsp, struct vnode **vpp)
4150Sstevel@tonic-gate {
4160Sstevel@tonic-gate 	*vpp = (VFS_TO_HSFS(vfsp))->hsfs_rootvp;
4170Sstevel@tonic-gate 	VN_HOLD(*vpp);
4180Sstevel@tonic-gate 	return (0);
4190Sstevel@tonic-gate }
4200Sstevel@tonic-gate 
4210Sstevel@tonic-gate /*ARGSUSED*/
4220Sstevel@tonic-gate static int
4230Sstevel@tonic-gate hsfs_statvfs(struct vfs *vfsp, struct statvfs64 *sbp)
4240Sstevel@tonic-gate {
4250Sstevel@tonic-gate 	struct hsfs *fsp;
4260Sstevel@tonic-gate 	dev32_t d32;
4270Sstevel@tonic-gate 
4280Sstevel@tonic-gate 	fsp = VFS_TO_HSFS(vfsp);
4290Sstevel@tonic-gate 	if (fsp->hsfs_magic != HSFS_MAGIC)
4300Sstevel@tonic-gate 		return (EINVAL);
4310Sstevel@tonic-gate 	bzero(sbp, sizeof (*sbp));
4320Sstevel@tonic-gate 	sbp->f_bsize = vfsp->vfs_bsize;
4330Sstevel@tonic-gate 	sbp->f_frsize = sbp->f_bsize; /* no fragment, same as block size */
4340Sstevel@tonic-gate 	sbp->f_blocks = (fsblkcnt64_t)fsp->hsfs_vol.vol_size;
4350Sstevel@tonic-gate 
4360Sstevel@tonic-gate 	sbp->f_bfree = (fsblkcnt64_t)0;
4370Sstevel@tonic-gate 	sbp->f_bavail = (fsblkcnt64_t)0;
4380Sstevel@tonic-gate 	sbp->f_files = (fsfilcnt64_t)-1;
4390Sstevel@tonic-gate 	sbp->f_ffree = (fsfilcnt64_t)0;
4400Sstevel@tonic-gate 	sbp->f_favail = (fsfilcnt64_t)0;
4410Sstevel@tonic-gate 	(void) cmpldev(&d32, vfsp->vfs_dev);
4420Sstevel@tonic-gate 	sbp->f_fsid = d32;
4430Sstevel@tonic-gate 	(void) strcpy(sbp->f_basetype, vfssw[vfsp->vfs_fstype].vsw_name);
4440Sstevel@tonic-gate 	sbp->f_flag = vf_to_stf(vfsp->vfs_flag);
4450Sstevel@tonic-gate 	sbp->f_namemax = fsp->hsfs_namemax;
4460Sstevel@tonic-gate 	(void) strcpy(sbp->f_fstr, fsp->hsfs_vol.vol_id);
4470Sstevel@tonic-gate 
4480Sstevel@tonic-gate 	return (0);
4490Sstevel@tonic-gate }
4500Sstevel@tonic-gate 
4510Sstevel@tonic-gate /*
4520Sstevel@tonic-gate  * Previously nodeid was declared as uint32_t. This has been changed
4530Sstevel@tonic-gate  * to conform better with the ISO9660 standard. The standard states that
4540Sstevel@tonic-gate  * a LBN can be a 32 bit number, as the MAKE_NODEID macro shifts this
4550Sstevel@tonic-gate  * LBN 11 places left (LBN_TO_BYTE) and then shifts the result 5 right
4560Sstevel@tonic-gate  * (divide by 32) we are left with the potential of an overflow if
4570Sstevel@tonic-gate  * confined to a 32 bit value.
4580Sstevel@tonic-gate  */
4590Sstevel@tonic-gate 
4600Sstevel@tonic-gate static int
4610Sstevel@tonic-gate hsfs_vget(struct vfs *vfsp, struct vnode **vpp, struct fid *fidp)
4620Sstevel@tonic-gate {
4630Sstevel@tonic-gate 	struct hsfid *fid;
4640Sstevel@tonic-gate 	struct hsfs *fsp;
4650Sstevel@tonic-gate 	ino64_t nodeid;
4660Sstevel@tonic-gate 	int error;
4670Sstevel@tonic-gate 
4680Sstevel@tonic-gate 	fsp = (struct hsfs *)VFS_TO_HSFS(vfsp);
4690Sstevel@tonic-gate 	fid = (struct hsfid *)fidp;
4700Sstevel@tonic-gate 
4710Sstevel@tonic-gate 	/*
4720Sstevel@tonic-gate 	 * Look for vnode on hashlist.
4730Sstevel@tonic-gate 	 * If found, it's now active and the refcnt was incremented.
4740Sstevel@tonic-gate 	 */
4750Sstevel@tonic-gate 
4760Sstevel@tonic-gate 	rw_enter(&fsp->hsfs_hash_lock, RW_READER);
4770Sstevel@tonic-gate 
4780Sstevel@tonic-gate 	nodeid = (ino64_t)MAKE_NODEID(fid->hf_dir_lbn, fid->hf_dir_off, vfsp);
4790Sstevel@tonic-gate 
4800Sstevel@tonic-gate 	if ((*vpp = hs_findhash(nodeid, vfsp)) == NULL) {
4810Sstevel@tonic-gate 		/*
4820Sstevel@tonic-gate 		 * Not in cache, so we need to remake it.
4830Sstevel@tonic-gate 		 * hs_remakenode() will read the directory entry
4840Sstevel@tonic-gate 		 * and then check again to see if anyone else has
4850Sstevel@tonic-gate 		 * put it in the cache.
4860Sstevel@tonic-gate 		 */
4870Sstevel@tonic-gate 		rw_exit(&fsp->hsfs_hash_lock);
4880Sstevel@tonic-gate 		error = hs_remakenode(fid->hf_dir_lbn, (uint_t)fid->hf_dir_off,
4890Sstevel@tonic-gate 		    vfsp, vpp);
4900Sstevel@tonic-gate 		return (error);
4910Sstevel@tonic-gate 	}
4920Sstevel@tonic-gate 	rw_exit(&fsp->hsfs_hash_lock);
4930Sstevel@tonic-gate 	return (0);
4940Sstevel@tonic-gate }
4950Sstevel@tonic-gate 
4960Sstevel@tonic-gate 
4970Sstevel@tonic-gate #define	CHECKSUM_SIZE				(64 * 1024)
4980Sstevel@tonic-gate 
4990Sstevel@tonic-gate /*
5000Sstevel@tonic-gate  * Compute a CD-ROM fsid by checksumming the first 64K of data on the CD
5010Sstevel@tonic-gate  * We use the 'fsp' argument to determine the location of the root
5020Sstevel@tonic-gate  * directory entry, and we start reading from there.
5030Sstevel@tonic-gate  */
5040Sstevel@tonic-gate static int
5050Sstevel@tonic-gate compute_cdrom_id(struct hsfs *fsp, vnode_t *devvp)
5060Sstevel@tonic-gate {
5070Sstevel@tonic-gate 	uint_t		secno;
5080Sstevel@tonic-gate 	struct hs_volume *hsvp = &fsp->hsfs_vol;
5090Sstevel@tonic-gate 	struct buf	*bp;
5100Sstevel@tonic-gate 	int		error;
5110Sstevel@tonic-gate 	int		fsid;
5120Sstevel@tonic-gate 
5130Sstevel@tonic-gate 	secno = hsvp->root_dir.ext_lbn >> hsvp->lbn_secshift;
514494Sfrankho 	bp = bread(devvp->v_rdev, secno * 4, CHECKSUM_SIZE);
5150Sstevel@tonic-gate 	error = geterror(bp);
516494Sfrankho 
517494Sfrankho 	/*
518494Sfrankho 	 * An error on read or a partial read means we asked
519494Sfrankho 	 * for a nonexistant/corrupted piece of the device
520494Sfrankho 	 * (including past-the-end of the media). Don't
521494Sfrankho 	 * try to use the checksumming method then.
522494Sfrankho 	 */
523494Sfrankho 	if (!error && bp->b_bcount == CHECKSUM_SIZE) {
5240Sstevel@tonic-gate 		int *ibuf = (int *)bp->b_un.b_addr;
5250Sstevel@tonic-gate 		int i;
5260Sstevel@tonic-gate 
5270Sstevel@tonic-gate 		fsid = 0;
5280Sstevel@tonic-gate 
529494Sfrankho 		for (i = 0; i < CHECKSUM_SIZE / sizeof (int); i++)
5300Sstevel@tonic-gate 			fsid ^= ibuf[ i ];
531494Sfrankho 	} else {
532494Sfrankho 		/*
533494Sfrankho 		 * Fallback - use creation date
534494Sfrankho 		 */
5350Sstevel@tonic-gate 		fsid = hsvp->cre_date.tv_sec;
536494Sfrankho 	}
5370Sstevel@tonic-gate 
5380Sstevel@tonic-gate 	brelse(bp);
5390Sstevel@tonic-gate 
5400Sstevel@tonic-gate 	return (fsid);
5410Sstevel@tonic-gate }
5420Sstevel@tonic-gate 
5430Sstevel@tonic-gate 
5440Sstevel@tonic-gate /*ARGSUSED*/
5450Sstevel@tonic-gate static int
5460Sstevel@tonic-gate hs_mountfs(
5470Sstevel@tonic-gate 	struct vfs	*vfsp,
5480Sstevel@tonic-gate 	dev_t		dev,
5490Sstevel@tonic-gate 	char		*path,
5500Sstevel@tonic-gate 	mode_t		mode,
5510Sstevel@tonic-gate 	int		mount_flags,
5520Sstevel@tonic-gate 	struct cred	*cr,
5530Sstevel@tonic-gate 	int		isroot)
5540Sstevel@tonic-gate {
5550Sstevel@tonic-gate 	struct vnode	*devvp;
5560Sstevel@tonic-gate 	struct hsfs	*tsp;
5570Sstevel@tonic-gate 	struct hsfs	*fsp = NULL;
5580Sstevel@tonic-gate 	struct vattr	vap;
5590Sstevel@tonic-gate 	struct hsnode	*hp;
5600Sstevel@tonic-gate 	int		error;
5610Sstevel@tonic-gate 	struct timeval	tv;
5620Sstevel@tonic-gate 	int		fsid;
5632900Sfrankho 	int		use_rrip;
5642900Sfrankho 	int		use_vers2;
5652900Sfrankho 	int		use_joliet;
5662900Sfrankho 	int		has_rrip = 0;
5672900Sfrankho 	int		has_vers2 = 0;
5682900Sfrankho 	int		has_joliet = 0;
5692900Sfrankho 	int		force_rrip_off;
5702900Sfrankho 	int		force_vers2_off;
5712900Sfrankho 	int		force_joliet_off;
5722900Sfrankho 	size_t		pathbufsz = strlen(path) + 1;
5732900Sfrankho 	int		redo_rootvp;
5742900Sfrankho 
5752900Sfrankho 	struct hs_volume *svp;		/* Supplemental VD for ISO-9660:1999 */
5762900Sfrankho 	struct hs_volume *jvp;		/* Joliet VD */
5772900Sfrankho 
5782900Sfrankho 	/*
5792900Sfrankho 	 * The rules for which extension will be used are:
5802900Sfrankho 	 * 1. No specific mount options given:
5812900Sfrankho 	 *	- use rrip if available
5822900Sfrankho 	 *	- use ISO9660:1999 if available
5832900Sfrankho 	 *	- use joliet if available.
5842900Sfrankho 	 * 2. rrip/ISO9660:1999/joliet explicitly disabled via mount option:
5852900Sfrankho 	 *	- use next "lower" extension
5862900Sfrankho 	 * 3. joliet/ISO9660:1999/rrip explicitly requested via mount option:
5872900Sfrankho 	 *	- disable rrip support even if available
5882900Sfrankho 	 *	- disable IOS9660:1999 support even if available
5892900Sfrankho 	 *
5902900Sfrankho 	 * We need to adjust these flags as we discover the extensions
5912900Sfrankho 	 * present. See below. These are just the starting values.
5922900Sfrankho 	 */
5932900Sfrankho 	use_rrip = (mount_flags & HSFSMNT_NORRIP) == 0;
5942900Sfrankho 	use_vers2 = (mount_flags & HSFSMNT_NOVERS2) == 0;
5952900Sfrankho 	use_joliet = (mount_flags & HSFSMNT_NOJOLIET) == 0;
5960Sstevel@tonic-gate 
5970Sstevel@tonic-gate 	/*
5980Sstevel@tonic-gate 	 * Open the device
5990Sstevel@tonic-gate 	 */
6000Sstevel@tonic-gate 	devvp = makespecvp(dev, VBLK);
6010Sstevel@tonic-gate 	ASSERT(devvp != 0);
6020Sstevel@tonic-gate 
6030Sstevel@tonic-gate 	/*
6040Sstevel@tonic-gate 	 * Open the target device (file) for read only.
6050Sstevel@tonic-gate 	 */
6060Sstevel@tonic-gate 	if (error = VOP_OPEN(&devvp, FREAD, cr)) {
6070Sstevel@tonic-gate 		VN_RELE(devvp);
6080Sstevel@tonic-gate 		return (error);
6090Sstevel@tonic-gate 	}
6100Sstevel@tonic-gate 
6110Sstevel@tonic-gate 	/*
6120Sstevel@tonic-gate 	 * Refuse to go any further if this
6130Sstevel@tonic-gate 	 * device is being used for swapping
6140Sstevel@tonic-gate 	 */
6150Sstevel@tonic-gate 	if (IS_SWAPVP(common_specvp(devvp))) {
6160Sstevel@tonic-gate 		error = EBUSY;
6170Sstevel@tonic-gate 		goto cleanup;
6180Sstevel@tonic-gate 	}
6190Sstevel@tonic-gate 
6200Sstevel@tonic-gate 	vap.va_mask = AT_SIZE;
6210Sstevel@tonic-gate 	if ((error = VOP_GETATTR(devvp, &vap, ATTR_COMM, cr)) != 0) {
6220Sstevel@tonic-gate 		cmn_err(CE_NOTE, "Cannot get attributes of the CD-ROM driver");
6230Sstevel@tonic-gate 		goto cleanup;
6240Sstevel@tonic-gate 	}
6250Sstevel@tonic-gate 
6260Sstevel@tonic-gate 	/*
6270Sstevel@tonic-gate 	 * Make sure we have a nonzero size partition.
6280Sstevel@tonic-gate 	 * The current version of the SD driver will *not* fail the open
6290Sstevel@tonic-gate 	 * of such a partition so we have to check for it here.
6300Sstevel@tonic-gate 	 */
6310Sstevel@tonic-gate 	if (vap.va_size == 0) {
6320Sstevel@tonic-gate 		error = ENXIO;
6330Sstevel@tonic-gate 		goto cleanup;
6340Sstevel@tonic-gate 	}
6350Sstevel@tonic-gate 
6360Sstevel@tonic-gate 	/*
6370Sstevel@tonic-gate 	 * Init a new hsfs structure.
6380Sstevel@tonic-gate 	 */
6390Sstevel@tonic-gate 	fsp = kmem_zalloc(sizeof (*fsp), KM_SLEEP);
6402900Sfrankho 	svp = kmem_zalloc(sizeof (*svp), KM_SLEEP);
6412900Sfrankho 	jvp = kmem_zalloc(sizeof (*jvp), KM_SLEEP);
6420Sstevel@tonic-gate 
6430Sstevel@tonic-gate 	/* hardwire perms, uid, gid */
6440Sstevel@tonic-gate 	fsp->hsfs_vol.vol_uid = hsfs_default_uid;
6450Sstevel@tonic-gate 	fsp->hsfs_vol.vol_gid =  hsfs_default_gid;
6460Sstevel@tonic-gate 	fsp->hsfs_vol.vol_prot = hsfs_default_mode;
6472900Sfrankho 	svp->vol_uid = hsfs_default_uid;
6482900Sfrankho 	svp->vol_gid =  hsfs_default_gid;
6492900Sfrankho 	svp->vol_prot = hsfs_default_mode;
6502900Sfrankho 	jvp->vol_uid = hsfs_default_uid;
6512900Sfrankho 	jvp->vol_gid =  hsfs_default_gid;
6522900Sfrankho 	jvp->vol_prot = hsfs_default_mode;
6530Sstevel@tonic-gate 
6540Sstevel@tonic-gate 	/*
6550Sstevel@tonic-gate 	 * Look for a Standard File Structure Volume Descriptor,
6560Sstevel@tonic-gate 	 * of which there must be at least one.
6570Sstevel@tonic-gate 	 * If found, check for volume size consistency.
6582900Sfrankho 	 *
6592900Sfrankho 	 * If svp->lbn_size is != 0, we did find a ISO-9660:1999 SVD
6602900Sfrankho 	 * If jvp->lbn_size is != 0, we did find a Joliet SVD.
6610Sstevel@tonic-gate 	 */
6622900Sfrankho 	fsp->hsfs_namemax = ISO_FILE_NAMELEN;
6632900Sfrankho 	fsp->hsfs_namelen = ISO_FILE_NAMELEN;
6642900Sfrankho 	error = hs_findisovol(fsp, devvp, &fsp->hsfs_vol, svp, jvp);
6651025Sfrankho 	if (error == EINVAL) /* no iso 9660 - try high sierra ... */
6661025Sfrankho 		error = hs_findhsvol(fsp, devvp, &fsp->hsfs_vol);
6670Sstevel@tonic-gate 
6680Sstevel@tonic-gate 	if (error)
6690Sstevel@tonic-gate 		goto cleanup;
6700Sstevel@tonic-gate 
6712900Sfrankho 	DTRACE_PROBE4(findvol,
6722900Sfrankho 	    struct hsfs *, fsp,
6732900Sfrankho 	    struct hs_volume *, &fsp->hsfs_vol,
6742900Sfrankho 	    struct hs_volume *, svp,
6752900Sfrankho 	    struct hs_volume *, jvp);
6762900Sfrankho 
6770Sstevel@tonic-gate 	/*
6780Sstevel@tonic-gate 	 * Generate a file system ID from the CD-ROM,
6790Sstevel@tonic-gate 	 * and check it for uniqueness.
6800Sstevel@tonic-gate 	 *
6810Sstevel@tonic-gate 	 * What we are aiming for is some chance of integrity
6820Sstevel@tonic-gate 	 * across disk change.  That is, if a client has an fhandle,
6830Sstevel@tonic-gate 	 * it will be valid as long as the same disk is mounted.
6840Sstevel@tonic-gate 	 */
6850Sstevel@tonic-gate 	fsid = compute_cdrom_id(fsp, devvp);
6860Sstevel@tonic-gate 
6870Sstevel@tonic-gate 	mutex_enter(&hs_mounttab_lock);
6880Sstevel@tonic-gate 
6890Sstevel@tonic-gate 	if (fsid == 0 || fsid == -1) {
6900Sstevel@tonic-gate 		uniqtime(&tv);
6910Sstevel@tonic-gate 		fsid = tv.tv_sec;
6920Sstevel@tonic-gate 	} else	/* make sure that the fsid is unique */
6930Sstevel@tonic-gate 		for (tsp = hs_mounttab; tsp != NULL; tsp = tsp->hsfs_next) {
6940Sstevel@tonic-gate 			if (fsid == tsp->hsfs_vfs->vfs_fsid.val[0]) {
6950Sstevel@tonic-gate 				uniqtime(&tv);
6960Sstevel@tonic-gate 				fsid = tv.tv_sec;
6970Sstevel@tonic-gate 				break;
6980Sstevel@tonic-gate 			}
6990Sstevel@tonic-gate 		}
7000Sstevel@tonic-gate 
7010Sstevel@tonic-gate 	fsp->hsfs_next = hs_mounttab;
7020Sstevel@tonic-gate 	hs_mounttab = fsp;
7030Sstevel@tonic-gate 
7040Sstevel@tonic-gate 	fsp->hsfs_devvp = devvp;
7050Sstevel@tonic-gate 	fsp->hsfs_vfs = vfsp;
7062900Sfrankho 	fsp->hsfs_fsmnt = kmem_alloc(pathbufsz, KM_SLEEP);
7072900Sfrankho 	(void) strlcpy(fsp->hsfs_fsmnt, path, pathbufsz);
7080Sstevel@tonic-gate 
7090Sstevel@tonic-gate 	mutex_init(&fsp->hsfs_free_lock, NULL, MUTEX_DEFAULT, NULL);
7100Sstevel@tonic-gate 	rw_init(&fsp->hsfs_hash_lock, NULL, RW_DEFAULT, NULL);
7110Sstevel@tonic-gate 
7120Sstevel@tonic-gate 	vfsp->vfs_data = (caddr_t)fsp;
7130Sstevel@tonic-gate 	vfsp->vfs_dev = dev;
7140Sstevel@tonic-gate 	vfsp->vfs_fstype = hsfsfstype;
7150Sstevel@tonic-gate 	vfsp->vfs_bsize = fsp->hsfs_vol.lbn_size; /* %% */
7160Sstevel@tonic-gate 	vfsp->vfs_fsid.val[0] = fsid;
7170Sstevel@tonic-gate 	vfsp->vfs_fsid.val[1] =  hsfsfstype;
7180Sstevel@tonic-gate 
7192900Sfrankho 	if (!hs_getrootvp(vfsp, fsp, pathbufsz)) {
7202900Sfrankho 		DTRACE_PROBE1(rootvp__failed, struct hsfs *, fsp);
7212900Sfrankho 		error = EINVAL;
7222900Sfrankho 		goto cleanup;
7232900Sfrankho 	}
7242900Sfrankho 	DTRACE_PROBE1(rootvp, struct hsfs *, fsp);
7252900Sfrankho 
7262900Sfrankho 	/*
7272900Sfrankho 	 * Attempt to discover a RR extension.
7282900Sfrankho 	 */
7292900Sfrankho 	if (use_rrip) {
7302900Sfrankho 		hp = VTOH(fsp->hsfs_rootvp);
7312900Sfrankho 		hs_check_root_dirent(fsp->hsfs_rootvp, &(hp->hs_dirent));
7322900Sfrankho 	}
7332900Sfrankho 
7342900Sfrankho 	has_rrip = IS_RRIP_IMPLEMENTED(fsp);
7352900Sfrankho 	has_vers2 = (svp->lbn_size != 0);
7362900Sfrankho 	has_joliet = (jvp->lbn_size != 0);
7372900Sfrankho 
7382900Sfrankho 	DTRACE_PROBE4(voltype__suggested, struct hsfs *, fsp,
7392900Sfrankho 	    int, use_rrip, int, use_vers2, int, use_joliet);
7402900Sfrankho 
7412900Sfrankho 	DTRACE_PROBE4(voltype__actual, struct hsfs *, fsp,
7422900Sfrankho 	    int, has_rrip, int, has_vers2, int, has_joliet);
7432900Sfrankho 
7442900Sfrankho 	DTRACE_PROBE4(findvol,
7452900Sfrankho 	    struct hsfs *, fsp,
7462900Sfrankho 	    struct hs_volume *, &fsp->hsfs_vol,
7472900Sfrankho 	    struct hs_volume *, svp,
7482900Sfrankho 	    struct hs_volume *, jvp);
7492900Sfrankho 
7502900Sfrankho 	force_rrip_off = !use_rrip ||
7512900Sfrankho 	    (vfs_optionisset(vfsp, HOPT_JOLIET, NULL) && has_joliet) ||
7522900Sfrankho 	    (vfs_optionisset(vfsp, HOPT_VERS2, NULL) && has_vers2);
7532900Sfrankho 
7542900Sfrankho 	force_vers2_off = !use_vers2 ||
7552900Sfrankho 	    (vfs_optionisset(vfsp, HOPT_JOLIET, NULL) && has_joliet);
7562900Sfrankho 
7572900Sfrankho 	force_joliet_off = !use_joliet;
7582900Sfrankho 
7592900Sfrankho 	DTRACE_PROBE4(voltype__force_off, struct hsfs *, fsp,
7602900Sfrankho 	    int, force_rrip_off, int, force_vers2_off, int, force_joliet_off);
7612900Sfrankho 
7622900Sfrankho 	/*
7632900Sfrankho 	 * At the moment, we have references of all three possible
7642900Sfrankho 	 * extensions (RR, ISO9660:1999/v2 and Joliet) if present.
7652900Sfrankho 	 *
7662900Sfrankho 	 * The "active" volume descriptor is RRIP (or ISO9660:1988).
7672900Sfrankho 	 * We now switch to the user-requested one.
7682900Sfrankho 	 */
7692900Sfrankho 	redo_rootvp = 0;
7702900Sfrankho 
7712900Sfrankho 	if (force_rrip_off || !has_rrip) {
7722900Sfrankho 		if (has_vers2 && !force_vers2_off) {
7732900Sfrankho 			VN_RELE(fsp->hsfs_rootvp);
7742900Sfrankho 			bcopy(svp, &fsp->hsfs_vol, sizeof (struct hs_volume));
7752900Sfrankho 			fsp->hsfs_vol_type = HS_VOL_TYPE_ISO_V2;
7762900Sfrankho 			vfsp->vfs_bsize = fsp->hsfs_vol.lbn_size;
7772900Sfrankho 			redo_rootvp = 1;
7782900Sfrankho 			has_joliet = 0;
7792900Sfrankho 		} else if (has_joliet && !force_joliet_off) {
7802900Sfrankho 			VN_RELE(fsp->hsfs_rootvp);
7812900Sfrankho 			bcopy(jvp, &fsp->hsfs_vol, sizeof (struct hs_volume));
7822900Sfrankho 			fsp->hsfs_vol_type = HS_VOL_TYPE_JOLIET;
7832900Sfrankho 			vfsp->vfs_bsize = fsp->hsfs_vol.lbn_size;
7842900Sfrankho 			redo_rootvp = 1;
7852900Sfrankho 			has_vers2 = 0;
7862900Sfrankho 		}
7872900Sfrankho 	}
7882900Sfrankho 
7892900Sfrankho 	if (redo_rootvp) {
7902900Sfrankho 		/*
7912900Sfrankho 		 * Make sure not to use Rock Ridge.
7922900Sfrankho 		 */
7932900Sfrankho 		UNSET_IMPL_BIT(fsp, RRIP_BIT);
7942900Sfrankho 		UNSET_SUSP_BIT(fsp);
7952900Sfrankho 		has_rrip = 0;
7962900Sfrankho 
7972900Sfrankho 		if (!hs_getrootvp(vfsp, fsp, pathbufsz)) {
7982900Sfrankho 			DTRACE_PROBE1(rootvp__failed, struct hsfs *, fsp);
7992900Sfrankho 			error = EINVAL;
8002900Sfrankho 			goto cleanup;
8012900Sfrankho 		}
8022900Sfrankho 		DTRACE_PROBE1(rootvp, struct hsfs *, fsp);
8032900Sfrankho 	}
8042900Sfrankho 	if (IS_RRIP_IMPLEMENTED(fsp)) {
8052900Sfrankho 		has_vers2 = 0;
8062900Sfrankho 		has_joliet = 0;
8072900Sfrankho 	}
8082900Sfrankho 	if (force_vers2_off)
8092900Sfrankho 		has_vers2 = 0;
8102900Sfrankho 	if (force_joliet_off)
8112900Sfrankho 		has_joliet = 0;
8122900Sfrankho 	DTRACE_PROBE4(voltype__taken, struct hsfs *, fsp,
8132900Sfrankho 	    int, has_rrip, int, has_vers2, int, has_joliet);
8142900Sfrankho 
8152900Sfrankho 	/*
8162900Sfrankho 	 * mark root node as VROOT
8172900Sfrankho 	 */
8182900Sfrankho 	fsp->hsfs_rootvp->v_flag |= VROOT;
8192900Sfrankho 
8202900Sfrankho 	/* Here we take care of some special case stuff for mountroot */
8212900Sfrankho 	if (isroot) {
8222900Sfrankho 		fsp->hsfs_rootvp->v_rdev = devvp->v_rdev;
8232900Sfrankho 		rootvp = fsp->hsfs_rootvp;
8242900Sfrankho 	}
8252900Sfrankho 
8262900Sfrankho 	if (IS_RRIP_IMPLEMENTED(fsp)) {
8272900Sfrankho 		/*
8282900Sfrankho 		 * if RRIP, don't copy NOMAPLCASE or NOTRAILDOT to hsfs_flags
8292900Sfrankho 		 */
8302900Sfrankho 		mount_flags &= ~(HSFSMNT_NOMAPLCASE | HSFSMNT_NOTRAILDOT);
8312900Sfrankho 
8322900Sfrankho 		fsp->hsfs_namemax = RRIP_FILE_NAMELEN;
8332900Sfrankho 		fsp->hsfs_namelen = RRIP_FILE_NAMELEN;
8342900Sfrankho 
8352900Sfrankho 		ASSERT(vfs_optionisset(vfsp, HOPT_RR, NULL));
8362900Sfrankho 		vfs_clearmntopt(vfsp, HOPT_VERS2);
8372900Sfrankho 		vfs_clearmntopt(vfsp, HOPT_JOLIET);
8382900Sfrankho 
8392900Sfrankho 	} else switch (fsp->hsfs_vol_type) {
8402900Sfrankho 
8412900Sfrankho 	case HS_VOL_TYPE_HS:
8422900Sfrankho 	case HS_VOL_TYPE_ISO:
8432900Sfrankho 	default:
8442900Sfrankho 		/*
8452900Sfrankho 		 * if iso v1, don't allow trailing spaces in iso file names
8462900Sfrankho 		 */
8472900Sfrankho 		mount_flags |= HSFSMNT_NOTRAILSPACE;
8482900Sfrankho 		fsp->hsfs_namemax = ISO_NAMELEN_V2_MAX;
8492900Sfrankho 		fsp->hsfs_namelen = ISO_FILE_NAMELEN;
8502900Sfrankho 		vfs_clearmntopt(vfsp, HOPT_RR);
8512900Sfrankho 		vfs_clearmntopt(vfsp, HOPT_VERS2);
8522900Sfrankho 		vfs_clearmntopt(vfsp, HOPT_JOLIET);
8532900Sfrankho 		break;
8542900Sfrankho 
8552900Sfrankho 	case HS_VOL_TYPE_ISO_V2:
8562900Sfrankho 		/*
8572900Sfrankho 		 * if iso v2, don't copy NOTRAILDOT to hsfs_flags
8582900Sfrankho 		 */
8592900Sfrankho 		mount_flags &= ~HSFSMNT_NOTRAILDOT;
8602900Sfrankho 		mount_flags |= HSFSMNT_NOMAPLCASE | HSFSMNT_NOVERSION;
8612900Sfrankho 		fsp->hsfs_namemax = ISO_NAMELEN_V2_MAX;
8622900Sfrankho 		fsp->hsfs_namelen = ISO_NAMELEN_V2;
8632900Sfrankho 		vfs_setmntopt(vfsp, HOPT_VERS2, NULL, 0);
8642900Sfrankho 		vfs_clearmntopt(vfsp, HOPT_RR);
8652900Sfrankho 		vfs_clearmntopt(vfsp, HOPT_JOLIET);
8662900Sfrankho 		break;
8672900Sfrankho 
8682900Sfrankho 	case HS_VOL_TYPE_JOLIET:
8692900Sfrankho 		/*
8702900Sfrankho 		 * if Joliet, don't copy NOMAPLCASE or NOTRAILDOT to hsfs_flags
8712900Sfrankho 		 */
8722900Sfrankho 		mount_flags &= ~(HSFSMNT_NOMAPLCASE | HSFSMNT_NOTRAILDOT);
8732900Sfrankho 		mount_flags |= HSFSMNT_NOMAPLCASE;
8742900Sfrankho 		if (mount_flags & HSFSMNT_JOLIETLONG)
8752900Sfrankho 			fsp->hsfs_namemax = JOLIET_NAMELEN_MAX*3; /* UTF-8 */
8762900Sfrankho 		else
8772900Sfrankho 			fsp->hsfs_namemax = MAXNAMELEN-1;
8782900Sfrankho 		fsp->hsfs_namelen = JOLIET_NAMELEN*2;
8792900Sfrankho 		vfs_setmntopt(vfsp, HOPT_JOLIET, NULL, 0);
8802900Sfrankho 		vfs_clearmntopt(vfsp, HOPT_RR);
8812900Sfrankho 		vfs_clearmntopt(vfsp, HOPT_VERS2);
8822900Sfrankho 		break;
8832900Sfrankho 	}
8842900Sfrankho 
8852900Sfrankho 	fsp->hsfs_flags = mount_flags;
8862900Sfrankho 
8872900Sfrankho 	DTRACE_PROBE1(mount__done, struct hsfs *, fsp);
8882900Sfrankho 
8892900Sfrankho 	/*
8902900Sfrankho 	 * set the magic word
8912900Sfrankho 	 */
8922900Sfrankho 	fsp->hsfs_magic = HSFS_MAGIC;
8932900Sfrankho 	mutex_exit(&hs_mounttab_lock);
8942900Sfrankho 
8952900Sfrankho 	return (0);
8962900Sfrankho 
8972900Sfrankho cleanup:
8982900Sfrankho 	(void) VOP_CLOSE(devvp, FREAD, 1, (offset_t)0, cr);
8992900Sfrankho 	VN_RELE(devvp);
9002900Sfrankho 	if (fsp)
9012900Sfrankho 		kmem_free(fsp, sizeof (*fsp));
9022900Sfrankho 	if (svp)
9032900Sfrankho 		kmem_free(svp, sizeof (*svp));
9042900Sfrankho 	if (jvp)
9052900Sfrankho 		kmem_free(jvp, sizeof (*jvp));
9062900Sfrankho 	return (error);
9072900Sfrankho }
9082900Sfrankho 
9092900Sfrankho /*
9102900Sfrankho  * Get the rootvp associated with fsp->hsfs_vol
9112900Sfrankho  */
9122900Sfrankho static int
9132900Sfrankho hs_getrootvp(
9142900Sfrankho 	struct vfs	*vfsp,
9152900Sfrankho 	struct hsfs	*fsp,
9162900Sfrankho 	size_t		pathsize)
9172900Sfrankho {
9182900Sfrankho 	struct hsnode	*hp;
9192900Sfrankho 
9202900Sfrankho 	ASSERT(pathsize == strlen(fsp->hsfs_fsmnt) + 1);
9212900Sfrankho 
9220Sstevel@tonic-gate 	/*
9230Sstevel@tonic-gate 	 * If the root directory does not appear to be
9240Sstevel@tonic-gate 	 * valid, use what it points to as "." instead.
9250Sstevel@tonic-gate 	 * Some Defense Mapping Agency disks are non-conformant
9260Sstevel@tonic-gate 	 * in this way.
9270Sstevel@tonic-gate 	 */
9280Sstevel@tonic-gate 	if (!hsfs_valid_dir(&fsp->hsfs_vol.root_dir)) {
9290Sstevel@tonic-gate 		hs_log_bogus_disk_warning(fsp, HSFS_ERR_BAD_ROOT_DIR, 0);
9300Sstevel@tonic-gate 		if (hs_remakenode(fsp->hsfs_vol.root_dir.ext_lbn,
9310Sstevel@tonic-gate 			    (uint_t)0, vfsp, &fsp->hsfs_rootvp)) {
9321025Sfrankho 			hs_mounttab = hs_mounttab->hsfs_next;
9331025Sfrankho 			mutex_destroy(&fsp->hsfs_free_lock);
9341025Sfrankho 			rw_destroy(&fsp->hsfs_hash_lock);
9352900Sfrankho 			kmem_free(fsp->hsfs_fsmnt, pathsize);
936494Sfrankho 			mutex_exit(&hs_mounttab_lock);
9372900Sfrankho 			return (0);
9380Sstevel@tonic-gate 		}
9390Sstevel@tonic-gate 	} else {
9400Sstevel@tonic-gate 		fsp->hsfs_rootvp = hs_makenode(&fsp->hsfs_vol.root_dir,
9410Sstevel@tonic-gate 			fsp->hsfs_vol.root_dir.ext_lbn, 0, vfsp);
9420Sstevel@tonic-gate 	}
9430Sstevel@tonic-gate 
9440Sstevel@tonic-gate 	/* XXX - ignore the path table for now */
9450Sstevel@tonic-gate 	fsp->hsfs_ptbl = NULL;
9460Sstevel@tonic-gate 	hp = VTOH(fsp->hsfs_rootvp);
9470Sstevel@tonic-gate 	hp->hs_ptbl_idx = NULL;
9480Sstevel@tonic-gate 
9492900Sfrankho 	return (1);
9500Sstevel@tonic-gate }
9510Sstevel@tonic-gate 
9520Sstevel@tonic-gate /*
9530Sstevel@tonic-gate  * hs_findhsvol()
9540Sstevel@tonic-gate  *
9550Sstevel@tonic-gate  * Locate the Standard File Structure Volume Descriptor and
9560Sstevel@tonic-gate  * parse it into an hs_volume structure.
9570Sstevel@tonic-gate  *
9580Sstevel@tonic-gate  * XXX - May someday want to look for Coded Character Set FSVD, too.
9590Sstevel@tonic-gate  */
9600Sstevel@tonic-gate static int
9610Sstevel@tonic-gate hs_findhsvol(struct hsfs *fsp, struct vnode *vp, struct hs_volume *hvp)
9620Sstevel@tonic-gate {
9630Sstevel@tonic-gate 	struct buf *secbp;
9640Sstevel@tonic-gate 	int i;
9650Sstevel@tonic-gate 	uchar_t *volp;
9660Sstevel@tonic-gate 	int error;
9670Sstevel@tonic-gate 	uint_t secno;
9680Sstevel@tonic-gate 
9690Sstevel@tonic-gate 	secno = hs_findvoldesc(vp->v_rdev, HS_VOLDESC_SEC);
9700Sstevel@tonic-gate 	secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE);
9710Sstevel@tonic-gate 	error = geterror(secbp);
9720Sstevel@tonic-gate 
9730Sstevel@tonic-gate 	if (error != 0) {
9740Sstevel@tonic-gate 		cmn_err(CE_NOTE, "hs_findhsvol: bread: error=(%d)", error);
9750Sstevel@tonic-gate 		brelse(secbp);
9760Sstevel@tonic-gate 		return (error);
9770Sstevel@tonic-gate 	}
9780Sstevel@tonic-gate 
9790Sstevel@tonic-gate 	volp = (uchar_t *)secbp->b_un.b_addr;
9800Sstevel@tonic-gate 
9810Sstevel@tonic-gate 	while (HSV_DESC_TYPE(volp) != VD_EOV) {
9820Sstevel@tonic-gate 		for (i = 0; i < HSV_ID_STRLEN; i++)
9830Sstevel@tonic-gate 			if (HSV_STD_ID(volp)[i] != HSV_ID_STRING[i])
9840Sstevel@tonic-gate 				goto cantfind;
9850Sstevel@tonic-gate 		if (HSV_STD_VER(volp) != HSV_ID_VER)
9860Sstevel@tonic-gate 			goto cantfind;
9870Sstevel@tonic-gate 		switch (HSV_DESC_TYPE(volp)) {
9880Sstevel@tonic-gate 		case VD_SFS:
9890Sstevel@tonic-gate 			/* Standard File Structure */
9900Sstevel@tonic-gate 			fsp->hsfs_vol_type = HS_VOL_TYPE_HS;
9910Sstevel@tonic-gate 			error = hs_parsehsvol(fsp, volp, hvp);
9920Sstevel@tonic-gate 			brelse(secbp);
9930Sstevel@tonic-gate 			return (error);
9940Sstevel@tonic-gate 
9950Sstevel@tonic-gate 		case VD_CCFS:
9960Sstevel@tonic-gate 			/* Coded Character File Structure */
9970Sstevel@tonic-gate 		case VD_BOOT:
9980Sstevel@tonic-gate 		case VD_UNSPEC:
9990Sstevel@tonic-gate 		case VD_EOV:
10000Sstevel@tonic-gate 			break;
10010Sstevel@tonic-gate 		}
10020Sstevel@tonic-gate 		brelse(secbp);
10030Sstevel@tonic-gate 		++secno;
10040Sstevel@tonic-gate 		secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE);
10050Sstevel@tonic-gate 
10060Sstevel@tonic-gate 		error = geterror(secbp);
10070Sstevel@tonic-gate 
10080Sstevel@tonic-gate 		if (error != 0) {
10090Sstevel@tonic-gate 			cmn_err(CE_NOTE, "hs_findhsvol: bread: error=(%d)",
10100Sstevel@tonic-gate 				error);
10110Sstevel@tonic-gate 			brelse(secbp);
10120Sstevel@tonic-gate 			return (error);
10130Sstevel@tonic-gate 		}
10140Sstevel@tonic-gate 
10150Sstevel@tonic-gate 		volp = (uchar_t *)secbp->b_un.b_addr;
10160Sstevel@tonic-gate 	}
10170Sstevel@tonic-gate cantfind:
10180Sstevel@tonic-gate 	brelse(secbp);
10190Sstevel@tonic-gate 	return (EINVAL);
10200Sstevel@tonic-gate }
10210Sstevel@tonic-gate 
10220Sstevel@tonic-gate /*
10230Sstevel@tonic-gate  * hs_parsehsvol
10240Sstevel@tonic-gate  *
10250Sstevel@tonic-gate  * Parse the Standard File Structure Volume Descriptor into
10260Sstevel@tonic-gate  * an hs_volume structure.  We can't just bcopy it into the
10270Sstevel@tonic-gate  * structure because of byte-ordering problems.
10280Sstevel@tonic-gate  *
10290Sstevel@tonic-gate  */
10300Sstevel@tonic-gate static int
10310Sstevel@tonic-gate hs_parsehsvol(struct hsfs *fsp, uchar_t *volp, struct hs_volume *hvp)
10320Sstevel@tonic-gate {
10330Sstevel@tonic-gate 	hvp->vol_size = HSV_VOL_SIZE(volp);
10340Sstevel@tonic-gate 	hvp->lbn_size = HSV_BLK_SIZE(volp);
10350Sstevel@tonic-gate 	if (hvp->lbn_size == 0) {
10360Sstevel@tonic-gate 		cmn_err(CE_NOTE, "hs_parsehsvol: logical block size in the "
10370Sstevel@tonic-gate 			"SFSVD is zero");
10380Sstevel@tonic-gate 		return (EINVAL);
10390Sstevel@tonic-gate 	}
10400Sstevel@tonic-gate 	hvp->lbn_shift = ffs((long)hvp->lbn_size) - 1;
10410Sstevel@tonic-gate 	hvp->lbn_secshift = ffs((long)howmany(HS_SECTOR_SIZE,
10420Sstevel@tonic-gate 				(int)hvp->lbn_size)) - 1;
10430Sstevel@tonic-gate 	hvp->lbn_maxoffset = hvp->lbn_size - 1;
10440Sstevel@tonic-gate 	hs_parse_longdate(HSV_cre_date(volp), &hvp->cre_date);
10450Sstevel@tonic-gate 	hs_parse_longdate(HSV_mod_date(volp), &hvp->mod_date);
10460Sstevel@tonic-gate 	hvp->file_struct_ver = HSV_FILE_STRUCT_VER(volp);
10470Sstevel@tonic-gate 	hvp->ptbl_len = HSV_PTBL_SIZE(volp);
10480Sstevel@tonic-gate 	hvp->vol_set_size = (ushort_t)HSV_SET_SIZE(volp);
10490Sstevel@tonic-gate 	hvp->vol_set_seq = (ushort_t)HSV_SET_SEQ(volp);
10500Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN)
10510Sstevel@tonic-gate 	hvp->ptbl_lbn = HSV_PTBL_MAN_LS(volp);
10520Sstevel@tonic-gate #else
10530Sstevel@tonic-gate 	hvp->ptbl_lbn = HSV_PTBL_MAN_MS(volp);
10540Sstevel@tonic-gate #endif
10552900Sfrankho 	hs_copylabel(hvp, HSV_VOL_ID(volp), 0);
10560Sstevel@tonic-gate 
10570Sstevel@tonic-gate 	/*
10580Sstevel@tonic-gate 	 * Make sure that lbn_size is a power of two and otherwise valid.
10590Sstevel@tonic-gate 	 */
10600Sstevel@tonic-gate 	if (hvp->lbn_size & ~(1 << hvp->lbn_shift)) {
10610Sstevel@tonic-gate 		cmn_err(CE_NOTE,
10620Sstevel@tonic-gate 			"hsfs: %d-byte logical block size not supported",
10630Sstevel@tonic-gate 			hvp->lbn_size);
10640Sstevel@tonic-gate 		return (EINVAL);
10650Sstevel@tonic-gate 	}
10660Sstevel@tonic-gate 	return (hs_parsedir(fsp, HSV_ROOT_DIR(volp), &hvp->root_dir,
10672900Sfrankho 			(char *)NULL, (int *)NULL, HDE_ROOT_DIR_REC_SIZE));
10680Sstevel@tonic-gate }
10690Sstevel@tonic-gate 
10700Sstevel@tonic-gate /*
10710Sstevel@tonic-gate  * hs_findisovol()
10720Sstevel@tonic-gate  *
10730Sstevel@tonic-gate  * Locate the Primary Volume Descriptor
10740Sstevel@tonic-gate  * parse it into an hs_volume structure.
10750Sstevel@tonic-gate  *
10762900Sfrankho  * XXX - Partition not yet done
10772900Sfrankho  *
10782900Sfrankho  * Except for fsp->hsfs_vol_type, no fsp member may be modified.
10792900Sfrankho  * fsp->hsfs_vol is modified indirectly via the *hvp argument.
10800Sstevel@tonic-gate  */
10810Sstevel@tonic-gate static int
10820Sstevel@tonic-gate hs_findisovol(struct hsfs *fsp, struct vnode *vp,
10832900Sfrankho     struct hs_volume *hvp,
10842900Sfrankho     struct hs_volume *svp,
10852900Sfrankho     struct hs_volume *jvp)
10860Sstevel@tonic-gate {
10870Sstevel@tonic-gate 	struct buf *secbp;
10880Sstevel@tonic-gate 	int i;
10890Sstevel@tonic-gate 	uchar_t *volp;
10900Sstevel@tonic-gate 	int error;
10910Sstevel@tonic-gate 	uint_t secno;
10920Sstevel@tonic-gate 	int foundpvd = 0;
10932900Sfrankho 	int foundsvd = 0;
10942900Sfrankho 	int foundjvd = 0;
10950Sstevel@tonic-gate 
10960Sstevel@tonic-gate 	secno = hs_findvoldesc(vp->v_rdev, ISO_VOLDESC_SEC);
10970Sstevel@tonic-gate 	secbp = bread(vp->v_rdev, secno * 4, ISO_SECTOR_SIZE);
10980Sstevel@tonic-gate 	error = geterror(secbp);
10990Sstevel@tonic-gate 
11000Sstevel@tonic-gate 	if (error != 0) {
11010Sstevel@tonic-gate 		cmn_err(CE_NOTE, "hs_findisovol: bread: error=(%d)", error);
11020Sstevel@tonic-gate 		brelse(secbp);
11030Sstevel@tonic-gate 		return (error);
11040Sstevel@tonic-gate 	}
11050Sstevel@tonic-gate 
11060Sstevel@tonic-gate 	volp = (uchar_t *)secbp->b_un.b_addr;
11070Sstevel@tonic-gate 
11080Sstevel@tonic-gate 	while ((enum iso_voldesc_type) ISO_DESC_TYPE(volp) != ISO_VD_EOV) {
11090Sstevel@tonic-gate 		for (i = 0; i < ISO_ID_STRLEN; i++)
11100Sstevel@tonic-gate 			if (ISO_STD_ID(volp)[i] != ISO_ID_STRING[i])
11110Sstevel@tonic-gate 				goto cantfind;
11120Sstevel@tonic-gate 		switch (ISO_DESC_TYPE(volp)) {
11130Sstevel@tonic-gate 		case ISO_VD_PVD:
11140Sstevel@tonic-gate 			/* Standard File Structure */
11152900Sfrankho 			if (ISO_STD_VER(volp) != ISO_ID_VER)
11162900Sfrankho 				goto cantfind;
11170Sstevel@tonic-gate 			if (foundpvd != 1) {
11180Sstevel@tonic-gate 				fsp->hsfs_vol_type = HS_VOL_TYPE_ISO;
11190Sstevel@tonic-gate 				if (error = hs_parseisovol(fsp, volp, hvp)) {
11200Sstevel@tonic-gate 					brelse(secbp);
11210Sstevel@tonic-gate 					return (error);
11220Sstevel@tonic-gate 				}
11230Sstevel@tonic-gate 				foundpvd = 1;
11240Sstevel@tonic-gate 			}
11250Sstevel@tonic-gate 			break;
11260Sstevel@tonic-gate 		case ISO_VD_SVD:
11270Sstevel@tonic-gate 			/* Supplementary Volume Descriptor */
11282900Sfrankho 			if (ISO_STD_VER(volp) == ISO_ID_VER2 &&
11292900Sfrankho 			    foundsvd != 1) {
11302900Sfrankho 				fsp->hsfs_vol_type = HS_VOL_TYPE_ISO;
11312900Sfrankho 				if (error = hs_parseisovol(fsp, volp, svp)) {
11322900Sfrankho 					brelse(secbp);
11332900Sfrankho 					return (error);
11342900Sfrankho 				}
11352900Sfrankho 				foundsvd = 1;
11362900Sfrankho 			}
11372900Sfrankho 			if (hs_joliet_level(volp) >= 1 && foundjvd != 1) {
11382900Sfrankho 				fsp->hsfs_vol_type = HS_VOL_TYPE_ISO;
11392900Sfrankho 				if (error = hs_parseisovol(fsp, volp, jvp)) {
11402900Sfrankho 					brelse(secbp);
11412900Sfrankho 					return (error);
11422900Sfrankho 				}
11432900Sfrankho 				foundjvd = 1;
11442900Sfrankho 			}
11450Sstevel@tonic-gate 			break;
11460Sstevel@tonic-gate 		case ISO_VD_BOOT:
11470Sstevel@tonic-gate 			break;
11480Sstevel@tonic-gate 		case ISO_VD_VPD:
11490Sstevel@tonic-gate 			/* currently cannot handle partition */
11500Sstevel@tonic-gate 			break;
11510Sstevel@tonic-gate 		case VD_EOV:
11520Sstevel@tonic-gate 			break;
11530Sstevel@tonic-gate 		}
11540Sstevel@tonic-gate 		brelse(secbp);
11550Sstevel@tonic-gate 		++secno;
11560Sstevel@tonic-gate 		secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE);
11570Sstevel@tonic-gate 		error = geterror(secbp);
11580Sstevel@tonic-gate 
11590Sstevel@tonic-gate 		if (error != 0) {
11600Sstevel@tonic-gate 			cmn_err(CE_NOTE, "hs_findisovol: bread: error=(%d)",
11610Sstevel@tonic-gate 				    error);
11620Sstevel@tonic-gate 			brelse(secbp);
11630Sstevel@tonic-gate 			return (error);
11640Sstevel@tonic-gate 		}
11650Sstevel@tonic-gate 
11660Sstevel@tonic-gate 		volp = (uchar_t *)secbp->b_un.b_addr;
11670Sstevel@tonic-gate 	}
11680Sstevel@tonic-gate 	if (foundpvd) {
11690Sstevel@tonic-gate 		brelse(secbp);
11700Sstevel@tonic-gate 		return (0);
11710Sstevel@tonic-gate 	}
11720Sstevel@tonic-gate cantfind:
11730Sstevel@tonic-gate 	brelse(secbp);
11740Sstevel@tonic-gate 	return (EINVAL);
11750Sstevel@tonic-gate }
11762900Sfrankho 
11772900Sfrankho /*
11782900Sfrankho  * Return 0 if no Joliet is found
11792900Sfrankho  * else return Joliet Level 1..3
11802900Sfrankho  */
11812900Sfrankho static int
11822900Sfrankho hs_joliet_level(uchar_t *volp)
11832900Sfrankho {
11842900Sfrankho 	if (ISO_std_ver(volp)[0] == ISO_ID_VER &&
11852900Sfrankho 	    ISO_svd_esc(volp)[0] == '%' &&
11862900Sfrankho 	    ISO_svd_esc(volp)[1] == '/') {
11872900Sfrankho 
11882900Sfrankho 		switch (ISO_svd_esc(volp)[2]) {
11892900Sfrankho 
11902900Sfrankho 		case '@':
11912900Sfrankho 			return (1);
11922900Sfrankho 		case 'C':
11932900Sfrankho 			return (2);
11942900Sfrankho 		case 'E':
11952900Sfrankho 			return (3);
11962900Sfrankho 		}
11972900Sfrankho 	}
11982900Sfrankho 	return (0);
11992900Sfrankho }
12002900Sfrankho 
12010Sstevel@tonic-gate /*
12020Sstevel@tonic-gate  * hs_parseisovol
12030Sstevel@tonic-gate  *
12040Sstevel@tonic-gate  * Parse the Primary Volume Descriptor into an hs_volume structure.
12050Sstevel@tonic-gate  *
12060Sstevel@tonic-gate  */
12070Sstevel@tonic-gate static int
12080Sstevel@tonic-gate hs_parseisovol(struct hsfs *fsp, uchar_t *volp, struct hs_volume *hvp)
12090Sstevel@tonic-gate {
12100Sstevel@tonic-gate 	hvp->vol_size = ISO_VOL_SIZE(volp);
12110Sstevel@tonic-gate 	hvp->lbn_size = ISO_BLK_SIZE(volp);
12120Sstevel@tonic-gate 	if (hvp->lbn_size == 0) {
12130Sstevel@tonic-gate 		cmn_err(CE_NOTE, "hs_parseisovol: logical block size in the "
12140Sstevel@tonic-gate 			"PVD is zero");
12150Sstevel@tonic-gate 		return (EINVAL);
12160Sstevel@tonic-gate 	}
12170Sstevel@tonic-gate 	hvp->lbn_shift = ffs((long)hvp->lbn_size) - 1;
12180Sstevel@tonic-gate 	hvp->lbn_secshift = ffs((long)howmany(ISO_SECTOR_SIZE,
12190Sstevel@tonic-gate 				(int)hvp->lbn_size)) - 1;
12200Sstevel@tonic-gate 	hvp->lbn_maxoffset = hvp->lbn_size - 1;
12210Sstevel@tonic-gate 	hs_parse_longdate(ISO_cre_date(volp), &hvp->cre_date);
12220Sstevel@tonic-gate 	hs_parse_longdate(ISO_mod_date(volp), &hvp->mod_date);
12230Sstevel@tonic-gate 	hvp->file_struct_ver = ISO_FILE_STRUCT_VER(volp);
12240Sstevel@tonic-gate 	hvp->ptbl_len = ISO_PTBL_SIZE(volp);
12250Sstevel@tonic-gate 	hvp->vol_set_size = (ushort_t)ISO_SET_SIZE(volp);
12260Sstevel@tonic-gate 	hvp->vol_set_seq = (ushort_t)ISO_SET_SEQ(volp);
12270Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN)
12280Sstevel@tonic-gate 	hvp->ptbl_lbn = ISO_PTBL_MAN_LS(volp);
12290Sstevel@tonic-gate #else
12300Sstevel@tonic-gate 	hvp->ptbl_lbn = ISO_PTBL_MAN_MS(volp);
12310Sstevel@tonic-gate #endif
12322900Sfrankho 	hs_copylabel(hvp, ISO_VOL_ID(volp), hs_joliet_level(volp) >= 1);
12330Sstevel@tonic-gate 
12340Sstevel@tonic-gate 	/*
12350Sstevel@tonic-gate 	 * Make sure that lbn_size is a power of two and otherwise valid.
12360Sstevel@tonic-gate 	 */
12370Sstevel@tonic-gate 	if (hvp->lbn_size & ~(1 << hvp->lbn_shift)) {
12380Sstevel@tonic-gate 		cmn_err(CE_NOTE,
12390Sstevel@tonic-gate 			"hsfs: %d-byte logical block size not supported",
12400Sstevel@tonic-gate 			hvp->lbn_size);
12410Sstevel@tonic-gate 		return (EINVAL);
12420Sstevel@tonic-gate 	}
12430Sstevel@tonic-gate 	return (hs_parsedir(fsp, ISO_ROOT_DIR(volp), &hvp->root_dir,
12442900Sfrankho 			(char *)NULL, (int *)NULL, IDE_ROOT_DIR_REC_SIZE));
12450Sstevel@tonic-gate }
12460Sstevel@tonic-gate 
12470Sstevel@tonic-gate /*
12480Sstevel@tonic-gate  * Common code for mount and umount.
12490Sstevel@tonic-gate  * Check that the user's argument is a reasonable
12500Sstevel@tonic-gate  * thing on which to mount, and return the device number if so.
12510Sstevel@tonic-gate  */
12520Sstevel@tonic-gate static int
12530Sstevel@tonic-gate hs_getmdev(struct vfs *vfsp, char *fspec, int flags, dev_t *pdev, mode_t *mode,
12540Sstevel@tonic-gate     cred_t *cr)
12550Sstevel@tonic-gate {
12560Sstevel@tonic-gate 	int error;
12570Sstevel@tonic-gate 	struct vnode *vp;
12580Sstevel@tonic-gate 	struct vattr vap;
12590Sstevel@tonic-gate 	dev_t dev;
12600Sstevel@tonic-gate 
12610Sstevel@tonic-gate 	/*
12620Sstevel@tonic-gate 	 * Get the device to be mounted
12630Sstevel@tonic-gate 	 */
12640Sstevel@tonic-gate 	error = lookupname(fspec, (flags & MS_SYSSPACE) ?
12650Sstevel@tonic-gate 	    UIO_SYSSPACE : UIO_USERSPACE, FOLLOW, NULLVPP, &vp);
12660Sstevel@tonic-gate 	if (error) {
12670Sstevel@tonic-gate 		if (error == ENOENT) {
12680Sstevel@tonic-gate 			return (ENODEV);	/* needs translation */
12690Sstevel@tonic-gate 		}
12700Sstevel@tonic-gate 		return (error);
12710Sstevel@tonic-gate 	}
12720Sstevel@tonic-gate 	if (vp->v_type != VBLK) {
12730Sstevel@tonic-gate 		VN_RELE(vp);
12740Sstevel@tonic-gate 		return (ENOTBLK);
12750Sstevel@tonic-gate 	}
12760Sstevel@tonic-gate 	/*
12770Sstevel@tonic-gate 	 * Can we read from the device?
12780Sstevel@tonic-gate 	 */
12790Sstevel@tonic-gate 	if ((error = VOP_ACCESS(vp, VREAD, 0, cr)) != 0 ||
12800Sstevel@tonic-gate 	    (error = secpolicy_spec_open(cr, vp, FREAD)) != 0) {
12810Sstevel@tonic-gate 		VN_RELE(vp);
12820Sstevel@tonic-gate 		return (error);
12830Sstevel@tonic-gate 	}
12840Sstevel@tonic-gate 
12850Sstevel@tonic-gate 	vap.va_mask = AT_MODE;		/* get protection mode */
12860Sstevel@tonic-gate 	(void) VOP_GETATTR(vp, &vap, 0, CRED());
12870Sstevel@tonic-gate 	*mode = vap.va_mode;
12880Sstevel@tonic-gate 
12890Sstevel@tonic-gate 	dev = *pdev = vp->v_rdev;
12900Sstevel@tonic-gate 	VN_RELE(vp);
12910Sstevel@tonic-gate 
12920Sstevel@tonic-gate 	/*
12930Sstevel@tonic-gate 	 * Ensure that this device isn't already mounted,
12940Sstevel@tonic-gate 	 * unless this is a REMOUNT request or we are told to suppress
12950Sstevel@tonic-gate 	 * mount checks.
12960Sstevel@tonic-gate 	 */
12970Sstevel@tonic-gate 	if ((flags & MS_NOCHECK) == 0) {
12980Sstevel@tonic-gate 		if (vfs_devmounting(dev, vfsp))
12990Sstevel@tonic-gate 			return (EBUSY);
13000Sstevel@tonic-gate 		if (vfs_devismounted(dev) && !(flags & MS_REMOUNT))
13010Sstevel@tonic-gate 			return (EBUSY);
13020Sstevel@tonic-gate 	}
13030Sstevel@tonic-gate 
13040Sstevel@tonic-gate 	if (getmajor(*pdev) >= devcnt)
13050Sstevel@tonic-gate 		return (ENXIO);
13060Sstevel@tonic-gate 	return (0);
13070Sstevel@tonic-gate }
13080Sstevel@tonic-gate 
13090Sstevel@tonic-gate static void
13102900Sfrankho hs_copylabel(struct hs_volume *hvp, unsigned char *label, int isjoliet)
13110Sstevel@tonic-gate {
13122900Sfrankho 	char	lbuf[64];	/* hs_joliet_cp() creates 48 bytes at most */
13132900Sfrankho 
13142900Sfrankho 	if (isjoliet) {
13152900Sfrankho 		/*
13162900Sfrankho 		 * hs_joliet_cp() will output 16..48 bytes.
13172900Sfrankho 		 * We need to clear 'lbuf' to avoid junk chars past byte 15.
13182900Sfrankho 		 */
13192900Sfrankho 		bzero(lbuf, sizeof (lbuf));
1320*2904Sfrankho 		(void) hs_joliet_cp((char *)label, lbuf, 32);
13212900Sfrankho 		label = (unsigned char *)lbuf;
13222900Sfrankho 	}
13230Sstevel@tonic-gate 	/* cdrom volid is at most 32 bytes */
13240Sstevel@tonic-gate 	bcopy(label, hvp->vol_id, 32);
13250Sstevel@tonic-gate 	hvp->vol_id[31] = NULL;
13260Sstevel@tonic-gate }
13270Sstevel@tonic-gate 
13280Sstevel@tonic-gate /*
13290Sstevel@tonic-gate  * Mount root file system.
13300Sstevel@tonic-gate  * "why" is ROOT_INIT on initial call, ROOT_REMOUNT if called to
13310Sstevel@tonic-gate  * remount the root file system, and ROOT_UNMOUNT if called to
13320Sstevel@tonic-gate  * unmount the root (e.g., as part of a system shutdown).
13330Sstevel@tonic-gate  *
13340Sstevel@tonic-gate  * XXX - this may be partially machine-dependent; it, along with the VFS_SWAPVP
13350Sstevel@tonic-gate  * operation, goes along with auto-configuration.  A mechanism should be
13360Sstevel@tonic-gate  * provided by which machine-INdependent code in the kernel can say "get me the
13370Sstevel@tonic-gate  * right root file system" and "get me the right initial swap area", and have
13380Sstevel@tonic-gate  * that done in what may well be a machine-dependent fashion.
13390Sstevel@tonic-gate  * Unfortunately, it is also file-system-type dependent (NFS gets it via
13400Sstevel@tonic-gate  * bootparams calls, UFS gets it from various and sundry machine-dependent
13410Sstevel@tonic-gate  * mechanisms, as SPECFS does for swap).
13420Sstevel@tonic-gate  */
13430Sstevel@tonic-gate static int
13440Sstevel@tonic-gate hsfs_mountroot(struct vfs *vfsp, enum whymountroot why)
13450Sstevel@tonic-gate {
13460Sstevel@tonic-gate 	int error;
13470Sstevel@tonic-gate 	struct hsfs *fsp;
13480Sstevel@tonic-gate 	struct hs_volume *fvolp;
13490Sstevel@tonic-gate 	static int hsfsrootdone = 0;
13500Sstevel@tonic-gate 	dev_t rootdev;
13510Sstevel@tonic-gate 	mode_t mode = 0;
13520Sstevel@tonic-gate 
13530Sstevel@tonic-gate 	if (why == ROOT_INIT) {
13540Sstevel@tonic-gate 		if (hsfsrootdone++)
13550Sstevel@tonic-gate 			return (EBUSY);
13560Sstevel@tonic-gate 		rootdev = getrootdev();
13570Sstevel@tonic-gate 		if (rootdev == (dev_t)NODEV)
13580Sstevel@tonic-gate 			return (ENODEV);
13590Sstevel@tonic-gate 		vfsp->vfs_dev = rootdev;
13600Sstevel@tonic-gate 		vfsp->vfs_flag |= VFS_RDONLY;
13610Sstevel@tonic-gate 	} else if (why == ROOT_REMOUNT) {
13620Sstevel@tonic-gate 		cmn_err(CE_NOTE, "hsfs_mountroot: ROOT_REMOUNT");
13630Sstevel@tonic-gate 		return (0);
13640Sstevel@tonic-gate 	} else if (why == ROOT_UNMOUNT) {
13650Sstevel@tonic-gate 		return (0);
13660Sstevel@tonic-gate 	}
13670Sstevel@tonic-gate 	error = vfs_lock(vfsp);
13680Sstevel@tonic-gate 	if (error) {
13690Sstevel@tonic-gate 		cmn_err(CE_NOTE, "hsfs_mountroot: couldn't get vfs_lock");
13700Sstevel@tonic-gate 		return (error);
13710Sstevel@tonic-gate 	}
13720Sstevel@tonic-gate 
13730Sstevel@tonic-gate 	error = hs_mountfs(vfsp, rootdev, "/", mode, 1, CRED(), 1);
13740Sstevel@tonic-gate 	/*
13750Sstevel@tonic-gate 	 * XXX - assumes root device is not indirect, because we don't set
13760Sstevel@tonic-gate 	 * rootvp.  Is rootvp used for anything?  If so, make another arg
13770Sstevel@tonic-gate 	 * to mountfs.
13780Sstevel@tonic-gate 	 */
13790Sstevel@tonic-gate 	if (error) {
13800Sstevel@tonic-gate 		vfs_unlock(vfsp);
13810Sstevel@tonic-gate 		if (rootvp) {
13820Sstevel@tonic-gate 			VN_RELE(rootvp);
13830Sstevel@tonic-gate 			rootvp = (struct vnode *)0;
13840Sstevel@tonic-gate 		}
13850Sstevel@tonic-gate 		return (error);
13860Sstevel@tonic-gate 	}
13870Sstevel@tonic-gate 	if (why == ROOT_INIT)
13880Sstevel@tonic-gate 		vfs_add((struct vnode *)0, vfsp,
13890Sstevel@tonic-gate 		    (vfsp->vfs_flag & VFS_RDONLY) ? MS_RDONLY : 0);
13900Sstevel@tonic-gate 	vfs_unlock(vfsp);
13910Sstevel@tonic-gate 	fsp = VFS_TO_HSFS(vfsp);
13920Sstevel@tonic-gate 	fvolp = &fsp->hsfs_vol;
13930Sstevel@tonic-gate #ifdef HSFS_CLKSET
13940Sstevel@tonic-gate 	if (fvolp->cre_date.tv_sec == 0) {
13950Sstevel@tonic-gate 	    cmn_err(CE_NOTE, "hsfs_mountroot: cre_date.tv_sec == 0");
13960Sstevel@tonic-gate 	    if (fvolp->mod_date.tv_sec == 0) {
13970Sstevel@tonic-gate 		cmn_err(CE_NOTE, "hsfs_mountroot: mod_date.tv_sec == 0");
13980Sstevel@tonic-gate 		cmn_err(CE_NOTE, "hsfs_mountroot: clkset(-1L)");
13990Sstevel@tonic-gate 		clkset(-1L);
14000Sstevel@tonic-gate 	    } else
14010Sstevel@tonic-gate 		clkset(fvolp->mod_date.tv_sec);
14020Sstevel@tonic-gate 	} else
14030Sstevel@tonic-gate 	    clkset(fvolp->mod_date.tv_sec);
14040Sstevel@tonic-gate #else	/* HSFS_CLKSET */
14050Sstevel@tonic-gate 	clkset(-1L);
14060Sstevel@tonic-gate #endif	/* HSFS_CLKSET */
14070Sstevel@tonic-gate 	return (0);
14080Sstevel@tonic-gate }
14090Sstevel@tonic-gate 
14100Sstevel@tonic-gate /*
14110Sstevel@tonic-gate  * hs_findvoldesc()
14120Sstevel@tonic-gate  *
14130Sstevel@tonic-gate  * Return the sector where the volume descriptor lives.  This is
14140Sstevel@tonic-gate  * a fixed value for "normal" cd-rom's, but can change for
14150Sstevel@tonic-gate  * multisession cd's.
14160Sstevel@tonic-gate  *
14170Sstevel@tonic-gate  * desc_sec is the same for high-sierra and iso 9660 formats, why
14180Sstevel@tonic-gate  * there are two differnt #defines used in the code for this is
14190Sstevel@tonic-gate  * beyond me.  These are standards, cast in concrete, right?
14200Sstevel@tonic-gate  * To be general, however, this function supports passing in different
14210Sstevel@tonic-gate  * values.
14220Sstevel@tonic-gate  */
14230Sstevel@tonic-gate static int
14240Sstevel@tonic-gate hs_findvoldesc(dev_t rdev, int desc_sec)
14250Sstevel@tonic-gate {
14260Sstevel@tonic-gate 	int secno;
14270Sstevel@tonic-gate 	int error;
14280Sstevel@tonic-gate 	int rval;	/* ignored */
14290Sstevel@tonic-gate 
14300Sstevel@tonic-gate #ifdef CDROMREADOFFSET
14310Sstevel@tonic-gate 	/*
14320Sstevel@tonic-gate 	 * Issue the Read Offset ioctl directly to the
14330Sstevel@tonic-gate 	 * device. Ignore any errors and set starting
14340Sstevel@tonic-gate 	 * secno to the default, otherwise add the
14350Sstevel@tonic-gate 	 * VOLDESC sector number to the offset.
14360Sstevel@tonic-gate 	 */
14370Sstevel@tonic-gate 	error = cdev_ioctl(rdev, CDROMREADOFFSET, (intptr_t)&secno,
14380Sstevel@tonic-gate 	    FNATIVE|FKIOCTL|FREAD, CRED(), &rval);
14390Sstevel@tonic-gate 	if (error) {
14400Sstevel@tonic-gate 		secno = desc_sec;
14410Sstevel@tonic-gate 	} else {
14420Sstevel@tonic-gate 		secno += desc_sec;
14430Sstevel@tonic-gate 	}
14440Sstevel@tonic-gate #else
14450Sstevel@tonic-gate 	secno = desc_sec;
14460Sstevel@tonic-gate #endif
14470Sstevel@tonic-gate 
14480Sstevel@tonic-gate 	return (secno);
14490Sstevel@tonic-gate }
1450