17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
554e0249cSfrankho  * Common Development and Distribution License (the "License").
654e0249cSfrankho  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
220fbb751dSJohn Levon  * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
2389b43686SBayard Bell  * Copyright (c) 2011 Bayard G. Bell. All rights reserved.
248cd81a20SJerry Jelinek  * Copyright 2013 Joyent, Inc. All rights reserved.
25d9a54dd1SSebastien Roy  * Copyright (c) 2017 by Delphix. All rights reserved.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate  * VFS operations for High Sierra filesystem
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/types.h>
337c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
347c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
357c478bd9Sstevel@tonic-gate #include <sys/param.h>
367c478bd9Sstevel@tonic-gate #include <sys/systm.h>
377c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
387c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
397c478bd9Sstevel@tonic-gate #include <sys/signal.h>
407c478bd9Sstevel@tonic-gate #include <sys/user.h>
417c478bd9Sstevel@tonic-gate #include <sys/proc.h>
427c478bd9Sstevel@tonic-gate #include <sys/disp.h>
437c478bd9Sstevel@tonic-gate #include <sys/buf.h>
447c478bd9Sstevel@tonic-gate #include <sys/pathname.h>
457c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
46aa59c4cbSrsb #include <sys/vfs_opreg.h>
477c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
487c478bd9Sstevel@tonic-gate #include <sys/file.h>
497c478bd9Sstevel@tonic-gate #include <sys/uio.h>
507c478bd9Sstevel@tonic-gate #include <sys/conf.h>
517c478bd9Sstevel@tonic-gate #include <sys/policy.h>
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate #include <vm/page.h>
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate #include <sys/fs/snode.h>
567c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_spec.h>
577c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_isospec.h>
587c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_node.h>
597c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_impl.h>
607c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_susp.h>
617c478bd9Sstevel@tonic-gate #include <sys/fs/hsfs_rrip.h>
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate #include <sys/statvfs.h>
647c478bd9Sstevel@tonic-gate #include <sys/mount.h>
657c478bd9Sstevel@tonic-gate #include <sys/mntent.h>
667c478bd9Sstevel@tonic-gate #include <sys/swap.h>
677c478bd9Sstevel@tonic-gate #include <sys/errno.h>
687c478bd9Sstevel@tonic-gate #include <sys/debug.h>
697c478bd9Sstevel@tonic-gate #include "fs/fs_subr.h"
707c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
717c478bd9Sstevel@tonic-gate #include <sys/bootconf.h>
727c478bd9Sstevel@tonic-gate 
73fc1c62b8Sfrankho #include <sys/sdt.h>
74fc1c62b8Sfrankho 
757c478bd9Sstevel@tonic-gate /*
767c478bd9Sstevel@tonic-gate  * These are needed for the CDROMREADOFFSET Code
777c478bd9Sstevel@tonic-gate  */
787c478bd9Sstevel@tonic-gate #include <sys/cdio.h>
797c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate #define	HSFS_CLKSET
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate /*
867c478bd9Sstevel@tonic-gate  * Options for mount.
877c478bd9Sstevel@tonic-gate  */
887c478bd9Sstevel@tonic-gate #define	HOPT_GLOBAL	MNTOPT_GLOBAL
897c478bd9Sstevel@tonic-gate #define	HOPT_NOGLOBAL	MNTOPT_NOGLOBAL
907c478bd9Sstevel@tonic-gate #define	HOPT_MAPLCASE	"maplcase"
917c478bd9Sstevel@tonic-gate #define	HOPT_NOMAPLCASE	"nomaplcase"
927c478bd9Sstevel@tonic-gate #define	HOPT_NOTRAILDOT	"notraildot"
937c478bd9Sstevel@tonic-gate #define	HOPT_TRAILDOT	"traildot"
947c478bd9Sstevel@tonic-gate #define	HOPT_NRR	"nrr"
957c478bd9Sstevel@tonic-gate #define	HOPT_RR		"rr"
96fc1c62b8Sfrankho #define	HOPT_JOLIET	"joliet"
97fc1c62b8Sfrankho #define	HOPT_NOJOLIET	"nojoliet"
98fc1c62b8Sfrankho #define	HOPT_JOLIETLONG	"jolietlong"
99fc1c62b8Sfrankho #define	HOPT_VERS2	"vers2"
100fc1c62b8Sfrankho #define	HOPT_NOVERS2	"novers2"
1017c478bd9Sstevel@tonic-gate #define	HOPT_RO		MNTOPT_RO
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate static char *global_cancel[] = { HOPT_NOGLOBAL, NULL };
1047c478bd9Sstevel@tonic-gate static char *noglobal_cancel[] = { HOPT_GLOBAL, NULL };
1057c478bd9Sstevel@tonic-gate static char *mapl_cancel[] = { HOPT_NOMAPLCASE, NULL };
1067c478bd9Sstevel@tonic-gate static char *nomapl_cancel[] = { HOPT_MAPLCASE, NULL };
1077c478bd9Sstevel@tonic-gate static char *ro_cancel[] = { MNTOPT_RW, NULL };
1087c478bd9Sstevel@tonic-gate static char *rr_cancel[] = { HOPT_NRR, NULL };
1097c478bd9Sstevel@tonic-gate static char *nrr_cancel[] = { HOPT_RR, NULL };
110fc1c62b8Sfrankho static char *joliet_cancel[] = { HOPT_NOJOLIET, NULL };
111fc1c62b8Sfrankho static char *nojoliet_cancel[] = { HOPT_JOLIET, NULL };
112fc1c62b8Sfrankho static char *vers2_cancel[] = { HOPT_NOVERS2, NULL };
113fc1c62b8Sfrankho static char *novers2_cancel[] = { HOPT_VERS2, NULL };
1147c478bd9Sstevel@tonic-gate static char *trail_cancel[] = { HOPT_NOTRAILDOT, NULL };
1157c478bd9Sstevel@tonic-gate static char *notrail_cancel[] = { HOPT_TRAILDOT, NULL };
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate static mntopt_t hsfs_options[] = {
1187c478bd9Sstevel@tonic-gate 	{ HOPT_GLOBAL, global_cancel, NULL, 0, NULL },
1197c478bd9Sstevel@tonic-gate 	{ HOPT_NOGLOBAL, noglobal_cancel, NULL, MO_DEFAULT, NULL },
1207c478bd9Sstevel@tonic-gate 	{ HOPT_MAPLCASE, mapl_cancel, NULL, MO_DEFAULT, NULL },
1217c478bd9Sstevel@tonic-gate 	{ HOPT_NOMAPLCASE, nomapl_cancel, NULL, 0, NULL },
1227c478bd9Sstevel@tonic-gate 	{ HOPT_RO, ro_cancel, NULL, MO_DEFAULT, NULL },
1237c478bd9Sstevel@tonic-gate 	{ HOPT_RR, rr_cancel, NULL, MO_DEFAULT, NULL },
1247c478bd9Sstevel@tonic-gate 	{ HOPT_NRR, nrr_cancel, NULL, 0, NULL },
125fc1c62b8Sfrankho 	{ HOPT_JOLIET, joliet_cancel, NULL, 0, NULL },
126fc1c62b8Sfrankho 	{ HOPT_NOJOLIET, nojoliet_cancel, NULL, 0, NULL },
127fc1c62b8Sfrankho 	{ HOPT_JOLIETLONG, NULL, NULL, 0, NULL },
128fc1c62b8Sfrankho 	{ HOPT_VERS2, vers2_cancel, NULL, 0, NULL },
129fc1c62b8Sfrankho 	{ HOPT_NOVERS2, novers2_cancel, NULL, 0, NULL },
1307c478bd9Sstevel@tonic-gate 	{ HOPT_TRAILDOT, trail_cancel, NULL, MO_DEFAULT, NULL },
1317c478bd9Sstevel@tonic-gate 	{ HOPT_NOTRAILDOT, notrail_cancel, NULL, 0, NULL },
132fc1c62b8Sfrankho 	{ "sector", NULL, "0", MO_HASVALUE, NULL},
1337c478bd9Sstevel@tonic-gate };
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate static mntopts_t hsfs_proto_opttbl = {
1367c478bd9Sstevel@tonic-gate 	sizeof (hsfs_options) / sizeof (mntopt_t),
1377c478bd9Sstevel@tonic-gate 	hsfs_options
1387c478bd9Sstevel@tonic-gate };
1397c478bd9Sstevel@tonic-gate 
14084b82766Smg /*
14184b82766Smg  * Indicates whether to enable the I/O scheduling and readahead logic
14284b82766Smg  * 1 - Enable, 0 - Do not Enable.
14384b82766Smg  * Debugging purposes.
14484b82766Smg  */
14584b82766Smg int do_schedio = 1;
146fc1c62b8Sfrankho static int hsfsfstype;
1477c478bd9Sstevel@tonic-gate static int hsfsinit(int, char *);
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate static vfsdef_t vfw = {
1507c478bd9Sstevel@tonic-gate 	VFSDEF_VERSION,
1517c478bd9Sstevel@tonic-gate 	"hsfs",
1527c478bd9Sstevel@tonic-gate 	hsfsinit,
15343d5cd3dSjohnlev 	/* We don't suppport remounting */
154d9a54dd1SSebastien Roy 	VSW_HASPROTO|VSW_STATS|VSW_CANLOFI|VSW_MOUNTDEV,
1557c478bd9Sstevel@tonic-gate 	&hsfs_proto_opttbl
1567c478bd9Sstevel@tonic-gate };
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate static struct modlfs modlfs = {
1597c478bd9Sstevel@tonic-gate 	&mod_fsops, "filesystem for HSFS", &vfw
1607c478bd9Sstevel@tonic-gate };
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
1637c478bd9Sstevel@tonic-gate 	MODREV_1, (void *)&modlfs, NULL
1647c478bd9Sstevel@tonic-gate };
1657c478bd9Sstevel@tonic-gate 
16684b82766Smg extern void hsched_init_caches(void);
16784b82766Smg extern void hsched_fini_caches(void);
16884b82766Smg 
16984b82766Smg 
1707c478bd9Sstevel@tonic-gate int
_init(void)171fc1c62b8Sfrankho _init(void)
1727c478bd9Sstevel@tonic-gate {
1737c478bd9Sstevel@tonic-gate 	return (mod_install(&modlinkage));
1747c478bd9Sstevel@tonic-gate }
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate int
_fini(void)177fc1c62b8Sfrankho _fini(void)
1787c478bd9Sstevel@tonic-gate {
179fc1c62b8Sfrankho 	int	error;
180fc1c62b8Sfrankho 
181fc1c62b8Sfrankho 	error = mod_remove(&modlinkage);
182fc1c62b8Sfrankho 
183fc1c62b8Sfrankho 	DTRACE_PROBE1(mod_remove, int, error);
184fc1c62b8Sfrankho 
185fc1c62b8Sfrankho 	if (error)
186fc1c62b8Sfrankho 		return (error);
187fc1c62b8Sfrankho 
188fc1c62b8Sfrankho 	mutex_destroy(&hs_mounttab_lock);
189fc1c62b8Sfrankho 
190fc1c62b8Sfrankho 	/*
191fc1c62b8Sfrankho 	 * Tear down the operations vectors
192fc1c62b8Sfrankho 	 */
193fc1c62b8Sfrankho 	(void) vfs_freevfsops_by_type(hsfsfstype);
194fc1c62b8Sfrankho 	vn_freevnodeops(hsfs_vnodeops);
195fc1c62b8Sfrankho 
196fc1c62b8Sfrankho 	hs_fini_hsnode_cache();
19784b82766Smg 	hsched_fini_caches();
198fc1c62b8Sfrankho 	return (0);
1997c478bd9Sstevel@tonic-gate }
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)2027c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
2037c478bd9Sstevel@tonic-gate {
2047c478bd9Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
2057c478bd9Sstevel@tonic-gate }
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate #define	BDEVFLAG(dev)	((devopsp[getmajor(dev)])->devo_cb_ops->cb_flag)
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate kmutex_t hs_mounttab_lock;
2107c478bd9Sstevel@tonic-gate struct hsfs *hs_mounttab = NULL;
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate /* default mode, uid, gid */
2137c478bd9Sstevel@tonic-gate mode_t hsfs_default_mode = 0555;
2147c478bd9Sstevel@tonic-gate uid_t hsfs_default_uid = 0;
2157c478bd9Sstevel@tonic-gate gid_t hsfs_default_gid = 3;
2167c478bd9Sstevel@tonic-gate 
21784b82766Smg extern void hsched_init(struct hsfs *fsp, int fsid,
21884b82766Smg 					struct modlinkage *modlinkage);
21984b82766Smg extern void hsched_fini(struct hsfs_queue *hqueue);
22084b82766Smg extern void hsfs_init_kstats(struct hsfs *fsp, int fsid);
22184b82766Smg extern void hsfs_fini_kstats(struct hsfs *fsp);
22284b82766Smg 
2237c478bd9Sstevel@tonic-gate static int hsfs_mount(struct vfs *vfsp, struct vnode *mvp,
2247c478bd9Sstevel@tonic-gate 	struct mounta *uap, struct cred *cr);
2257c478bd9Sstevel@tonic-gate static int hsfs_unmount(struct vfs *vfsp, int, struct cred *cr);
2267c478bd9Sstevel@tonic-gate static int hsfs_root(struct vfs *vfsp, struct vnode **vpp);
2277c478bd9Sstevel@tonic-gate static int hsfs_statvfs(struct vfs *vfsp, struct statvfs64 *sbp);
2287c478bd9Sstevel@tonic-gate static int hsfs_vget(struct vfs *vfsp, struct vnode **vpp, struct fid *fidp);
2297c478bd9Sstevel@tonic-gate static int hsfs_mountroot(struct vfs *, enum whymountroot);
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate static int hs_mountfs(struct vfs *vfsp, dev_t dev, char *path,
2327c478bd9Sstevel@tonic-gate 	mode_t mode, int flags, struct cred *cr, int isroot);
233fc1c62b8Sfrankho static int hs_getrootvp(struct vfs *vfsp, struct hsfs *fsp, size_t pathsize);
2347c478bd9Sstevel@tonic-gate static int hs_findhsvol(struct hsfs *fsp, struct vnode *vp,
2357c478bd9Sstevel@tonic-gate 	struct hs_volume *hvp);
2367c478bd9Sstevel@tonic-gate static int hs_parsehsvol(struct hsfs *fsp, uchar_t *volp,
2377c478bd9Sstevel@tonic-gate 	struct hs_volume *hvp);
2387c478bd9Sstevel@tonic-gate static int hs_findisovol(struct hsfs *fsp, struct vnode *vp,
239fc1c62b8Sfrankho 	struct hs_volume *hvp,
240fc1c62b8Sfrankho 	struct hs_volume *svp,
241fc1c62b8Sfrankho 	struct hs_volume *jvp);
242fc1c62b8Sfrankho static int hs_joliet_level(uchar_t *volp);
2437c478bd9Sstevel@tonic-gate static int hs_parseisovol(struct hsfs *fsp, uchar_t *volp,
2447c478bd9Sstevel@tonic-gate 	struct hs_volume *hvp);
245fc1c62b8Sfrankho static void hs_copylabel(struct hs_volume *, unsigned char *, int);
2467c478bd9Sstevel@tonic-gate static int hs_getmdev(struct vfs *, char *fspec, int flags, dev_t *pdev,
2477c478bd9Sstevel@tonic-gate 	mode_t *mode, cred_t *cr);
2487c478bd9Sstevel@tonic-gate static int hs_findvoldesc(dev_t rdev, int desc_sec);
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate static int
hsfsinit(int fstype,char * name)2517c478bd9Sstevel@tonic-gate hsfsinit(int fstype, char *name)
2527c478bd9Sstevel@tonic-gate {
2537c478bd9Sstevel@tonic-gate 	static const fs_operation_def_t hsfs_vfsops_template[] = {
254aa59c4cbSrsb 		VFSNAME_MOUNT,		{ .vfs_mount = hsfs_mount },
255aa59c4cbSrsb 		VFSNAME_UNMOUNT,	{ .vfs_unmount = hsfs_unmount },
256aa59c4cbSrsb 		VFSNAME_ROOT,		{ .vfs_root = hsfs_root },
257aa59c4cbSrsb 		VFSNAME_STATVFS,	{ .vfs_statvfs = hsfs_statvfs },
258aa59c4cbSrsb 		VFSNAME_VGET,		{ .vfs_vget = hsfs_vget },
259aa59c4cbSrsb 		VFSNAME_MOUNTROOT,	{ .vfs_mountroot = hsfs_mountroot },
260aa59c4cbSrsb 		NULL,			NULL
2617c478bd9Sstevel@tonic-gate 	};
2627c478bd9Sstevel@tonic-gate 	int error;
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate 	error = vfs_setfsops(fstype, hsfs_vfsops_template, NULL);
2657c478bd9Sstevel@tonic-gate 	if (error != 0) {
2667c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "hsfsinit: bad vfs ops template");
2677c478bd9Sstevel@tonic-gate 		return (error);
2687c478bd9Sstevel@tonic-gate 	}
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate 	error = vn_make_ops(name, hsfs_vnodeops_template, &hsfs_vnodeops);
2717c478bd9Sstevel@tonic-gate 	if (error != 0) {
2727c478bd9Sstevel@tonic-gate 		(void) vfs_freevfsops_by_type(fstype);
2737c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "hsfsinit: bad vnode ops template");
2747c478bd9Sstevel@tonic-gate 		return (error);
2757c478bd9Sstevel@tonic-gate 	}
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate 	hsfsfstype = fstype;
2787c478bd9Sstevel@tonic-gate 	mutex_init(&hs_mounttab_lock, NULL, MUTEX_DEFAULT, NULL);
2797c478bd9Sstevel@tonic-gate 	hs_init_hsnode_cache();
28084b82766Smg 	hsched_init_caches();
2817c478bd9Sstevel@tonic-gate 	return (0);
2827c478bd9Sstevel@tonic-gate }
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2857c478bd9Sstevel@tonic-gate static int
hsfs_mount(struct vfs * vfsp,struct vnode * mvp,struct mounta * uap,struct cred * cr)2867c478bd9Sstevel@tonic-gate hsfs_mount(struct vfs *vfsp, struct vnode *mvp,
2877c478bd9Sstevel@tonic-gate     struct mounta *uap, struct cred *cr)
2887c478bd9Sstevel@tonic-gate {
2897c478bd9Sstevel@tonic-gate 	int		vnode_busy;
2907c478bd9Sstevel@tonic-gate 	dev_t		dev;
2917c478bd9Sstevel@tonic-gate 	struct pathname dpn;
2927c478bd9Sstevel@tonic-gate 	int		error;
2937c478bd9Sstevel@tonic-gate 	mode_t		mode;
2947c478bd9Sstevel@tonic-gate 	int		flags;	/* this will hold the mount specific data */
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate 	if ((error = secpolicy_fs_mount(cr, mvp, vfsp)) != 0)
2977c478bd9Sstevel@tonic-gate 		return (error);
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate 	if (mvp->v_type != VDIR)
3007c478bd9Sstevel@tonic-gate 		return (ENOTDIR);
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate 	/* mount option must be read only, else mount will be rejected */
3037c478bd9Sstevel@tonic-gate 	if (!(uap->flags & MS_RDONLY))
3047c478bd9Sstevel@tonic-gate 		return (EROFS);
3057c478bd9Sstevel@tonic-gate 
3067c478bd9Sstevel@tonic-gate 	/*
3077c478bd9Sstevel@tonic-gate 	 * We already told the framework that we don't support remounting.
3087c478bd9Sstevel@tonic-gate 	 */
3097c478bd9Sstevel@tonic-gate 	ASSERT(!(uap->flags & MS_REMOUNT));
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate 	mutex_enter(&mvp->v_lock);
3127c478bd9Sstevel@tonic-gate 	vnode_busy = (mvp->v_count != 1) || (mvp->v_flag & VROOT);
3137c478bd9Sstevel@tonic-gate 	mutex_exit(&mvp->v_lock);
3147c478bd9Sstevel@tonic-gate 
3157c478bd9Sstevel@tonic-gate 	if ((uap->flags & MS_OVERLAY) == 0 && vnode_busy) {
3167c478bd9Sstevel@tonic-gate 		return (EBUSY);
3177c478bd9Sstevel@tonic-gate 	}
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate 	/*
3207c478bd9Sstevel@tonic-gate 	 * Check for the options that actually affect things
3217c478bd9Sstevel@tonic-gate 	 * at our level.
3227c478bd9Sstevel@tonic-gate 	 */
3237c478bd9Sstevel@tonic-gate 	flags = 0;
3247c478bd9Sstevel@tonic-gate 	if (vfs_optionisset(vfsp, HOPT_NOMAPLCASE, NULL))
325d10b6702Sfrankho 		flags |= HSFSMNT_NOMAPLCASE;
3267c478bd9Sstevel@tonic-gate 	if (vfs_optionisset(vfsp, HOPT_NOTRAILDOT, NULL))
327d10b6702Sfrankho 		flags |= HSFSMNT_NOTRAILDOT;
3287c478bd9Sstevel@tonic-gate 	if (vfs_optionisset(vfsp, HOPT_NRR, NULL))
329d10b6702Sfrankho 		flags |= HSFSMNT_NORRIP;
330fc1c62b8Sfrankho 	if (vfs_optionisset(vfsp, HOPT_NOJOLIET, NULL))
331d10b6702Sfrankho 		flags |= HSFSMNT_NOJOLIET;
332fc1c62b8Sfrankho 	if (vfs_optionisset(vfsp, HOPT_JOLIETLONG, NULL))
333d10b6702Sfrankho 		flags |= HSFSMNT_JOLIETLONG;
334fc1c62b8Sfrankho 	if (vfs_optionisset(vfsp, HOPT_NOVERS2, NULL))
335d10b6702Sfrankho 		flags |= HSFSMNT_NOVERS2;
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate 	error = pn_get(uap->dir, (uap->flags & MS_SYSSPACE) ?
3387c478bd9Sstevel@tonic-gate 	    UIO_SYSSPACE : UIO_USERSPACE, &dpn);
3397c478bd9Sstevel@tonic-gate 	if (error)
3407c478bd9Sstevel@tonic-gate 		return (error);
3417c478bd9Sstevel@tonic-gate 
342d10b6702Sfrankho 	error = hs_getmdev(vfsp, uap->spec, uap->flags, &dev, &mode, cr);
343d10b6702Sfrankho 	if (error != 0) {
3447c478bd9Sstevel@tonic-gate 		pn_free(&dpn);
3457c478bd9Sstevel@tonic-gate 		return (error);
3467c478bd9Sstevel@tonic-gate 	}
3477c478bd9Sstevel@tonic-gate 
3487c478bd9Sstevel@tonic-gate 	/*
3497c478bd9Sstevel@tonic-gate 	 * If the device is a tape, return error
3507c478bd9Sstevel@tonic-gate 	 */
3517c478bd9Sstevel@tonic-gate 	if ((BDEVFLAG(dev) & D_TAPE) == D_TAPE)  {
3527c478bd9Sstevel@tonic-gate 		pn_free(&dpn);
3537c478bd9Sstevel@tonic-gate 		return (ENOTBLK);
3547c478bd9Sstevel@tonic-gate 	}
3557c478bd9Sstevel@tonic-gate 
3567c478bd9Sstevel@tonic-gate 	/*
3577c478bd9Sstevel@tonic-gate 	 * Mount the filesystem.
3587c478bd9Sstevel@tonic-gate 	 */
3597c478bd9Sstevel@tonic-gate 	error = hs_mountfs(vfsp, dev, dpn.pn_path, mode, flags, cr, 0);
3607c478bd9Sstevel@tonic-gate 	pn_free(&dpn);
3617c478bd9Sstevel@tonic-gate 	return (error);
3627c478bd9Sstevel@tonic-gate }
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3657c478bd9Sstevel@tonic-gate static int
hsfs_unmount(struct vfs * vfsp,int flag,struct cred * cr)3667c478bd9Sstevel@tonic-gate hsfs_unmount(
3677c478bd9Sstevel@tonic-gate 	struct vfs *vfsp,
3687c478bd9Sstevel@tonic-gate 	int flag,
3697c478bd9Sstevel@tonic-gate 	struct cred *cr)
3707c478bd9Sstevel@tonic-gate {
3717c478bd9Sstevel@tonic-gate 	struct hsfs **tspp;
3727c478bd9Sstevel@tonic-gate 	struct hsfs *fsp;
3737c478bd9Sstevel@tonic-gate 
3747c478bd9Sstevel@tonic-gate 	if (secpolicy_fs_unmount(cr, vfsp) != 0)
3757c478bd9Sstevel@tonic-gate 		return (EPERM);
3767c478bd9Sstevel@tonic-gate 
3777c478bd9Sstevel@tonic-gate 	/*
3787c478bd9Sstevel@tonic-gate 	 * forced unmount is not supported by this file system
3797c478bd9Sstevel@tonic-gate 	 * and thus, ENOTSUP is being returned.
3807c478bd9Sstevel@tonic-gate 	 */
3817c478bd9Sstevel@tonic-gate 	if (flag & MS_FORCE)
3827c478bd9Sstevel@tonic-gate 		return (ENOTSUP);
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate 	fsp = VFS_TO_HSFS(vfsp);
3857c478bd9Sstevel@tonic-gate 
3867c478bd9Sstevel@tonic-gate 	if (fsp->hsfs_rootvp->v_count != 1)
3877c478bd9Sstevel@tonic-gate 		return (EBUSY);
3887c478bd9Sstevel@tonic-gate 
3897c478bd9Sstevel@tonic-gate 	/* destroy all old pages and hsnodes for this vfs */
3907c478bd9Sstevel@tonic-gate 	if (hs_synchash(vfsp))
3917c478bd9Sstevel@tonic-gate 		return (EBUSY);
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate 	mutex_enter(&hs_mounttab_lock);
3947c478bd9Sstevel@tonic-gate 	for (tspp = &hs_mounttab; *tspp != NULL; tspp = &(*tspp)->hsfs_next) {
3957c478bd9Sstevel@tonic-gate 		if (*tspp == fsp)
3967c478bd9Sstevel@tonic-gate 			break;
3977c478bd9Sstevel@tonic-gate 	}
3987c478bd9Sstevel@tonic-gate 	if (*tspp == NULL) {
3997c478bd9Sstevel@tonic-gate 		mutex_exit(&hs_mounttab_lock);
4007c478bd9Sstevel@tonic-gate 		panic("hsfs_unmount: vfs not mounted?");
4017c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
4027c478bd9Sstevel@tonic-gate 	}
4037c478bd9Sstevel@tonic-gate 
4047c478bd9Sstevel@tonic-gate 	*tspp = fsp->hsfs_next;
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate 	mutex_exit(&hs_mounttab_lock);
4077c478bd9Sstevel@tonic-gate 
40884b82766Smg 	hsfs_fini_kstats(fsp);
409da6c28aaSamw 	(void) VOP_CLOSE(fsp->hsfs_devvp, FREAD, 1, (offset_t)0, cr, NULL);
4107c478bd9Sstevel@tonic-gate 	VN_RELE(fsp->hsfs_devvp);
4117c478bd9Sstevel@tonic-gate 	/* free path table space */
4127c478bd9Sstevel@tonic-gate 	if (fsp->hsfs_ptbl != NULL)
413d10b6702Sfrankho 		kmem_free(fsp->hsfs_ptbl, (size_t)fsp->hsfs_vol.ptbl_len);
4147c478bd9Sstevel@tonic-gate 	/* free path table index table */
4157c478bd9Sstevel@tonic-gate 	if (fsp->hsfs_ptbl_idx != NULL)
4167c478bd9Sstevel@tonic-gate 		kmem_free(fsp->hsfs_ptbl_idx, (size_t)
417d10b6702Sfrankho 		    (fsp->hsfs_ptbl_idx_size * sizeof (struct ptable_idx)));
4187c478bd9Sstevel@tonic-gate 
4197c478bd9Sstevel@tonic-gate 	/* free "mounted on" pathame */
4207c478bd9Sstevel@tonic-gate 	if (fsp->hsfs_fsmnt != NULL)
4217c478bd9Sstevel@tonic-gate 		kmem_free(fsp->hsfs_fsmnt, strlen(fsp->hsfs_fsmnt) + 1);
4227c478bd9Sstevel@tonic-gate 
42384b82766Smg 	hsched_fini(fsp->hqueue);
42484b82766Smg 	kmem_free(fsp->hqueue, sizeof (struct hsfs_queue));
42584b82766Smg 
4267c478bd9Sstevel@tonic-gate 	mutex_destroy(&fsp->hsfs_free_lock);
4277c478bd9Sstevel@tonic-gate 	rw_destroy(&fsp->hsfs_hash_lock);
4287c478bd9Sstevel@tonic-gate 
4297c478bd9Sstevel@tonic-gate 	kmem_free(fsp, sizeof (*fsp));
4307c478bd9Sstevel@tonic-gate 	return (0);
4317c478bd9Sstevel@tonic-gate }
4327c478bd9Sstevel@tonic-gate 
4337c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4347c478bd9Sstevel@tonic-gate static int
hsfs_root(struct vfs * vfsp,struct vnode ** vpp)4357c478bd9Sstevel@tonic-gate hsfs_root(struct vfs *vfsp, struct vnode **vpp)
4367c478bd9Sstevel@tonic-gate {
4377c478bd9Sstevel@tonic-gate 	*vpp = (VFS_TO_HSFS(vfsp))->hsfs_rootvp;
4387c478bd9Sstevel@tonic-gate 	VN_HOLD(*vpp);
4397c478bd9Sstevel@tonic-gate 	return (0);
4407c478bd9Sstevel@tonic-gate }
4417c478bd9Sstevel@tonic-gate 
4427c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4437c478bd9Sstevel@tonic-gate static int
hsfs_statvfs(struct vfs * vfsp,struct statvfs64 * sbp)4447c478bd9Sstevel@tonic-gate hsfs_statvfs(struct vfs *vfsp, struct statvfs64 *sbp)
4457c478bd9Sstevel@tonic-gate {
4467c478bd9Sstevel@tonic-gate 	struct hsfs *fsp;
4477c478bd9Sstevel@tonic-gate 	dev32_t d32;
4487c478bd9Sstevel@tonic-gate 
4497c478bd9Sstevel@tonic-gate 	fsp = VFS_TO_HSFS(vfsp);
4507c478bd9Sstevel@tonic-gate 	if (fsp->hsfs_magic != HSFS_MAGIC)
4517c478bd9Sstevel@tonic-gate 		return (EINVAL);
4527c478bd9Sstevel@tonic-gate 	bzero(sbp, sizeof (*sbp));
4537c478bd9Sstevel@tonic-gate 	sbp->f_bsize = vfsp->vfs_bsize;
4547c478bd9Sstevel@tonic-gate 	sbp->f_frsize = sbp->f_bsize; /* no fragment, same as block size */
4557c478bd9Sstevel@tonic-gate 	sbp->f_blocks = (fsblkcnt64_t)fsp->hsfs_vol.vol_size;
4567c478bd9Sstevel@tonic-gate 
4577c478bd9Sstevel@tonic-gate 	sbp->f_bfree = (fsblkcnt64_t)0;
4587c478bd9Sstevel@tonic-gate 	sbp->f_bavail = (fsblkcnt64_t)0;
4597c478bd9Sstevel@tonic-gate 	sbp->f_files = (fsfilcnt64_t)-1;
4607c478bd9Sstevel@tonic-gate 	sbp->f_ffree = (fsfilcnt64_t)0;
4617c478bd9Sstevel@tonic-gate 	sbp->f_favail = (fsfilcnt64_t)0;
4627c478bd9Sstevel@tonic-gate 	(void) cmpldev(&d32, vfsp->vfs_dev);
4637c478bd9Sstevel@tonic-gate 	sbp->f_fsid = d32;
4647c478bd9Sstevel@tonic-gate 	(void) strcpy(sbp->f_basetype, vfssw[vfsp->vfs_fstype].vsw_name);
4657c478bd9Sstevel@tonic-gate 	sbp->f_flag = vf_to_stf(vfsp->vfs_flag);
4667c478bd9Sstevel@tonic-gate 	sbp->f_namemax = fsp->hsfs_namemax;
4677c478bd9Sstevel@tonic-gate 	(void) strcpy(sbp->f_fstr, fsp->hsfs_vol.vol_id);
4687c478bd9Sstevel@tonic-gate 
4697c478bd9Sstevel@tonic-gate 	return (0);
4707c478bd9Sstevel@tonic-gate }
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate /*
4737c478bd9Sstevel@tonic-gate  * Previously nodeid was declared as uint32_t. This has been changed
4747c478bd9Sstevel@tonic-gate  * to conform better with the ISO9660 standard. The standard states that
4757c478bd9Sstevel@tonic-gate  * a LBN can be a 32 bit number, as the MAKE_NODEID macro shifts this
4767c478bd9Sstevel@tonic-gate  * LBN 11 places left (LBN_TO_BYTE) and then shifts the result 5 right
4777c478bd9Sstevel@tonic-gate  * (divide by 32) we are left with the potential of an overflow if
4787c478bd9Sstevel@tonic-gate  * confined to a 32 bit value.
4797c478bd9Sstevel@tonic-gate  */
4807c478bd9Sstevel@tonic-gate 
4817c478bd9Sstevel@tonic-gate static int
hsfs_vget(struct vfs * vfsp,struct vnode ** vpp,struct fid * fidp)4827c478bd9Sstevel@tonic-gate hsfs_vget(struct vfs *vfsp, struct vnode **vpp, struct fid *fidp)
4837c478bd9Sstevel@tonic-gate {
4847c478bd9Sstevel@tonic-gate 	struct hsfid *fid;
4857c478bd9Sstevel@tonic-gate 	struct hsfs *fsp;
4867c478bd9Sstevel@tonic-gate 	ino64_t nodeid;
4877c478bd9Sstevel@tonic-gate 	int error;
4887c478bd9Sstevel@tonic-gate 
4897c478bd9Sstevel@tonic-gate 	fsp = (struct hsfs *)VFS_TO_HSFS(vfsp);
4907c478bd9Sstevel@tonic-gate 	fid = (struct hsfid *)fidp;
4917c478bd9Sstevel@tonic-gate 
4927c478bd9Sstevel@tonic-gate 	/*
4937c478bd9Sstevel@tonic-gate 	 * Look for vnode on hashlist.
4947c478bd9Sstevel@tonic-gate 	 * If found, it's now active and the refcnt was incremented.
4957c478bd9Sstevel@tonic-gate 	 */
4967c478bd9Sstevel@tonic-gate 
4977c478bd9Sstevel@tonic-gate 	rw_enter(&fsp->hsfs_hash_lock, RW_READER);
4987c478bd9Sstevel@tonic-gate 
499d10b6702Sfrankho 	nodeid = fid->hf_ino;
5007c478bd9Sstevel@tonic-gate 
501d10b6702Sfrankho 	if ((*vpp = hs_findhash(nodeid, fid->hf_dir_lbn,
502d10b6702Sfrankho 	    (uint_t)fid->hf_dir_off, vfsp)) == NULL) {
5037c478bd9Sstevel@tonic-gate 		/*
5047c478bd9Sstevel@tonic-gate 		 * Not in cache, so we need to remake it.
5057c478bd9Sstevel@tonic-gate 		 * hs_remakenode() will read the directory entry
5067c478bd9Sstevel@tonic-gate 		 * and then check again to see if anyone else has
5077c478bd9Sstevel@tonic-gate 		 * put it in the cache.
5087c478bd9Sstevel@tonic-gate 		 */
5097c478bd9Sstevel@tonic-gate 		rw_exit(&fsp->hsfs_hash_lock);
5107c478bd9Sstevel@tonic-gate 		error = hs_remakenode(fid->hf_dir_lbn, (uint_t)fid->hf_dir_off,
5117c478bd9Sstevel@tonic-gate 		    vfsp, vpp);
5127c478bd9Sstevel@tonic-gate 		return (error);
5137c478bd9Sstevel@tonic-gate 	}
5147c478bd9Sstevel@tonic-gate 	rw_exit(&fsp->hsfs_hash_lock);
5157c478bd9Sstevel@tonic-gate 	return (0);
5167c478bd9Sstevel@tonic-gate }
5177c478bd9Sstevel@tonic-gate 
5187c478bd9Sstevel@tonic-gate 
5197c478bd9Sstevel@tonic-gate #define	CHECKSUM_SIZE				(64 * 1024)
5207c478bd9Sstevel@tonic-gate 
5217c478bd9Sstevel@tonic-gate /*
5227c478bd9Sstevel@tonic-gate  * Compute a CD-ROM fsid by checksumming the first 64K of data on the CD
5237c478bd9Sstevel@tonic-gate  * We use the 'fsp' argument to determine the location of the root
5247c478bd9Sstevel@tonic-gate  * directory entry, and we start reading from there.
5257c478bd9Sstevel@tonic-gate  */
5267c478bd9Sstevel@tonic-gate static int
compute_cdrom_id(struct hsfs * fsp,vnode_t * devvp)5277c478bd9Sstevel@tonic-gate compute_cdrom_id(struct hsfs *fsp, vnode_t *devvp)
5287c478bd9Sstevel@tonic-gate {
5297c478bd9Sstevel@tonic-gate 	uint_t		secno;
5307c478bd9Sstevel@tonic-gate 	struct hs_volume *hsvp = &fsp->hsfs_vol;
5317c478bd9Sstevel@tonic-gate 	struct buf	*bp;
5327c478bd9Sstevel@tonic-gate 	int		error;
5337c478bd9Sstevel@tonic-gate 	int		fsid;
5347c478bd9Sstevel@tonic-gate 
5357c478bd9Sstevel@tonic-gate 	secno = hsvp->root_dir.ext_lbn >> hsvp->lbn_secshift;
536cf83459aSfrankho 	bp = bread(devvp->v_rdev, secno * 4, CHECKSUM_SIZE);
5377c478bd9Sstevel@tonic-gate 	error = geterror(bp);
538cf83459aSfrankho 
539cf83459aSfrankho 	/*
540cf83459aSfrankho 	 * An error on read or a partial read means we asked
541cf83459aSfrankho 	 * for a nonexistant/corrupted piece of the device
542cf83459aSfrankho 	 * (including past-the-end of the media). Don't
543cf83459aSfrankho 	 * try to use the checksumming method then.
544cf83459aSfrankho 	 */
545cf83459aSfrankho 	if (!error && bp->b_bcount == CHECKSUM_SIZE) {
5467c478bd9Sstevel@tonic-gate 		int *ibuf = (int *)bp->b_un.b_addr;
5477c478bd9Sstevel@tonic-gate 		int i;
5487c478bd9Sstevel@tonic-gate 
5497c478bd9Sstevel@tonic-gate 		fsid = 0;
5507c478bd9Sstevel@tonic-gate 
551cf83459aSfrankho 		for (i = 0; i < CHECKSUM_SIZE / sizeof (int); i++)
5527c478bd9Sstevel@tonic-gate 			fsid ^= ibuf[ i ];
553cf83459aSfrankho 	} else {
554cf83459aSfrankho 		/*
555cf83459aSfrankho 		 * Fallback - use creation date
556cf83459aSfrankho 		 */
5577c478bd9Sstevel@tonic-gate 		fsid = hsvp->cre_date.tv_sec;
558cf83459aSfrankho 	}
5597c478bd9Sstevel@tonic-gate 
5607c478bd9Sstevel@tonic-gate 	brelse(bp);
5617c478bd9Sstevel@tonic-gate 
5627c478bd9Sstevel@tonic-gate 	return (fsid);
5637c478bd9Sstevel@tonic-gate }
5647c478bd9Sstevel@tonic-gate 
5657c478bd9Sstevel@tonic-gate 
5667c478bd9Sstevel@tonic-gate /*ARGSUSED*/
5677c478bd9Sstevel@tonic-gate static int
hs_mountfs(struct vfs * vfsp,dev_t dev,char * path,mode_t mode,int mount_flags,struct cred * cr,int isroot)5687c478bd9Sstevel@tonic-gate hs_mountfs(
5697c478bd9Sstevel@tonic-gate 	struct vfs	*vfsp,
5707c478bd9Sstevel@tonic-gate 	dev_t		dev,
5717c478bd9Sstevel@tonic-gate 	char		*path,
5727c478bd9Sstevel@tonic-gate 	mode_t		mode,
5737c478bd9Sstevel@tonic-gate 	int		mount_flags,
5747c478bd9Sstevel@tonic-gate 	struct cred	*cr,
5757c478bd9Sstevel@tonic-gate 	int		isroot)
5767c478bd9Sstevel@tonic-gate {
5777c478bd9Sstevel@tonic-gate 	struct vnode	*devvp;
5787c478bd9Sstevel@tonic-gate 	struct hsfs	*tsp;
5797c478bd9Sstevel@tonic-gate 	struct hsfs	*fsp = NULL;
5807c478bd9Sstevel@tonic-gate 	struct vattr	vap;
5817c478bd9Sstevel@tonic-gate 	struct hsnode	*hp;
5827c478bd9Sstevel@tonic-gate 	int		error;
5837c478bd9Sstevel@tonic-gate 	struct timeval	tv;
5847c478bd9Sstevel@tonic-gate 	int		fsid;
585fc1c62b8Sfrankho 	int		use_rrip;
586fc1c62b8Sfrankho 	int		use_vers2;
587fc1c62b8Sfrankho 	int		use_joliet;
588fc1c62b8Sfrankho 	int		has_rrip = 0;
589fc1c62b8Sfrankho 	int		has_vers2 = 0;
590fc1c62b8Sfrankho 	int		has_joliet = 0;
591fc1c62b8Sfrankho 	int		force_rrip_off;
592fc1c62b8Sfrankho 	int		force_vers2_off;
593fc1c62b8Sfrankho 	int		force_joliet_off;
594fc1c62b8Sfrankho 	size_t		pathbufsz = strlen(path) + 1;
595fc1c62b8Sfrankho 	int		redo_rootvp;
596fc1c62b8Sfrankho 
59776a4d1fdSdanmcd 	struct hs_volume *svp = NULL;	/* Supplemental VD for ISO-9660:1999 */
59876a4d1fdSdanmcd 	struct hs_volume *jvp = NULL;	/* Joliet VD */
599fc1c62b8Sfrankho 
600fc1c62b8Sfrankho 	/*
601fc1c62b8Sfrankho 	 * The rules for which extension will be used are:
602fc1c62b8Sfrankho 	 * 1. No specific mount options given:
603fc1c62b8Sfrankho 	 *	- use rrip if available
604fc1c62b8Sfrankho 	 *	- use ISO9660:1999 if available
605fc1c62b8Sfrankho 	 *	- use joliet if available.
606fc1c62b8Sfrankho 	 * 2. rrip/ISO9660:1999/joliet explicitly disabled via mount option:
607fc1c62b8Sfrankho 	 *	- use next "lower" extension
608fc1c62b8Sfrankho 	 * 3. joliet/ISO9660:1999/rrip explicitly requested via mount option:
609fc1c62b8Sfrankho 	 *	- disable rrip support even if available
610fc1c62b8Sfrankho 	 *	- disable IOS9660:1999 support even if available
611fc1c62b8Sfrankho 	 *
612fc1c62b8Sfrankho 	 * We need to adjust these flags as we discover the extensions
613fc1c62b8Sfrankho 	 * present. See below. These are just the starting values.
614fc1c62b8Sfrankho 	 */
615fc1c62b8Sfrankho 	use_rrip = (mount_flags & HSFSMNT_NORRIP) == 0;
616fc1c62b8Sfrankho 	use_vers2 = (mount_flags & HSFSMNT_NOVERS2) == 0;
617fc1c62b8Sfrankho 	use_joliet = (mount_flags & HSFSMNT_NOJOLIET) == 0;
6187c478bd9Sstevel@tonic-gate 
6197c478bd9Sstevel@tonic-gate 	/*
6207c478bd9Sstevel@tonic-gate 	 * Open the device
6217c478bd9Sstevel@tonic-gate 	 */
6227c478bd9Sstevel@tonic-gate 	devvp = makespecvp(dev, VBLK);
6237c478bd9Sstevel@tonic-gate 	ASSERT(devvp != 0);
6247c478bd9Sstevel@tonic-gate 
6257c478bd9Sstevel@tonic-gate 	/*
6267c478bd9Sstevel@tonic-gate 	 * Open the target device (file) for read only.
6277c478bd9Sstevel@tonic-gate 	 */
628da6c28aaSamw 	if (error = VOP_OPEN(&devvp, FREAD, cr, NULL)) {
6297c478bd9Sstevel@tonic-gate 		VN_RELE(devvp);
6307c478bd9Sstevel@tonic-gate 		return (error);
6317c478bd9Sstevel@tonic-gate 	}
6327c478bd9Sstevel@tonic-gate 
6337c478bd9Sstevel@tonic-gate 	/*
6347c478bd9Sstevel@tonic-gate 	 * Refuse to go any further if this
6357c478bd9Sstevel@tonic-gate 	 * device is being used for swapping
6367c478bd9Sstevel@tonic-gate 	 */
6377c478bd9Sstevel@tonic-gate 	if (IS_SWAPVP(common_specvp(devvp))) {
6387c478bd9Sstevel@tonic-gate 		error = EBUSY;
6397c478bd9Sstevel@tonic-gate 		goto cleanup;
6407c478bd9Sstevel@tonic-gate 	}
6417c478bd9Sstevel@tonic-gate 
6427c478bd9Sstevel@tonic-gate 	vap.va_mask = AT_SIZE;
643da6c28aaSamw 	if ((error = VOP_GETATTR(devvp, &vap, ATTR_COMM, cr, NULL)) != 0) {
6447c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "Cannot get attributes of the CD-ROM driver");
6457c478bd9Sstevel@tonic-gate 		goto cleanup;
6467c478bd9Sstevel@tonic-gate 	}
6477c478bd9Sstevel@tonic-gate 
6487c478bd9Sstevel@tonic-gate 	/*
6497c478bd9Sstevel@tonic-gate 	 * Make sure we have a nonzero size partition.
6507c478bd9Sstevel@tonic-gate 	 * The current version of the SD driver will *not* fail the open
6517c478bd9Sstevel@tonic-gate 	 * of such a partition so we have to check for it here.
6527c478bd9Sstevel@tonic-gate 	 */
6537c478bd9Sstevel@tonic-gate 	if (vap.va_size == 0) {
6547c478bd9Sstevel@tonic-gate 		error = ENXIO;
6557c478bd9Sstevel@tonic-gate 		goto cleanup;
6567c478bd9Sstevel@tonic-gate 	}
6577c478bd9Sstevel@tonic-gate 
6587c478bd9Sstevel@tonic-gate 	/*
6597c478bd9Sstevel@tonic-gate 	 * Init a new hsfs structure.
6607c478bd9Sstevel@tonic-gate 	 */
6617c478bd9Sstevel@tonic-gate 	fsp = kmem_zalloc(sizeof (*fsp), KM_SLEEP);
662fc1c62b8Sfrankho 	svp = kmem_zalloc(sizeof (*svp), KM_SLEEP);
663fc1c62b8Sfrankho 	jvp = kmem_zalloc(sizeof (*jvp), KM_SLEEP);
6647c478bd9Sstevel@tonic-gate 
6657c478bd9Sstevel@tonic-gate 	/* hardwire perms, uid, gid */
6667c478bd9Sstevel@tonic-gate 	fsp->hsfs_vol.vol_uid = hsfs_default_uid;
6677c478bd9Sstevel@tonic-gate 	fsp->hsfs_vol.vol_gid =  hsfs_default_gid;
6687c478bd9Sstevel@tonic-gate 	fsp->hsfs_vol.vol_prot = hsfs_default_mode;
669fc1c62b8Sfrankho 	svp->vol_uid = hsfs_default_uid;
670fc1c62b8Sfrankho 	svp->vol_gid =  hsfs_default_gid;
671fc1c62b8Sfrankho 	svp->vol_prot = hsfs_default_mode;
672fc1c62b8Sfrankho 	jvp->vol_uid = hsfs_default_uid;
673fc1c62b8Sfrankho 	jvp->vol_gid =  hsfs_default_gid;
674fc1c62b8Sfrankho 	jvp->vol_prot = hsfs_default_mode;
6757c478bd9Sstevel@tonic-gate 
6767c478bd9Sstevel@tonic-gate 	/*
6777c478bd9Sstevel@tonic-gate 	 * Look for a Standard File Structure Volume Descriptor,
6787c478bd9Sstevel@tonic-gate 	 * of which there must be at least one.
6797c478bd9Sstevel@tonic-gate 	 * If found, check for volume size consistency.
680fc1c62b8Sfrankho 	 *
681fc1c62b8Sfrankho 	 * If svp->lbn_size is != 0, we did find a ISO-9660:1999 SVD
682fc1c62b8Sfrankho 	 * If jvp->lbn_size is != 0, we did find a Joliet SVD.
6837c478bd9Sstevel@tonic-gate 	 */
684fc1c62b8Sfrankho 	fsp->hsfs_namemax = ISO_FILE_NAMELEN;
685fc1c62b8Sfrankho 	fsp->hsfs_namelen = ISO_FILE_NAMELEN;
686fc1c62b8Sfrankho 	error = hs_findisovol(fsp, devvp, &fsp->hsfs_vol, svp, jvp);
68754e0249cSfrankho 	if (error == EINVAL) /* no iso 9660 - try high sierra ... */
68854e0249cSfrankho 		error = hs_findhsvol(fsp, devvp, &fsp->hsfs_vol);
6897c478bd9Sstevel@tonic-gate 
6907c478bd9Sstevel@tonic-gate 	if (error)
6917c478bd9Sstevel@tonic-gate 		goto cleanup;
6927c478bd9Sstevel@tonic-gate 
693fc1c62b8Sfrankho 	DTRACE_PROBE4(findvol,
694fc1c62b8Sfrankho 	    struct hsfs *, fsp,
695fc1c62b8Sfrankho 	    struct hs_volume *, &fsp->hsfs_vol,
696fc1c62b8Sfrankho 	    struct hs_volume *, svp,
697fc1c62b8Sfrankho 	    struct hs_volume *, jvp);
698fc1c62b8Sfrankho 
6997c478bd9Sstevel@tonic-gate 	/*
7007c478bd9Sstevel@tonic-gate 	 * Generate a file system ID from the CD-ROM,
7017c478bd9Sstevel@tonic-gate 	 * and check it for uniqueness.
7027c478bd9Sstevel@tonic-gate 	 *
7037c478bd9Sstevel@tonic-gate 	 * What we are aiming for is some chance of integrity
7047c478bd9Sstevel@tonic-gate 	 * across disk change.  That is, if a client has an fhandle,
7057c478bd9Sstevel@tonic-gate 	 * it will be valid as long as the same disk is mounted.
7067c478bd9Sstevel@tonic-gate 	 */
7077c478bd9Sstevel@tonic-gate 	fsid = compute_cdrom_id(fsp, devvp);
7087c478bd9Sstevel@tonic-gate 
7097c478bd9Sstevel@tonic-gate 	mutex_enter(&hs_mounttab_lock);
7107c478bd9Sstevel@tonic-gate 
7117c478bd9Sstevel@tonic-gate 	if (fsid == 0 || fsid == -1) {
7127c478bd9Sstevel@tonic-gate 		uniqtime(&tv);
7137c478bd9Sstevel@tonic-gate 		fsid = tv.tv_sec;
7147c478bd9Sstevel@tonic-gate 	} else	/* make sure that the fsid is unique */
7157c478bd9Sstevel@tonic-gate 		for (tsp = hs_mounttab; tsp != NULL; tsp = tsp->hsfs_next) {
7167c478bd9Sstevel@tonic-gate 			if (fsid == tsp->hsfs_vfs->vfs_fsid.val[0]) {
7177c478bd9Sstevel@tonic-gate 				uniqtime(&tv);
7187c478bd9Sstevel@tonic-gate 				fsid = tv.tv_sec;
7197c478bd9Sstevel@tonic-gate 				break;
7207c478bd9Sstevel@tonic-gate 			}
7217c478bd9Sstevel@tonic-gate 		}
7227c478bd9Sstevel@tonic-gate 
7237c478bd9Sstevel@tonic-gate 	fsp->hsfs_next = hs_mounttab;
7247c478bd9Sstevel@tonic-gate 	hs_mounttab = fsp;
7257c478bd9Sstevel@tonic-gate 
7267c478bd9Sstevel@tonic-gate 	fsp->hsfs_devvp = devvp;
7277c478bd9Sstevel@tonic-gate 	fsp->hsfs_vfs = vfsp;
728fc1c62b8Sfrankho 	fsp->hsfs_fsmnt = kmem_alloc(pathbufsz, KM_SLEEP);
729fc1c62b8Sfrankho 	(void) strlcpy(fsp->hsfs_fsmnt, path, pathbufsz);
7307c478bd9Sstevel@tonic-gate 
7317c478bd9Sstevel@tonic-gate 	mutex_init(&fsp->hsfs_free_lock, NULL, MUTEX_DEFAULT, NULL);
7327c478bd9Sstevel@tonic-gate 	rw_init(&fsp->hsfs_hash_lock, NULL, RW_DEFAULT, NULL);
7337c478bd9Sstevel@tonic-gate 
7347c478bd9Sstevel@tonic-gate 	vfsp->vfs_data = (caddr_t)fsp;
7357c478bd9Sstevel@tonic-gate 	vfsp->vfs_dev = dev;
7367c478bd9Sstevel@tonic-gate 	vfsp->vfs_fstype = hsfsfstype;
7377c478bd9Sstevel@tonic-gate 	vfsp->vfs_bsize = fsp->hsfs_vol.lbn_size; /* %% */
7387c478bd9Sstevel@tonic-gate 	vfsp->vfs_fsid.val[0] = fsid;
7397c478bd9Sstevel@tonic-gate 	vfsp->vfs_fsid.val[1] =  hsfsfstype;
7407c478bd9Sstevel@tonic-gate 
741fc1c62b8Sfrankho 	if (!hs_getrootvp(vfsp, fsp, pathbufsz)) {
742fc1c62b8Sfrankho 		DTRACE_PROBE1(rootvp__failed, struct hsfs *, fsp);
743fc1c62b8Sfrankho 		error = EINVAL;
744fc1c62b8Sfrankho 		goto cleanup;
745fc1c62b8Sfrankho 	}
746fc1c62b8Sfrankho 	DTRACE_PROBE1(rootvp, struct hsfs *, fsp);
747fc1c62b8Sfrankho 
7487c478bd9Sstevel@tonic-gate 	/*
749fc1c62b8Sfrankho 	 * Attempt to discover a RR extension.
7507c478bd9Sstevel@tonic-gate 	 */
751fc1c62b8Sfrankho 	if (use_rrip) {
752fc1c62b8Sfrankho 		hp = VTOH(fsp->hsfs_rootvp);
753fc1c62b8Sfrankho 		hs_check_root_dirent(fsp->hsfs_rootvp, &(hp->hs_dirent));
754fc1c62b8Sfrankho 	}
755fc1c62b8Sfrankho 
756fc1c62b8Sfrankho 	has_rrip = IS_RRIP_IMPLEMENTED(fsp);
757fc1c62b8Sfrankho 	has_vers2 = (svp->lbn_size != 0);
758fc1c62b8Sfrankho 	has_joliet = (jvp->lbn_size != 0);
759fc1c62b8Sfrankho 
760fc1c62b8Sfrankho 	DTRACE_PROBE4(voltype__suggested, struct hsfs *, fsp,
761fc1c62b8Sfrankho 	    int, use_rrip, int, use_vers2, int, use_joliet);
762fc1c62b8Sfrankho 
763fc1c62b8Sfrankho 	DTRACE_PROBE4(voltype__actual, struct hsfs *, fsp,
764fc1c62b8Sfrankho 	    int, has_rrip, int, has_vers2, int, has_joliet);
765fc1c62b8Sfrankho 
766fc1c62b8Sfrankho 	DTRACE_PROBE4(findvol,
767fc1c62b8Sfrankho 	    struct hsfs *, fsp,
768fc1c62b8Sfrankho 	    struct hs_volume *, &fsp->hsfs_vol,
769fc1c62b8Sfrankho 	    struct hs_volume *, svp,
770fc1c62b8Sfrankho 	    struct hs_volume *, jvp);
771fc1c62b8Sfrankho 
772fc1c62b8Sfrankho 	force_rrip_off = !use_rrip ||
773fc1c62b8Sfrankho 	    (vfs_optionisset(vfsp, HOPT_JOLIET, NULL) && has_joliet) ||
774fc1c62b8Sfrankho 	    (vfs_optionisset(vfsp, HOPT_VERS2, NULL) && has_vers2);
775fc1c62b8Sfrankho 
776fc1c62b8Sfrankho 	force_vers2_off = !use_vers2 ||
777fc1c62b8Sfrankho 	    (vfs_optionisset(vfsp, HOPT_JOLIET, NULL) && has_joliet);
778fc1c62b8Sfrankho 
779fc1c62b8Sfrankho 	force_joliet_off = !use_joliet;
780fc1c62b8Sfrankho 
781fc1c62b8Sfrankho 	DTRACE_PROBE4(voltype__force_off, struct hsfs *, fsp,
782fc1c62b8Sfrankho 	    int, force_rrip_off, int, force_vers2_off, int, force_joliet_off);
783fc1c62b8Sfrankho 
784fc1c62b8Sfrankho 	/*
785fc1c62b8Sfrankho 	 * At the moment, we have references of all three possible
786fc1c62b8Sfrankho 	 * extensions (RR, ISO9660:1999/v2 and Joliet) if present.
787fc1c62b8Sfrankho 	 *
788fc1c62b8Sfrankho 	 * The "active" volume descriptor is RRIP (or ISO9660:1988).
789fc1c62b8Sfrankho 	 * We now switch to the user-requested one.
790fc1c62b8Sfrankho 	 */
791fc1c62b8Sfrankho 	redo_rootvp = 0;
792fc1c62b8Sfrankho 
793fc1c62b8Sfrankho 	if (force_rrip_off || !has_rrip) {
794fc1c62b8Sfrankho 		if (has_vers2 && !force_vers2_off) {
795fc1c62b8Sfrankho 			VN_RELE(fsp->hsfs_rootvp);
796fc1c62b8Sfrankho 			bcopy(svp, &fsp->hsfs_vol, sizeof (struct hs_volume));
797fc1c62b8Sfrankho 			fsp->hsfs_vol_type = HS_VOL_TYPE_ISO_V2;
798fc1c62b8Sfrankho 			vfsp->vfs_bsize = fsp->hsfs_vol.lbn_size;
799fc1c62b8Sfrankho 			redo_rootvp = 1;
800fc1c62b8Sfrankho 			has_joliet = 0;
801fc1c62b8Sfrankho 		} else if (has_joliet && !force_joliet_off) {
802fc1c62b8Sfrankho 			VN_RELE(fsp->hsfs_rootvp);
803fc1c62b8Sfrankho 			bcopy(jvp, &fsp->hsfs_vol, sizeof (struct hs_volume));
804fc1c62b8Sfrankho 			fsp->hsfs_vol_type = HS_VOL_TYPE_JOLIET;
805fc1c62b8Sfrankho 			vfsp->vfs_bsize = fsp->hsfs_vol.lbn_size;
806fc1c62b8Sfrankho 			redo_rootvp = 1;
807fc1c62b8Sfrankho 			has_vers2 = 0;
808fc1c62b8Sfrankho 		}
809fc1c62b8Sfrankho 	}
810fc1c62b8Sfrankho 
811fc1c62b8Sfrankho 	if (redo_rootvp) {
812fc1c62b8Sfrankho 		/*
813fc1c62b8Sfrankho 		 * Make sure not to use Rock Ridge.
814fc1c62b8Sfrankho 		 */
815fc1c62b8Sfrankho 		UNSET_IMPL_BIT(fsp, RRIP_BIT);
816fc1c62b8Sfrankho 		UNSET_SUSP_BIT(fsp);
817fc1c62b8Sfrankho 		has_rrip = 0;
818fc1c62b8Sfrankho 
819fc1c62b8Sfrankho 		if (!hs_getrootvp(vfsp, fsp, pathbufsz)) {
820fc1c62b8Sfrankho 			DTRACE_PROBE1(rootvp__failed, struct hsfs *, fsp);
8217c478bd9Sstevel@tonic-gate 			error = EINVAL;
8227c478bd9Sstevel@tonic-gate 			goto cleanup;
8237c478bd9Sstevel@tonic-gate 		}
824fc1c62b8Sfrankho 		DTRACE_PROBE1(rootvp, struct hsfs *, fsp);
825fc1c62b8Sfrankho 	}
826fc1c62b8Sfrankho 	if (IS_RRIP_IMPLEMENTED(fsp)) {
827fc1c62b8Sfrankho 		has_vers2 = 0;
828fc1c62b8Sfrankho 		has_joliet = 0;
8297c478bd9Sstevel@tonic-gate 	}
830fc1c62b8Sfrankho 	if (force_vers2_off)
831fc1c62b8Sfrankho 		has_vers2 = 0;
832fc1c62b8Sfrankho 	if (force_joliet_off)
833fc1c62b8Sfrankho 		has_joliet = 0;
834fc1c62b8Sfrankho 	DTRACE_PROBE4(voltype__taken, struct hsfs *, fsp,
835fc1c62b8Sfrankho 	    int, has_rrip, int, has_vers2, int, has_joliet);
8367c478bd9Sstevel@tonic-gate 
837fc1c62b8Sfrankho 	/*
838fc1c62b8Sfrankho 	 * mark root node as VROOT
839fc1c62b8Sfrankho 	 */
8407c478bd9Sstevel@tonic-gate 	fsp->hsfs_rootvp->v_flag |= VROOT;
8417c478bd9Sstevel@tonic-gate 
8427c478bd9Sstevel@tonic-gate 	/* Here we take care of some special case stuff for mountroot */
8437c478bd9Sstevel@tonic-gate 	if (isroot) {
8447c478bd9Sstevel@tonic-gate 		fsp->hsfs_rootvp->v_rdev = devvp->v_rdev;
8457c478bd9Sstevel@tonic-gate 		rootvp = fsp->hsfs_rootvp;
8467c478bd9Sstevel@tonic-gate 	}
8477c478bd9Sstevel@tonic-gate 
848fc1c62b8Sfrankho 	if (IS_RRIP_IMPLEMENTED(fsp)) {
849fc1c62b8Sfrankho 		/*
850fc1c62b8Sfrankho 		 * if RRIP, don't copy NOMAPLCASE or NOTRAILDOT to hsfs_flags
851fc1c62b8Sfrankho 		 */
852fc1c62b8Sfrankho 		mount_flags &= ~(HSFSMNT_NOMAPLCASE | HSFSMNT_NOTRAILDOT);
8537c478bd9Sstevel@tonic-gate 
854fc1c62b8Sfrankho 		fsp->hsfs_namemax = RRIP_FILE_NAMELEN;
855fc1c62b8Sfrankho 		fsp->hsfs_namelen = RRIP_FILE_NAMELEN;
8567c478bd9Sstevel@tonic-gate 
857fc1c62b8Sfrankho 		ASSERT(vfs_optionisset(vfsp, HOPT_RR, NULL));
858fc1c62b8Sfrankho 		vfs_clearmntopt(vfsp, HOPT_VERS2);
859fc1c62b8Sfrankho 		vfs_clearmntopt(vfsp, HOPT_JOLIET);
860fc1c62b8Sfrankho 
861fc1c62b8Sfrankho 	} else switch (fsp->hsfs_vol_type) {
862fc1c62b8Sfrankho 
863fc1c62b8Sfrankho 	case HS_VOL_TYPE_HS:
864fc1c62b8Sfrankho 	case HS_VOL_TYPE_ISO:
865fc1c62b8Sfrankho 	default:
866fc1c62b8Sfrankho 		/*
867fc1c62b8Sfrankho 		 * if iso v1, don't allow trailing spaces in iso file names
868fc1c62b8Sfrankho 		 */
869fc1c62b8Sfrankho 		mount_flags |= HSFSMNT_NOTRAILSPACE;
870fc1c62b8Sfrankho 		fsp->hsfs_namemax = ISO_NAMELEN_V2_MAX;
871fc1c62b8Sfrankho 		fsp->hsfs_namelen = ISO_FILE_NAMELEN;
872fc1c62b8Sfrankho 		vfs_clearmntopt(vfsp, HOPT_RR);
873fc1c62b8Sfrankho 		vfs_clearmntopt(vfsp, HOPT_VERS2);
874fc1c62b8Sfrankho 		vfs_clearmntopt(vfsp, HOPT_JOLIET);
875fc1c62b8Sfrankho 		break;
876fc1c62b8Sfrankho 
877fc1c62b8Sfrankho 	case HS_VOL_TYPE_ISO_V2:
878fc1c62b8Sfrankho 		/*
879fc1c62b8Sfrankho 		 * if iso v2, don't copy NOTRAILDOT to hsfs_flags
880fc1c62b8Sfrankho 		 */
881fc1c62b8Sfrankho 		mount_flags &= ~HSFSMNT_NOTRAILDOT;
882fc1c62b8Sfrankho 		mount_flags |= HSFSMNT_NOMAPLCASE | HSFSMNT_NOVERSION;
883fc1c62b8Sfrankho 		fsp->hsfs_namemax = ISO_NAMELEN_V2_MAX;
884fc1c62b8Sfrankho 		fsp->hsfs_namelen = ISO_NAMELEN_V2;
885fc1c62b8Sfrankho 		vfs_setmntopt(vfsp, HOPT_VERS2, NULL, 0);
886fc1c62b8Sfrankho 		vfs_clearmntopt(vfsp, HOPT_RR);
887fc1c62b8Sfrankho 		vfs_clearmntopt(vfsp, HOPT_JOLIET);
888fc1c62b8Sfrankho 		break;
889fc1c62b8Sfrankho 
890fc1c62b8Sfrankho 	case HS_VOL_TYPE_JOLIET:
891fc1c62b8Sfrankho 		/*
892fc1c62b8Sfrankho 		 * if Joliet, don't copy NOMAPLCASE or NOTRAILDOT to hsfs_flags
893fc1c62b8Sfrankho 		 */
8947c478bd9Sstevel@tonic-gate 		mount_flags &= ~(HSFSMNT_NOMAPLCASE | HSFSMNT_NOTRAILDOT);
895fc1c62b8Sfrankho 		mount_flags |= HSFSMNT_NOMAPLCASE;
896fc1c62b8Sfrankho 		if (mount_flags & HSFSMNT_JOLIETLONG)
897fc1c62b8Sfrankho 			fsp->hsfs_namemax = JOLIET_NAMELEN_MAX*3; /* UTF-8 */
898fc1c62b8Sfrankho 		else
899fc1c62b8Sfrankho 			fsp->hsfs_namemax = MAXNAMELEN-1;
900fc1c62b8Sfrankho 		fsp->hsfs_namelen = JOLIET_NAMELEN*2;
901fc1c62b8Sfrankho 		vfs_setmntopt(vfsp, HOPT_JOLIET, NULL, 0);
902fc1c62b8Sfrankho 		vfs_clearmntopt(vfsp, HOPT_RR);
903fc1c62b8Sfrankho 		vfs_clearmntopt(vfsp, HOPT_VERS2);
904fc1c62b8Sfrankho 		break;
905fc1c62b8Sfrankho 	}
9067c478bd9Sstevel@tonic-gate 
907d10b6702Sfrankho 	/*
908d10b6702Sfrankho 	 * Add the HSFSMNT_INODE pseudo mount flag to the current mount flags.
909d10b6702Sfrankho 	 */
910d10b6702Sfrankho 	fsp->hsfs_flags = mount_flags | (fsp->hsfs_flags & HSFSMNT_INODE);
9117c478bd9Sstevel@tonic-gate 
91284b82766Smg 	/*
91384b82766Smg 	 * Setup I/O Scheduling structures
91484b82766Smg 	 */
91584b82766Smg 	if (do_schedio) {
91684b82766Smg 		fsp->hqueue = kmem_alloc(sizeof (struct hsfs_queue), KM_SLEEP);
91784b82766Smg 		hsched_init(fsp, fsid, &modlinkage);
91884b82766Smg 	}
91984b82766Smg 
92084b82766Smg 	/*
92184b82766Smg 	 * Setup kstats
92284b82766Smg 	 */
92384b82766Smg 	hsfs_init_kstats(fsp, fsid);
92484b82766Smg 
925fc1c62b8Sfrankho 	DTRACE_PROBE1(mount__done, struct hsfs *, fsp);
926fc1c62b8Sfrankho 
927fc1c62b8Sfrankho 	/*
928fc1c62b8Sfrankho 	 * set the magic word
929fc1c62b8Sfrankho 	 */
9307c478bd9Sstevel@tonic-gate 	fsp->hsfs_magic = HSFS_MAGIC;
9317c478bd9Sstevel@tonic-gate 	mutex_exit(&hs_mounttab_lock);
9327c478bd9Sstevel@tonic-gate 
933d10b6702Sfrankho 	kmem_free(svp, sizeof (*svp));
934d10b6702Sfrankho 	kmem_free(jvp, sizeof (*jvp));
935d10b6702Sfrankho 
9367c478bd9Sstevel@tonic-gate 	return (0);
9377c478bd9Sstevel@tonic-gate 
9387c478bd9Sstevel@tonic-gate cleanup:
939da6c28aaSamw 	(void) VOP_CLOSE(devvp, FREAD, 1, (offset_t)0, cr, NULL);
9407c478bd9Sstevel@tonic-gate 	VN_RELE(devvp);
9417c478bd9Sstevel@tonic-gate 	if (fsp)
9427c478bd9Sstevel@tonic-gate 		kmem_free(fsp, sizeof (*fsp));
943fc1c62b8Sfrankho 	if (svp)
944fc1c62b8Sfrankho 		kmem_free(svp, sizeof (*svp));
945fc1c62b8Sfrankho 	if (jvp)
946fc1c62b8Sfrankho 		kmem_free(jvp, sizeof (*jvp));
9477c478bd9Sstevel@tonic-gate 	return (error);
9487c478bd9Sstevel@tonic-gate }
9497c478bd9Sstevel@tonic-gate 
950fc1c62b8Sfrankho /*
951fc1c62b8Sfrankho  * Get the rootvp associated with fsp->hsfs_vol
952fc1c62b8Sfrankho  */
953fc1c62b8Sfrankho static int
hs_getrootvp(struct vfs * vfsp,struct hsfs * fsp,size_t pathsize)954fc1c62b8Sfrankho hs_getrootvp(
955fc1c62b8Sfrankho 	struct vfs	*vfsp,
956fc1c62b8Sfrankho 	struct hsfs	*fsp,
957fc1c62b8Sfrankho 	size_t		pathsize)
958fc1c62b8Sfrankho {
959fc1c62b8Sfrankho 	struct hsnode	*hp;
960fc1c62b8Sfrankho 
961fc1c62b8Sfrankho 	ASSERT(pathsize == strlen(fsp->hsfs_fsmnt) + 1);
962fc1c62b8Sfrankho 
963fc1c62b8Sfrankho 	/*
964fc1c62b8Sfrankho 	 * If the root directory does not appear to be
965fc1c62b8Sfrankho 	 * valid, use what it points to as "." instead.
966fc1c62b8Sfrankho 	 * Some Defense Mapping Agency disks are non-conformant
967fc1c62b8Sfrankho 	 * in this way.
968fc1c62b8Sfrankho 	 */
969fc1c62b8Sfrankho 	if (!hsfs_valid_dir(&fsp->hsfs_vol.root_dir)) {
970fc1c62b8Sfrankho 		hs_log_bogus_disk_warning(fsp, HSFS_ERR_BAD_ROOT_DIR, 0);
971fc1c62b8Sfrankho 		if (hs_remakenode(fsp->hsfs_vol.root_dir.ext_lbn,
972d10b6702Sfrankho 		    (uint_t)0, vfsp, &fsp->hsfs_rootvp)) {
973fc1c62b8Sfrankho 			hs_mounttab = hs_mounttab->hsfs_next;
974fc1c62b8Sfrankho 			mutex_destroy(&fsp->hsfs_free_lock);
975fc1c62b8Sfrankho 			rw_destroy(&fsp->hsfs_hash_lock);
976fc1c62b8Sfrankho 			kmem_free(fsp->hsfs_fsmnt, pathsize);
977fc1c62b8Sfrankho 			mutex_exit(&hs_mounttab_lock);
978fc1c62b8Sfrankho 			return (0);
979fc1c62b8Sfrankho 		}
980fc1c62b8Sfrankho 	} else {
981fc1c62b8Sfrankho 		fsp->hsfs_rootvp = hs_makenode(&fsp->hsfs_vol.root_dir,
982d10b6702Sfrankho 		    fsp->hsfs_vol.root_dir.ext_lbn, 0, vfsp);
983fc1c62b8Sfrankho 	}
984fc1c62b8Sfrankho 
985fc1c62b8Sfrankho 	/* XXX - ignore the path table for now */
986fc1c62b8Sfrankho 	fsp->hsfs_ptbl = NULL;
987fc1c62b8Sfrankho 	hp = VTOH(fsp->hsfs_rootvp);
988fc1c62b8Sfrankho 	hp->hs_ptbl_idx = NULL;
989fc1c62b8Sfrankho 
990fc1c62b8Sfrankho 	return (1);
991fc1c62b8Sfrankho }
992fc1c62b8Sfrankho 
9937c478bd9Sstevel@tonic-gate /*
9947c478bd9Sstevel@tonic-gate  * hs_findhsvol()
9957c478bd9Sstevel@tonic-gate  *
9967c478bd9Sstevel@tonic-gate  * Locate the Standard File Structure Volume Descriptor and
9977c478bd9Sstevel@tonic-gate  * parse it into an hs_volume structure.
9987c478bd9Sstevel@tonic-gate  *
9997c478bd9Sstevel@tonic-gate  * XXX - May someday want to look for Coded Character Set FSVD, too.
10007c478bd9Sstevel@tonic-gate  */
10017c478bd9Sstevel@tonic-gate static int
hs_findhsvol(struct hsfs * fsp,struct vnode * vp,struct hs_volume * hvp)10027c478bd9Sstevel@tonic-gate hs_findhsvol(struct hsfs *fsp, struct vnode *vp, struct hs_volume *hvp)
10037c478bd9Sstevel@tonic-gate {
10047c478bd9Sstevel@tonic-gate 	struct buf *secbp;
10057c478bd9Sstevel@tonic-gate 	int i;
1006d10b6702Sfrankho 	int n;
10077c478bd9Sstevel@tonic-gate 	uchar_t *volp;
10087c478bd9Sstevel@tonic-gate 	int error;
10097c478bd9Sstevel@tonic-gate 	uint_t secno;
10107c478bd9Sstevel@tonic-gate 
10117c478bd9Sstevel@tonic-gate 	secno = hs_findvoldesc(vp->v_rdev, HS_VOLDESC_SEC);
10127c478bd9Sstevel@tonic-gate 	secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE);
10137c478bd9Sstevel@tonic-gate 	error = geterror(secbp);
10147c478bd9Sstevel@tonic-gate 
10157c478bd9Sstevel@tonic-gate 	if (error != 0) {
10167c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "hs_findhsvol: bread: error=(%d)", error);
10177c478bd9Sstevel@tonic-gate 		brelse(secbp);
10187c478bd9Sstevel@tonic-gate 		return (error);
10197c478bd9Sstevel@tonic-gate 	}
10207c478bd9Sstevel@tonic-gate 
10217c478bd9Sstevel@tonic-gate 	volp = (uchar_t *)secbp->b_un.b_addr;
10227c478bd9Sstevel@tonic-gate 
1023d10b6702Sfrankho 	/*
1024d10b6702Sfrankho 	 * To avoid that we read the whole medium in case that someone prepares
1025d10b6702Sfrankho 	 * a malicious "fs image", we read at most 32 blocks.
1026d10b6702Sfrankho 	 */
1027d10b6702Sfrankho 	for (n = 0; n < 32 &&
1028d10b6702Sfrankho 	    HSV_DESC_TYPE(volp) != VD_EOV; n++) {
10297c478bd9Sstevel@tonic-gate 		for (i = 0; i < HSV_ID_STRLEN; i++)
10307c478bd9Sstevel@tonic-gate 			if (HSV_STD_ID(volp)[i] != HSV_ID_STRING[i])
10317c478bd9Sstevel@tonic-gate 				goto cantfind;
10327c478bd9Sstevel@tonic-gate 		if (HSV_STD_VER(volp) != HSV_ID_VER)
10337c478bd9Sstevel@tonic-gate 			goto cantfind;
10347c478bd9Sstevel@tonic-gate 		switch (HSV_DESC_TYPE(volp)) {
10357c478bd9Sstevel@tonic-gate 		case VD_SFS:
10367c478bd9Sstevel@tonic-gate 			/* Standard File Structure */
10377c478bd9Sstevel@tonic-gate 			fsp->hsfs_vol_type = HS_VOL_TYPE_HS;
10387c478bd9Sstevel@tonic-gate 			error = hs_parsehsvol(fsp, volp, hvp);
10397c478bd9Sstevel@tonic-gate 			brelse(secbp);
10407c478bd9Sstevel@tonic-gate 			return (error);
10417c478bd9Sstevel@tonic-gate 
10427c478bd9Sstevel@tonic-gate 		case VD_CCFS:
10437c478bd9Sstevel@tonic-gate 			/* Coded Character File Structure */
10447c478bd9Sstevel@tonic-gate 		case VD_BOOT:
10457c478bd9Sstevel@tonic-gate 		case VD_UNSPEC:
10467c478bd9Sstevel@tonic-gate 		case VD_EOV:
10477c478bd9Sstevel@tonic-gate 			break;
10487c478bd9Sstevel@tonic-gate 		}
10497c478bd9Sstevel@tonic-gate 		brelse(secbp);
10507c478bd9Sstevel@tonic-gate 		++secno;
10517c478bd9Sstevel@tonic-gate 		secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE);
10527c478bd9Sstevel@tonic-gate 
10537c478bd9Sstevel@tonic-gate 		error = geterror(secbp);
10547c478bd9Sstevel@tonic-gate 
10557c478bd9Sstevel@tonic-gate 		if (error != 0) {
10567c478bd9Sstevel@tonic-gate 			cmn_err(CE_NOTE, "hs_findhsvol: bread: error=(%d)",
1057d10b6702Sfrankho 			    error);
10587c478bd9Sstevel@tonic-gate 			brelse(secbp);
10597c478bd9Sstevel@tonic-gate 			return (error);
10607c478bd9Sstevel@tonic-gate 		}
10617c478bd9Sstevel@tonic-gate 
10627c478bd9Sstevel@tonic-gate 		volp = (uchar_t *)secbp->b_un.b_addr;
10637c478bd9Sstevel@tonic-gate 	}
10647c478bd9Sstevel@tonic-gate cantfind:
10657c478bd9Sstevel@tonic-gate 	brelse(secbp);
10667c478bd9Sstevel@tonic-gate 	return (EINVAL);
10677c478bd9Sstevel@tonic-gate }
10687c478bd9Sstevel@tonic-gate 
10697c478bd9Sstevel@tonic-gate /*
10707c478bd9Sstevel@tonic-gate  * hs_parsehsvol
10717c478bd9Sstevel@tonic-gate  *
10727c478bd9Sstevel@tonic-gate  * Parse the Standard File Structure Volume Descriptor into
10737c478bd9Sstevel@tonic-gate  * an hs_volume structure.  We can't just bcopy it into the
10747c478bd9Sstevel@tonic-gate  * structure because of byte-ordering problems.
10757c478bd9Sstevel@tonic-gate  *
10767c478bd9Sstevel@tonic-gate  */
10777c478bd9Sstevel@tonic-gate static int
hs_parsehsvol(struct hsfs * fsp,uchar_t * volp,struct hs_volume * hvp)10787c478bd9Sstevel@tonic-gate hs_parsehsvol(struct hsfs *fsp, uchar_t *volp, struct hs_volume *hvp)
10797c478bd9Sstevel@tonic-gate {
10807c478bd9Sstevel@tonic-gate 	hvp->vol_size = HSV_VOL_SIZE(volp);
10817c478bd9Sstevel@tonic-gate 	hvp->lbn_size = HSV_BLK_SIZE(volp);
10827c478bd9Sstevel@tonic-gate 	if (hvp->lbn_size == 0) {
10837c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "hs_parsehsvol: logical block size in the "
1084d10b6702Sfrankho 		    "SFSVD is zero");
10857c478bd9Sstevel@tonic-gate 		return (EINVAL);
10867c478bd9Sstevel@tonic-gate 	}
10877c478bd9Sstevel@tonic-gate 	hvp->lbn_shift = ffs((long)hvp->lbn_size) - 1;
1088d10b6702Sfrankho 	hvp->lbn_secshift =
1089d10b6702Sfrankho 	    ffs((long)howmany(HS_SECTOR_SIZE, (int)hvp->lbn_size)) - 1;
10907c478bd9Sstevel@tonic-gate 	hvp->lbn_maxoffset = hvp->lbn_size - 1;
10917c478bd9Sstevel@tonic-gate 	hs_parse_longdate(HSV_cre_date(volp), &hvp->cre_date);
10927c478bd9Sstevel@tonic-gate 	hs_parse_longdate(HSV_mod_date(volp), &hvp->mod_date);
10937c478bd9Sstevel@tonic-gate 	hvp->file_struct_ver = HSV_FILE_STRUCT_VER(volp);
10947c478bd9Sstevel@tonic-gate 	hvp->ptbl_len = HSV_PTBL_SIZE(volp);
10957c478bd9Sstevel@tonic-gate 	hvp->vol_set_size = (ushort_t)HSV_SET_SIZE(volp);
10967c478bd9Sstevel@tonic-gate 	hvp->vol_set_seq = (ushort_t)HSV_SET_SEQ(volp);
10977c478bd9Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN)
10987c478bd9Sstevel@tonic-gate 	hvp->ptbl_lbn = HSV_PTBL_MAN_LS(volp);
10997c478bd9Sstevel@tonic-gate #else
11007c478bd9Sstevel@tonic-gate 	hvp->ptbl_lbn = HSV_PTBL_MAN_MS(volp);
11017c478bd9Sstevel@tonic-gate #endif
1102fc1c62b8Sfrankho 	hs_copylabel(hvp, HSV_VOL_ID(volp), 0);
11037c478bd9Sstevel@tonic-gate 
11047c478bd9Sstevel@tonic-gate 	/*
11057c478bd9Sstevel@tonic-gate 	 * Make sure that lbn_size is a power of two and otherwise valid.
11067c478bd9Sstevel@tonic-gate 	 */
11077c478bd9Sstevel@tonic-gate 	if (hvp->lbn_size & ~(1 << hvp->lbn_shift)) {
11087c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE,
1109d10b6702Sfrankho 		    "hsfs: %d-byte logical block size not supported",
1110d10b6702Sfrankho 		    hvp->lbn_size);
11117c478bd9Sstevel@tonic-gate 		return (EINVAL);
11127c478bd9Sstevel@tonic-gate 	}
11137c478bd9Sstevel@tonic-gate 	return (hs_parsedir(fsp, HSV_ROOT_DIR(volp), &hvp->root_dir,
1114d10b6702Sfrankho 	    (char *)NULL, (int *)NULL, HDE_ROOT_DIR_REC_SIZE));
11157c478bd9Sstevel@tonic-gate }
11167c478bd9Sstevel@tonic-gate 
11177c478bd9Sstevel@tonic-gate /*
11187c478bd9Sstevel@tonic-gate  * hs_findisovol()
11197c478bd9Sstevel@tonic-gate  *
11207c478bd9Sstevel@tonic-gate  * Locate the Primary Volume Descriptor
11217c478bd9Sstevel@tonic-gate  * parse it into an hs_volume structure.
11227c478bd9Sstevel@tonic-gate  *
1123fc1c62b8Sfrankho  * XXX - Partition not yet done
1124fc1c62b8Sfrankho  *
1125fc1c62b8Sfrankho  * Except for fsp->hsfs_vol_type, no fsp member may be modified.
1126fc1c62b8Sfrankho  * fsp->hsfs_vol is modified indirectly via the *hvp argument.
11277c478bd9Sstevel@tonic-gate  */
11287c478bd9Sstevel@tonic-gate static int
hs_findisovol(struct hsfs * fsp,struct vnode * vp,struct hs_volume * hvp,struct hs_volume * svp,struct hs_volume * jvp)11297c478bd9Sstevel@tonic-gate hs_findisovol(struct hsfs *fsp, struct vnode *vp,
1130fc1c62b8Sfrankho     struct hs_volume *hvp,
1131fc1c62b8Sfrankho     struct hs_volume *svp,
1132fc1c62b8Sfrankho     struct hs_volume *jvp)
11337c478bd9Sstevel@tonic-gate {
11347c478bd9Sstevel@tonic-gate 	struct buf *secbp;
11357c478bd9Sstevel@tonic-gate 	int i;
1136d10b6702Sfrankho 	int n;
11377c478bd9Sstevel@tonic-gate 	uchar_t *volp;
11387c478bd9Sstevel@tonic-gate 	int error;
11397c478bd9Sstevel@tonic-gate 	uint_t secno;
11407c478bd9Sstevel@tonic-gate 	int foundpvd = 0;
1141fc1c62b8Sfrankho 	int foundsvd = 0;
1142fc1c62b8Sfrankho 	int foundjvd = 0;
1143d10b6702Sfrankho 	int pvd_sum = 0;
11447c478bd9Sstevel@tonic-gate 
11457c478bd9Sstevel@tonic-gate 	secno = hs_findvoldesc(vp->v_rdev, ISO_VOLDESC_SEC);
11467c478bd9Sstevel@tonic-gate 	secbp = bread(vp->v_rdev, secno * 4, ISO_SECTOR_SIZE);
11477c478bd9Sstevel@tonic-gate 	error = geterror(secbp);
11487c478bd9Sstevel@tonic-gate 
11497c478bd9Sstevel@tonic-gate 	if (error != 0) {
11507c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "hs_findisovol: bread: error=(%d)", error);
11517c478bd9Sstevel@tonic-gate 		brelse(secbp);
11527c478bd9Sstevel@tonic-gate 		return (error);
11537c478bd9Sstevel@tonic-gate 	}
11547c478bd9Sstevel@tonic-gate 
11557c478bd9Sstevel@tonic-gate 	volp = (uchar_t *)secbp->b_un.b_addr;
11567c478bd9Sstevel@tonic-gate 
1157d10b6702Sfrankho 	/*
1158d10b6702Sfrankho 	 * To avoid that we read the whole medium in case that someone prepares
1159d10b6702Sfrankho 	 * a malicious "fs image", we read at most 32 blocks.
1160d10b6702Sfrankho 	 */
11610c79d02bSRichard Lowe 	for (n = 0; n < 32 && ISO_DESC_TYPE(volp) != ISO_VD_EOV; n++) {
11627c478bd9Sstevel@tonic-gate 		for (i = 0; i < ISO_ID_STRLEN; i++)
11637c478bd9Sstevel@tonic-gate 			if (ISO_STD_ID(volp)[i] != ISO_ID_STRING[i])
11647c478bd9Sstevel@tonic-gate 				goto cantfind;
11657c478bd9Sstevel@tonic-gate 		switch (ISO_DESC_TYPE(volp)) {
11667c478bd9Sstevel@tonic-gate 		case ISO_VD_PVD:
11677c478bd9Sstevel@tonic-gate 			/* Standard File Structure */
1168fc1c62b8Sfrankho 			if (ISO_STD_VER(volp) != ISO_ID_VER)
1169fc1c62b8Sfrankho 				goto cantfind;
11707c478bd9Sstevel@tonic-gate 			if (foundpvd != 1) {
11717c478bd9Sstevel@tonic-gate 				fsp->hsfs_vol_type = HS_VOL_TYPE_ISO;
11727c478bd9Sstevel@tonic-gate 				if (error = hs_parseisovol(fsp, volp, hvp)) {
11737c478bd9Sstevel@tonic-gate 					brelse(secbp);
11747c478bd9Sstevel@tonic-gate 					return (error);
11757c478bd9Sstevel@tonic-gate 				}
11767c478bd9Sstevel@tonic-gate 				foundpvd = 1;
1177d10b6702Sfrankho 				for (i = 0; i < ISO_SECTOR_SIZE; i++)
1178d10b6702Sfrankho 					pvd_sum += volp[i];
11797c478bd9Sstevel@tonic-gate 			}
11807c478bd9Sstevel@tonic-gate 			break;
11817c478bd9Sstevel@tonic-gate 		case ISO_VD_SVD:
11827c478bd9Sstevel@tonic-gate 			/* Supplementary Volume Descriptor */
1183fc1c62b8Sfrankho 			if (ISO_STD_VER(volp) == ISO_ID_VER2 &&
1184fc1c62b8Sfrankho 			    foundsvd != 1) {
1185fc1c62b8Sfrankho 				fsp->hsfs_vol_type = HS_VOL_TYPE_ISO;
1186fc1c62b8Sfrankho 				if (error = hs_parseisovol(fsp, volp, svp)) {
1187fc1c62b8Sfrankho 					brelse(secbp);
1188fc1c62b8Sfrankho 					return (error);
1189fc1c62b8Sfrankho 				}
1190fc1c62b8Sfrankho 				foundsvd = 1;
1191fc1c62b8Sfrankho 			}
1192fc1c62b8Sfrankho 			if (hs_joliet_level(volp) >= 1 && foundjvd != 1) {
1193fc1c62b8Sfrankho 				fsp->hsfs_vol_type = HS_VOL_TYPE_ISO;
1194fc1c62b8Sfrankho 				if (error = hs_parseisovol(fsp, volp, jvp)) {
1195fc1c62b8Sfrankho 					brelse(secbp);
1196fc1c62b8Sfrankho 					return (error);
1197fc1c62b8Sfrankho 				}
1198fc1c62b8Sfrankho 				foundjvd = 1;
1199fc1c62b8Sfrankho 			}
12007c478bd9Sstevel@tonic-gate 			break;
12017c478bd9Sstevel@tonic-gate 		case ISO_VD_BOOT:
12027c478bd9Sstevel@tonic-gate 			break;
12037c478bd9Sstevel@tonic-gate 		case ISO_VD_VPD:
12047c478bd9Sstevel@tonic-gate 			/* currently cannot handle partition */
12057c478bd9Sstevel@tonic-gate 			break;
12067c478bd9Sstevel@tonic-gate 		case VD_EOV:
12077c478bd9Sstevel@tonic-gate 			break;
12087c478bd9Sstevel@tonic-gate 		}
12097c478bd9Sstevel@tonic-gate 		brelse(secbp);
12107c478bd9Sstevel@tonic-gate 		++secno;
12117c478bd9Sstevel@tonic-gate 		secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE);
12127c478bd9Sstevel@tonic-gate 		error = geterror(secbp);
12137c478bd9Sstevel@tonic-gate 
12147c478bd9Sstevel@tonic-gate 		if (error != 0) {
12157c478bd9Sstevel@tonic-gate 			cmn_err(CE_NOTE, "hs_findisovol: bread: error=(%d)",
1216d10b6702Sfrankho 			    error);
1217d10b6702Sfrankho 			brelse(secbp);
1218d10b6702Sfrankho 			return (error);
1219d10b6702Sfrankho 		}
1220d10b6702Sfrankho 
1221d10b6702Sfrankho 		volp = (uchar_t *)secbp->b_un.b_addr;
1222d10b6702Sfrankho 	}
1223d10b6702Sfrankho 	for (n = 0; n < 16; n++) {
1224d10b6702Sfrankho 		brelse(secbp);
1225d10b6702Sfrankho 		++secno;
1226d10b6702Sfrankho 		secbp = bread(vp->v_rdev, secno * 4, HS_SECTOR_SIZE);
1227d10b6702Sfrankho 		error = geterror(secbp);
1228d10b6702Sfrankho 
1229d10b6702Sfrankho 		if (error != 0) {
1230d10b6702Sfrankho 			cmn_err(CE_NOTE, "hs_findisovol: bread: error=(%d)",
1231d10b6702Sfrankho 			    error);
12327c478bd9Sstevel@tonic-gate 			brelse(secbp);
12337c478bd9Sstevel@tonic-gate 			return (error);
12347c478bd9Sstevel@tonic-gate 		}
12357c478bd9Sstevel@tonic-gate 
1236d10b6702Sfrankho 		/*
1237d10b6702Sfrankho 		 * Check for the signature from mkisofs that grants that
1238d10b6702Sfrankho 		 * the current filesystem allows to use the extent lbn as
1239d10b6702Sfrankho 		 * inode number even in pure ISO9660 mode.
1240d10b6702Sfrankho 		 */
12417c478bd9Sstevel@tonic-gate 		volp = (uchar_t *)secbp->b_un.b_addr;
1242d10b6702Sfrankho 		if (strncmp((char *)volp, "MKI ", 4) == 0) {
1243d10b6702Sfrankho 			int	sum;
1244d10b6702Sfrankho 
1245d10b6702Sfrankho 			sum  = volp[2045];
1246d10b6702Sfrankho 			sum *= 256;
1247d10b6702Sfrankho 			sum += volp[2046];
1248d10b6702Sfrankho 			sum *= 256;
1249d10b6702Sfrankho 			sum += volp[2047];
1250d10b6702Sfrankho 			if (sum == pvd_sum)
1251d10b6702Sfrankho 				fsp->hsfs_flags |= HSFSMNT_INODE;
1252d10b6702Sfrankho 			break;
1253d10b6702Sfrankho 		}
12547c478bd9Sstevel@tonic-gate 	}
12557c478bd9Sstevel@tonic-gate 	if (foundpvd) {
12567c478bd9Sstevel@tonic-gate 		brelse(secbp);
12577c478bd9Sstevel@tonic-gate 		return (0);
12587c478bd9Sstevel@tonic-gate 	}
12597c478bd9Sstevel@tonic-gate cantfind:
12607c478bd9Sstevel@tonic-gate 	brelse(secbp);
12617c478bd9Sstevel@tonic-gate 	return (EINVAL);
12627c478bd9Sstevel@tonic-gate }
1263fc1c62b8Sfrankho 
1264fc1c62b8Sfrankho /*
1265fc1c62b8Sfrankho  * Return 0 if no Joliet is found
1266fc1c62b8Sfrankho  * else return Joliet Level 1..3
1267fc1c62b8Sfrankho  */
1268fc1c62b8Sfrankho static int
hs_joliet_level(uchar_t * volp)1269fc1c62b8Sfrankho hs_joliet_level(uchar_t *volp)
1270fc1c62b8Sfrankho {
1271fc1c62b8Sfrankho 	if (ISO_std_ver(volp)[0] == ISO_ID_VER &&
1272fc1c62b8Sfrankho 	    ISO_svd_esc(volp)[0] == '%' &&
1273fc1c62b8Sfrankho 	    ISO_svd_esc(volp)[1] == '/') {
1274fc1c62b8Sfrankho 
1275fc1c62b8Sfrankho 		switch (ISO_svd_esc(volp)[2]) {
1276fc1c62b8Sfrankho 
1277fc1c62b8Sfrankho 		case '@':
1278fc1c62b8Sfrankho 			return (1);
1279fc1c62b8Sfrankho 		case 'C':
1280fc1c62b8Sfrankho 			return (2);
1281fc1c62b8Sfrankho 		case 'E':
1282fc1c62b8Sfrankho 			return (3);
1283fc1c62b8Sfrankho 		}
1284fc1c62b8Sfrankho 	}
1285fc1c62b8Sfrankho 	return (0);
1286fc1c62b8Sfrankho }
1287fc1c62b8Sfrankho 
12887c478bd9Sstevel@tonic-gate /*
12897c478bd9Sstevel@tonic-gate  * hs_parseisovol
12907c478bd9Sstevel@tonic-gate  *
12917c478bd9Sstevel@tonic-gate  * Parse the Primary Volume Descriptor into an hs_volume structure.
12927c478bd9Sstevel@tonic-gate  *
12937c478bd9Sstevel@tonic-gate  */
12947c478bd9Sstevel@tonic-gate static int
hs_parseisovol(struct hsfs * fsp,uchar_t * volp,struct hs_volume * hvp)12957c478bd9Sstevel@tonic-gate hs_parseisovol(struct hsfs *fsp, uchar_t *volp, struct hs_volume *hvp)
12967c478bd9Sstevel@tonic-gate {
12977c478bd9Sstevel@tonic-gate 	hvp->vol_size = ISO_VOL_SIZE(volp);
12987c478bd9Sstevel@tonic-gate 	hvp->lbn_size = ISO_BLK_SIZE(volp);
12997c478bd9Sstevel@tonic-gate 	if (hvp->lbn_size == 0) {
13007c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "hs_parseisovol: logical block size in the "
1301d10b6702Sfrankho 		    "PVD is zero");
13027c478bd9Sstevel@tonic-gate 		return (EINVAL);
13037c478bd9Sstevel@tonic-gate 	}
13047c478bd9Sstevel@tonic-gate 	hvp->lbn_shift = ffs((long)hvp->lbn_size) - 1;
1305d10b6702Sfrankho 	hvp->lbn_secshift =
1306d10b6702Sfrankho 	    ffs((long)howmany(ISO_SECTOR_SIZE, (int)hvp->lbn_size)) - 1;
13077c478bd9Sstevel@tonic-gate 	hvp->lbn_maxoffset = hvp->lbn_size - 1;
13087c478bd9Sstevel@tonic-gate 	hs_parse_longdate(ISO_cre_date(volp), &hvp->cre_date);
13097c478bd9Sstevel@tonic-gate 	hs_parse_longdate(ISO_mod_date(volp), &hvp->mod_date);
13107c478bd9Sstevel@tonic-gate 	hvp->file_struct_ver = ISO_FILE_STRUCT_VER(volp);
13117c478bd9Sstevel@tonic-gate 	hvp->ptbl_len = ISO_PTBL_SIZE(volp);
13127c478bd9Sstevel@tonic-gate 	hvp->vol_set_size = (ushort_t)ISO_SET_SIZE(volp);
13137c478bd9Sstevel@tonic-gate 	hvp->vol_set_seq = (ushort_t)ISO_SET_SEQ(volp);
13147c478bd9Sstevel@tonic-gate #if defined(_LITTLE_ENDIAN)
13157c478bd9Sstevel@tonic-gate 	hvp->ptbl_lbn = ISO_PTBL_MAN_LS(volp);
13167c478bd9Sstevel@tonic-gate #else
13177c478bd9Sstevel@tonic-gate 	hvp->ptbl_lbn = ISO_PTBL_MAN_MS(volp);
13187c478bd9Sstevel@tonic-gate #endif
1319fc1c62b8Sfrankho 	hs_copylabel(hvp, ISO_VOL_ID(volp), hs_joliet_level(volp) >= 1);
13207c478bd9Sstevel@tonic-gate 
13217c478bd9Sstevel@tonic-gate 	/*
13227c478bd9Sstevel@tonic-gate 	 * Make sure that lbn_size is a power of two and otherwise valid.
13237c478bd9Sstevel@tonic-gate 	 */
13247c478bd9Sstevel@tonic-gate 	if (hvp->lbn_size & ~(1 << hvp->lbn_shift)) {
13257c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE,
1326d10b6702Sfrankho 		    "hsfs: %d-byte logical block size not supported",
1327d10b6702Sfrankho 		    hvp->lbn_size);
13287c478bd9Sstevel@tonic-gate 		return (EINVAL);
13297c478bd9Sstevel@tonic-gate 	}
13307c478bd9Sstevel@tonic-gate 	return (hs_parsedir(fsp, ISO_ROOT_DIR(volp), &hvp->root_dir,
1331d10b6702Sfrankho 	    (char *)NULL, (int *)NULL, IDE_ROOT_DIR_REC_SIZE));
13327c478bd9Sstevel@tonic-gate }
13337c478bd9Sstevel@tonic-gate 
13347c478bd9Sstevel@tonic-gate /*
13357c478bd9Sstevel@tonic-gate  * Common code for mount and umount.
13367c478bd9Sstevel@tonic-gate  * Check that the user's argument is a reasonable
13377c478bd9Sstevel@tonic-gate  * thing on which to mount, and return the device number if so.
13387c478bd9Sstevel@tonic-gate  */
13397c478bd9Sstevel@tonic-gate static int
hs_getmdev(struct vfs * vfsp,char * fspec,int flags,dev_t * pdev,mode_t * mode,cred_t * cr)13407c478bd9Sstevel@tonic-gate hs_getmdev(struct vfs *vfsp, char *fspec, int flags, dev_t *pdev, mode_t *mode,
13417c478bd9Sstevel@tonic-gate     cred_t *cr)
13427c478bd9Sstevel@tonic-gate {
13437c478bd9Sstevel@tonic-gate 	int error;
134493239addSjohnlev 	struct vnode *svp = NULL;
134593239addSjohnlev 	struct vnode *lvp = NULL;
134693239addSjohnlev 	struct vnode *bvp;
13477c478bd9Sstevel@tonic-gate 	struct vattr vap;
13487c478bd9Sstevel@tonic-gate 	dev_t dev;
134993239addSjohnlev 	enum uio_seg fromspace = (flags & MS_SYSSPACE) ?
135093239addSjohnlev 	    UIO_SYSSPACE : UIO_USERSPACE;
13517c478bd9Sstevel@tonic-gate 
13527c478bd9Sstevel@tonic-gate 	/*
135393239addSjohnlev 	 * Look up the device/file to be mounted.
13547c478bd9Sstevel@tonic-gate 	 */
135593239addSjohnlev 	error = lookupname(fspec, fromspace, FOLLOW, NULLVPP, &svp);
13567c478bd9Sstevel@tonic-gate 	if (error) {
135793239addSjohnlev 		if (error == ENOENT)
135893239addSjohnlev 			error = ENODEV;
135993239addSjohnlev 		goto out;
13607c478bd9Sstevel@tonic-gate 	}
136193239addSjohnlev 
136293239addSjohnlev 	error = vfs_get_lofi(vfsp, &lvp);
136393239addSjohnlev 
136493239addSjohnlev 	if (error > 0) {
136593239addSjohnlev 		if (error == ENOENT)
136693239addSjohnlev 			error = ENODEV;
136793239addSjohnlev 		goto out;
136893239addSjohnlev 	} else if (error == 0) {
136993239addSjohnlev 		bvp = lvp;
137093239addSjohnlev 	} else {
137193239addSjohnlev 		bvp = svp;
137293239addSjohnlev 
137393239addSjohnlev 		if (bvp->v_type != VBLK) {
137493239addSjohnlev 			error = ENOTBLK;
137593239addSjohnlev 			goto out;
137693239addSjohnlev 		}
137793239addSjohnlev 
137893239addSjohnlev 		if ((error = secpolicy_spec_open(cr, bvp, FREAD)) != 0)
137993239addSjohnlev 			goto out;
13807c478bd9Sstevel@tonic-gate 	}
138193239addSjohnlev 
13827c478bd9Sstevel@tonic-gate 	/*
138393239addSjohnlev 	 * Can we read from the device/file ?
13847c478bd9Sstevel@tonic-gate 	 */
138593239addSjohnlev 	if ((error = VOP_ACCESS(svp, VREAD, 0, cr, NULL)) != 0)
138693239addSjohnlev 		goto out;
13877c478bd9Sstevel@tonic-gate 
13887c478bd9Sstevel@tonic-gate 	vap.va_mask = AT_MODE;		/* get protection mode */
138993239addSjohnlev 	(void) VOP_GETATTR(bvp, &vap, 0, CRED(), NULL);
13907c478bd9Sstevel@tonic-gate 	*mode = vap.va_mode;
13917c478bd9Sstevel@tonic-gate 
139293239addSjohnlev 	dev = *pdev = bvp->v_rdev;
139393239addSjohnlev 
139493239addSjohnlev 	error = EBUSY;
13957c478bd9Sstevel@tonic-gate 
13967c478bd9Sstevel@tonic-gate 	/*
13977c478bd9Sstevel@tonic-gate 	 * Ensure that this device isn't already mounted,
13987c478bd9Sstevel@tonic-gate 	 * unless this is a REMOUNT request or we are told to suppress
13997c478bd9Sstevel@tonic-gate 	 * mount checks.
14007c478bd9Sstevel@tonic-gate 	 */
14017c478bd9Sstevel@tonic-gate 	if ((flags & MS_NOCHECK) == 0) {
14027c478bd9Sstevel@tonic-gate 		if (vfs_devmounting(dev, vfsp))
140393239addSjohnlev 			goto out;
14047c478bd9Sstevel@tonic-gate 		if (vfs_devismounted(dev) && !(flags & MS_REMOUNT))
140593239addSjohnlev 			goto out;
14067c478bd9Sstevel@tonic-gate 	}
14077c478bd9Sstevel@tonic-gate 
140893239addSjohnlev 	if (getmajor(*pdev) >= devcnt) {
140993239addSjohnlev 		error = ENXIO;
141093239addSjohnlev 		goto out;
141193239addSjohnlev 	}
141293239addSjohnlev 
141393239addSjohnlev 	error = 0;
141493239addSjohnlev out:
141593239addSjohnlev 	if (svp != NULL)
141693239addSjohnlev 		VN_RELE(svp);
141793239addSjohnlev 	if (lvp != NULL)
141893239addSjohnlev 		VN_RELE(lvp);
141993239addSjohnlev 	return (error);
14207c478bd9Sstevel@tonic-gate }
14217c478bd9Sstevel@tonic-gate 
14227c478bd9Sstevel@tonic-gate static void
hs_copylabel(struct hs_volume * hvp,unsigned char * label,int isjoliet)1423fc1c62b8Sfrankho hs_copylabel(struct hs_volume *hvp, unsigned char *label, int isjoliet)
14247c478bd9Sstevel@tonic-gate {
1425fc1c62b8Sfrankho 	char	lbuf[64];	/* hs_joliet_cp() creates 48 bytes at most */
1426fc1c62b8Sfrankho 
1427fc1c62b8Sfrankho 	if (isjoliet) {
1428fc1c62b8Sfrankho 		/*
1429fc1c62b8Sfrankho 		 * hs_joliet_cp() will output 16..48 bytes.
1430fc1c62b8Sfrankho 		 * We need to clear 'lbuf' to avoid junk chars past byte 15.
1431fc1c62b8Sfrankho 		 */
1432fc1c62b8Sfrankho 		bzero(lbuf, sizeof (lbuf));
1433663e0ec4Sfrankho 		(void) hs_joliet_cp((char *)label, lbuf, 32);
1434fc1c62b8Sfrankho 		label = (unsigned char *)lbuf;
1435fc1c62b8Sfrankho 	}
14367c478bd9Sstevel@tonic-gate 	/* cdrom volid is at most 32 bytes */
14377c478bd9Sstevel@tonic-gate 	bcopy(label, hvp->vol_id, 32);
1438*55bd65d2SToomas Soome 	hvp->vol_id[31] = '\0';
14397c478bd9Sstevel@tonic-gate }
14407c478bd9Sstevel@tonic-gate 
14417c478bd9Sstevel@tonic-gate /*
14427c478bd9Sstevel@tonic-gate  * Mount root file system.
14437c478bd9Sstevel@tonic-gate  * "why" is ROOT_INIT on initial call, ROOT_REMOUNT if called to
14447c478bd9Sstevel@tonic-gate  * remount the root file system, and ROOT_UNMOUNT if called to
14457c478bd9Sstevel@tonic-gate  * unmount the root (e.g., as part of a system shutdown).
14467c478bd9Sstevel@tonic-gate  *
14477c478bd9Sstevel@tonic-gate  * XXX - this may be partially machine-dependent; it, along with the VFS_SWAPVP
14487c478bd9Sstevel@tonic-gate  * operation, goes along with auto-configuration.  A mechanism should be
14497c478bd9Sstevel@tonic-gate  * provided by which machine-INdependent code in the kernel can say "get me the
14507c478bd9Sstevel@tonic-gate  * right root file system" and "get me the right initial swap area", and have
14517c478bd9Sstevel@tonic-gate  * that done in what may well be a machine-dependent fashion.
14527c478bd9Sstevel@tonic-gate  * Unfortunately, it is also file-system-type dependent (NFS gets it via
14537c478bd9Sstevel@tonic-gate  * bootparams calls, UFS gets it from various and sundry machine-dependent
14547c478bd9Sstevel@tonic-gate  * mechanisms, as SPECFS does for swap).
14557c478bd9Sstevel@tonic-gate  */
14567c478bd9Sstevel@tonic-gate static int
hsfs_mountroot(struct vfs * vfsp,enum whymountroot why)14577c478bd9Sstevel@tonic-gate hsfs_mountroot(struct vfs *vfsp, enum whymountroot why)
14587c478bd9Sstevel@tonic-gate {
14597c478bd9Sstevel@tonic-gate 	int error;
14607c478bd9Sstevel@tonic-gate 	struct hsfs *fsp;
14617c478bd9Sstevel@tonic-gate 	struct hs_volume *fvolp;
14627c478bd9Sstevel@tonic-gate 	static int hsfsrootdone = 0;
14637c478bd9Sstevel@tonic-gate 	dev_t rootdev;
14647c478bd9Sstevel@tonic-gate 	mode_t mode = 0;
14657c478bd9Sstevel@tonic-gate 
14667c478bd9Sstevel@tonic-gate 	if (why == ROOT_INIT) {
14677c478bd9Sstevel@tonic-gate 		if (hsfsrootdone++)
14687c478bd9Sstevel@tonic-gate 			return (EBUSY);
14697c478bd9Sstevel@tonic-gate 		rootdev = getrootdev();
14707c478bd9Sstevel@tonic-gate 		if (rootdev == (dev_t)NODEV)
14717c478bd9Sstevel@tonic-gate 			return (ENODEV);
14727c478bd9Sstevel@tonic-gate 		vfsp->vfs_dev = rootdev;
14737c478bd9Sstevel@tonic-gate 		vfsp->vfs_flag |= VFS_RDONLY;
14747c478bd9Sstevel@tonic-gate 	} else if (why == ROOT_REMOUNT) {
14757c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "hsfs_mountroot: ROOT_REMOUNT");
14767c478bd9Sstevel@tonic-gate 		return (0);
14777c478bd9Sstevel@tonic-gate 	} else if (why == ROOT_UNMOUNT) {
14787c478bd9Sstevel@tonic-gate 		return (0);
14797c478bd9Sstevel@tonic-gate 	}
14807c478bd9Sstevel@tonic-gate 	error = vfs_lock(vfsp);
14817c478bd9Sstevel@tonic-gate 	if (error) {
14827c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "hsfs_mountroot: couldn't get vfs_lock");
14837c478bd9Sstevel@tonic-gate 		return (error);
14847c478bd9Sstevel@tonic-gate 	}
14857c478bd9Sstevel@tonic-gate 
14867c478bd9Sstevel@tonic-gate 	error = hs_mountfs(vfsp, rootdev, "/", mode, 1, CRED(), 1);
14877c478bd9Sstevel@tonic-gate 	/*
14887c478bd9Sstevel@tonic-gate 	 * XXX - assumes root device is not indirect, because we don't set
14897c478bd9Sstevel@tonic-gate 	 * rootvp.  Is rootvp used for anything?  If so, make another arg
14907c478bd9Sstevel@tonic-gate 	 * to mountfs.
14917c478bd9Sstevel@tonic-gate 	 */
14927c478bd9Sstevel@tonic-gate 	if (error) {
14937c478bd9Sstevel@tonic-gate 		vfs_unlock(vfsp);
14947c478bd9Sstevel@tonic-gate 		if (rootvp) {
14957c478bd9Sstevel@tonic-gate 			VN_RELE(rootvp);
14967c478bd9Sstevel@tonic-gate 			rootvp = (struct vnode *)0;
14977c478bd9Sstevel@tonic-gate 		}
14987c478bd9Sstevel@tonic-gate 		return (error);
14997c478bd9Sstevel@tonic-gate 	}
15007c478bd9Sstevel@tonic-gate 	if (why == ROOT_INIT)
15017c478bd9Sstevel@tonic-gate 		vfs_add((struct vnode *)0, vfsp,
15027c478bd9Sstevel@tonic-gate 		    (vfsp->vfs_flag & VFS_RDONLY) ? MS_RDONLY : 0);
15037c478bd9Sstevel@tonic-gate 	vfs_unlock(vfsp);
15047c478bd9Sstevel@tonic-gate 	fsp = VFS_TO_HSFS(vfsp);
15057c478bd9Sstevel@tonic-gate 	fvolp = &fsp->hsfs_vol;
15067c478bd9Sstevel@tonic-gate #ifdef HSFS_CLKSET
15077c478bd9Sstevel@tonic-gate 	if (fvolp->cre_date.tv_sec == 0) {
1508d10b6702Sfrankho 		cmn_err(CE_NOTE, "hsfs_mountroot: cre_date.tv_sec == 0");
1509d10b6702Sfrankho 		if (fvolp->mod_date.tv_sec == 0) {
1510d10b6702Sfrankho 			cmn_err(CE_NOTE,
1511d10b6702Sfrankho 			    "hsfs_mountroot: mod_date.tv_sec == 0");
1512d10b6702Sfrankho 			cmn_err(CE_NOTE, "hsfs_mountroot: clkset(-1L)");
1513d10b6702Sfrankho 			clkset(-1L);
1514d10b6702Sfrankho 		} else {
1515d10b6702Sfrankho 			clkset(fvolp->mod_date.tv_sec);
1516d10b6702Sfrankho 		}
1517d10b6702Sfrankho 	} else {
15187c478bd9Sstevel@tonic-gate 		clkset(fvolp->mod_date.tv_sec);
1519d10b6702Sfrankho 	}
15207c478bd9Sstevel@tonic-gate #else	/* HSFS_CLKSET */
15217c478bd9Sstevel@tonic-gate 	clkset(-1L);
15227c478bd9Sstevel@tonic-gate #endif	/* HSFS_CLKSET */
15237c478bd9Sstevel@tonic-gate 	return (0);
15247c478bd9Sstevel@tonic-gate }
15257c478bd9Sstevel@tonic-gate 
15267c478bd9Sstevel@tonic-gate /*
15277c478bd9Sstevel@tonic-gate  * hs_findvoldesc()
15287c478bd9Sstevel@tonic-gate  *
15297c478bd9Sstevel@tonic-gate  * Return the sector where the volume descriptor lives.  This is
15307c478bd9Sstevel@tonic-gate  * a fixed value for "normal" cd-rom's, but can change for
15317c478bd9Sstevel@tonic-gate  * multisession cd's.
15327c478bd9Sstevel@tonic-gate  *
15337c478bd9Sstevel@tonic-gate  * desc_sec is the same for high-sierra and iso 9660 formats, why
1534da6c28aaSamw  * there are two different #defines used in the code for this is
15357c478bd9Sstevel@tonic-gate  * beyond me.  These are standards, cast in concrete, right?
15367c478bd9Sstevel@tonic-gate  * To be general, however, this function supports passing in different
15377c478bd9Sstevel@tonic-gate  * values.
15387c478bd9Sstevel@tonic-gate  */
15397c478bd9Sstevel@tonic-gate static int
hs_findvoldesc(dev_t rdev,int desc_sec)15407c478bd9Sstevel@tonic-gate hs_findvoldesc(dev_t rdev, int desc_sec)
15417c478bd9Sstevel@tonic-gate {
15427c478bd9Sstevel@tonic-gate 	int secno;
15437c478bd9Sstevel@tonic-gate 	int error;
15447c478bd9Sstevel@tonic-gate 	int rval;	/* ignored */
15457c478bd9Sstevel@tonic-gate 
15467c478bd9Sstevel@tonic-gate #ifdef CDROMREADOFFSET
15477c478bd9Sstevel@tonic-gate 	/*
15487c478bd9Sstevel@tonic-gate 	 * Issue the Read Offset ioctl directly to the
15497c478bd9Sstevel@tonic-gate 	 * device. Ignore any errors and set starting
15507c478bd9Sstevel@tonic-gate 	 * secno to the default, otherwise add the
15517c478bd9Sstevel@tonic-gate 	 * VOLDESC sector number to the offset.
15527c478bd9Sstevel@tonic-gate 	 */
15537c478bd9Sstevel@tonic-gate 	error = cdev_ioctl(rdev, CDROMREADOFFSET, (intptr_t)&secno,
15547c478bd9Sstevel@tonic-gate 	    FNATIVE|FKIOCTL|FREAD, CRED(), &rval);
15557c478bd9Sstevel@tonic-gate 	if (error) {
15567c478bd9Sstevel@tonic-gate 		secno = desc_sec;
15577c478bd9Sstevel@tonic-gate 	} else {
15587c478bd9Sstevel@tonic-gate 		secno += desc_sec;
15597c478bd9Sstevel@tonic-gate 	}
15607c478bd9Sstevel@tonic-gate #else
15617c478bd9Sstevel@tonic-gate 	secno = desc_sec;
15627c478bd9Sstevel@tonic-gate #endif
15637c478bd9Sstevel@tonic-gate 
15647c478bd9Sstevel@tonic-gate 	return (secno);
15657c478bd9Sstevel@tonic-gate }
1566