xref: /illumos-gate/usr/src/uts/common/fs/pcfs/pc_vfsops.c (revision 90c30842)
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
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/param.h>
307c478bd9Sstevel@tonic-gate #include <sys/systm.h>
317c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
327c478bd9Sstevel@tonic-gate #include <sys/user.h>
337c478bd9Sstevel@tonic-gate #include <sys/proc.h>
347c478bd9Sstevel@tonic-gate #include <sys/cred.h>
357c478bd9Sstevel@tonic-gate #include <sys/disp.h>
367c478bd9Sstevel@tonic-gate #include <sys/buf.h>
377c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
387c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
397c478bd9Sstevel@tonic-gate #include <sys/fdio.h>
407c478bd9Sstevel@tonic-gate #include <sys/file.h>
417c478bd9Sstevel@tonic-gate #include <sys/uio.h>
427c478bd9Sstevel@tonic-gate #include <sys/conf.h>
437c478bd9Sstevel@tonic-gate #undef NFSCLIENT
447c478bd9Sstevel@tonic-gate #include <sys/statvfs.h>
457c478bd9Sstevel@tonic-gate #include <sys/mount.h>
467c478bd9Sstevel@tonic-gate #include <sys/pathname.h>
477c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
487c478bd9Sstevel@tonic-gate #include <sys/debug.h>
497c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
507c478bd9Sstevel@tonic-gate #include <sys/conf.h>
517c478bd9Sstevel@tonic-gate #include <sys/mkdev.h>
527c478bd9Sstevel@tonic-gate #include <sys/swap.h>
537c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
547c478bd9Sstevel@tonic-gate #include <sys/sunldi.h>
557c478bd9Sstevel@tonic-gate #include <sys/dktp/fdisk.h>
567c478bd9Sstevel@tonic-gate #include <sys/fs/pc_label.h>
577c478bd9Sstevel@tonic-gate #include <sys/fs/pc_fs.h>
587c478bd9Sstevel@tonic-gate #include <sys/fs/pc_dir.h>
597c478bd9Sstevel@tonic-gate #include <sys/fs/pc_node.h>
607c478bd9Sstevel@tonic-gate #include <fs/fs_subr.h>
617c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
627c478bd9Sstevel@tonic-gate #include <sys/vol.h>
637c478bd9Sstevel@tonic-gate #include <sys/dkio.h>
647c478bd9Sstevel@tonic-gate #include <sys/open.h>
657c478bd9Sstevel@tonic-gate #include <sys/mntent.h>
667c478bd9Sstevel@tonic-gate #include <sys/policy.h>
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /*
697c478bd9Sstevel@tonic-gate  * The majority of PC media use a 512 sector size, but
707c478bd9Sstevel@tonic-gate  * occasionally you will run across a 1k sector size.
717c478bd9Sstevel@tonic-gate  * For media with a 1k sector size, fd_strategy() requires
727c478bd9Sstevel@tonic-gate  * the I/O size to be a 1k multiple; so when the sector size
737c478bd9Sstevel@tonic-gate  * is not yet known, always read 1k.
747c478bd9Sstevel@tonic-gate  */
757c478bd9Sstevel@tonic-gate #define	PC_SAFESECSIZE	(PC_SECSIZE * 2)
767c478bd9Sstevel@tonic-gate 
77*90c30842Sjmcp static int pcfs_pseudo_floppy(dev_t);
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate static int pcfsinit(int, char *);
807c478bd9Sstevel@tonic-gate static int pcfs_mount(struct vfs *, struct vnode *, struct mounta *,
817c478bd9Sstevel@tonic-gate 	struct cred *);
827c478bd9Sstevel@tonic-gate static int pcfs_unmount(struct vfs *, int, struct cred *);
837c478bd9Sstevel@tonic-gate static int pcfs_root(struct vfs *, struct vnode **);
847c478bd9Sstevel@tonic-gate static int pcfs_statvfs(struct vfs *, struct statvfs64 *);
857c478bd9Sstevel@tonic-gate static int pc_syncfsnodes(struct pcfs *);
867c478bd9Sstevel@tonic-gate static int pcfs_sync(struct vfs *, short, struct cred *);
877c478bd9Sstevel@tonic-gate static int pcfs_vget(struct vfs *vfsp, struct vnode **vpp, struct fid *fidp);
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate static int pc_getfattype(struct vnode *, int, daddr_t *, int *);
907c478bd9Sstevel@tonic-gate static int pc_readfat(struct pcfs *fsp, uchar_t *fatp, daddr_t start,
917c478bd9Sstevel@tonic-gate     size_t fatsize);
927c478bd9Sstevel@tonic-gate static int pc_writefat(struct pcfs *fsp, daddr_t start);
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate /*
957c478bd9Sstevel@tonic-gate  * pcfs mount options table
967c478bd9Sstevel@tonic-gate  */
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate static char *nohidden_cancel[] = {MNTOPT_PCFS_HIDDEN, NULL};
997c478bd9Sstevel@tonic-gate static char *hidden_cancel[] = {MNTOPT_PCFS_NOHIDDEN, NULL};
1007c478bd9Sstevel@tonic-gate static char *nofoldcase_cancel[] = {MNTOPT_PCFS_FOLDCASE, NULL};
1017c478bd9Sstevel@tonic-gate static char *foldcase_cancel[] = {MNTOPT_PCFS_NOFOLDCASE, NULL};
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate static mntopt_t mntopts[] = {
1047c478bd9Sstevel@tonic-gate /*
1057c478bd9Sstevel@tonic-gate  *	option name		cancel option	default arg	flags
1067c478bd9Sstevel@tonic-gate  *		opt data
1077c478bd9Sstevel@tonic-gate  */
1087c478bd9Sstevel@tonic-gate 	{ MNTOPT_PCFS_NOHIDDEN,	nohidden_cancel, NULL,		MO_DEFAULT,
1097c478bd9Sstevel@tonic-gate 		NULL },
1107c478bd9Sstevel@tonic-gate 	{ MNTOPT_PCFS_HIDDEN,	hidden_cancel, NULL,		0,
1117c478bd9Sstevel@tonic-gate 		NULL },
1127c478bd9Sstevel@tonic-gate 	{ MNTOPT_PCFS_NOFOLDCASE, nofoldcase_cancel, NULL,	MO_DEFAULT,
1137c478bd9Sstevel@tonic-gate 		NULL },
1147c478bd9Sstevel@tonic-gate 	{ MNTOPT_PCFS_FOLDCASE,	foldcase_cancel, NULL,		0,
1157c478bd9Sstevel@tonic-gate 		NULL }
1167c478bd9Sstevel@tonic-gate };
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate static mntopts_t pcfs_mntopts = {
1197c478bd9Sstevel@tonic-gate 	sizeof (mntopts) / sizeof (mntopt_t),
1207c478bd9Sstevel@tonic-gate 	mntopts
1217c478bd9Sstevel@tonic-gate };
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate int pcfsdebuglevel = 0;
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate /*
1267c478bd9Sstevel@tonic-gate  * pcfslock:	protects the list of mounted pc filesystems "pc_mounttab.
1277c478bd9Sstevel@tonic-gate  * pcfs_lock:	(inside per filesystem structure "pcfs")
1287c478bd9Sstevel@tonic-gate  *		per filesystem lock. Most of the vfsops and vnodeops are
1297c478bd9Sstevel@tonic-gate  *		protected by this lock.
1307c478bd9Sstevel@tonic-gate  * pcnodes_lock: protects the pcnode hash table "pcdhead", "pcfhead".
1317c478bd9Sstevel@tonic-gate  *
1327c478bd9Sstevel@tonic-gate  * Lock hierarchy: pcfslock > pcfs_lock > pcnodes_lock
1337c478bd9Sstevel@tonic-gate  */
1347c478bd9Sstevel@tonic-gate kmutex_t	pcfslock;
1357c478bd9Sstevel@tonic-gate krwlock_t pcnodes_lock; /* protect the pcnode hash table "pcdhead", "pcfhead" */
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate static int pcfstype;
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate static vfsdef_t vfw = {
1407c478bd9Sstevel@tonic-gate 	VFSDEF_VERSION,
1417c478bd9Sstevel@tonic-gate 	"pcfs",
1427c478bd9Sstevel@tonic-gate 	pcfsinit,
1437c478bd9Sstevel@tonic-gate 	VSW_HASPROTO|VSW_CANREMOUNT,
1447c478bd9Sstevel@tonic-gate 	&pcfs_mntopts
1457c478bd9Sstevel@tonic-gate };
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate extern struct mod_ops mod_fsops;
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate static struct modlfs modlfs = {
1507c478bd9Sstevel@tonic-gate 	&mod_fsops,
151*90c30842Sjmcp 	"PC filesystem v%I%",
1527c478bd9Sstevel@tonic-gate 	&vfw
1537c478bd9Sstevel@tonic-gate };
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
1567c478bd9Sstevel@tonic-gate 	MODREV_1,
1577c478bd9Sstevel@tonic-gate 	&modlfs,
1587c478bd9Sstevel@tonic-gate 	NULL
1597c478bd9Sstevel@tonic-gate };
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate int
1627c478bd9Sstevel@tonic-gate _init(void)
1637c478bd9Sstevel@tonic-gate {
1647c478bd9Sstevel@tonic-gate 	int	error;
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate #if !defined(lint)
1677c478bd9Sstevel@tonic-gate 	/* make sure the on-disk structures are sane */
1687c478bd9Sstevel@tonic-gate 	ASSERT(sizeof (struct pcdir) == 32);
1697c478bd9Sstevel@tonic-gate 	ASSERT(sizeof (struct pcdir_lfn) == 32);
1707c478bd9Sstevel@tonic-gate #endif
1717c478bd9Sstevel@tonic-gate 	mutex_init(&pcfslock, NULL, MUTEX_DEFAULT, NULL);
1727c478bd9Sstevel@tonic-gate 	rw_init(&pcnodes_lock, NULL, RW_DEFAULT, NULL);
1737c478bd9Sstevel@tonic-gate 	error = mod_install(&modlinkage);
1747c478bd9Sstevel@tonic-gate 	if (error) {
1757c478bd9Sstevel@tonic-gate 		mutex_destroy(&pcfslock);
1767c478bd9Sstevel@tonic-gate 		rw_destroy(&pcnodes_lock);
1777c478bd9Sstevel@tonic-gate 	}
1787c478bd9Sstevel@tonic-gate 	return (error);
1797c478bd9Sstevel@tonic-gate }
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate int
1827c478bd9Sstevel@tonic-gate _fini(void)
1837c478bd9Sstevel@tonic-gate {
1847c478bd9Sstevel@tonic-gate 	int	error;
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate 	error = mod_remove(&modlinkage);
1877c478bd9Sstevel@tonic-gate 	if (error)
1887c478bd9Sstevel@tonic-gate 		return (error);
1897c478bd9Sstevel@tonic-gate 	mutex_destroy(&pcfslock);
1907c478bd9Sstevel@tonic-gate 	rw_destroy(&pcnodes_lock);
1917c478bd9Sstevel@tonic-gate 	/*
1927c478bd9Sstevel@tonic-gate 	 * Tear down the operations vectors
1937c478bd9Sstevel@tonic-gate 	 */
1947c478bd9Sstevel@tonic-gate 	(void) vfs_freevfsops_by_type(pcfstype);
1957c478bd9Sstevel@tonic-gate 	vn_freevnodeops(pcfs_fvnodeops);
1967c478bd9Sstevel@tonic-gate 	vn_freevnodeops(pcfs_dvnodeops);
1977c478bd9Sstevel@tonic-gate 	return (0);
1987c478bd9Sstevel@tonic-gate }
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate int
2017c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
2027c478bd9Sstevel@tonic-gate {
2037c478bd9Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
2047c478bd9Sstevel@tonic-gate }
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate /* ARGSUSED1 */
2077c478bd9Sstevel@tonic-gate static int
2087c478bd9Sstevel@tonic-gate pcfsinit(int fstype, char *name)
2097c478bd9Sstevel@tonic-gate {
2107c478bd9Sstevel@tonic-gate 	static const fs_operation_def_t pcfs_vfsops_template[] = {
2117c478bd9Sstevel@tonic-gate 		VFSNAME_MOUNT, pcfs_mount,
2127c478bd9Sstevel@tonic-gate 		VFSNAME_UNMOUNT, pcfs_unmount,
2137c478bd9Sstevel@tonic-gate 		VFSNAME_ROOT, pcfs_root,
2147c478bd9Sstevel@tonic-gate 		VFSNAME_STATVFS, pcfs_statvfs,
2157c478bd9Sstevel@tonic-gate 		VFSNAME_SYNC, (fs_generic_func_p) pcfs_sync,
2167c478bd9Sstevel@tonic-gate 		VFSNAME_VGET, pcfs_vget,
2177c478bd9Sstevel@tonic-gate 		NULL, NULL
2187c478bd9Sstevel@tonic-gate 	};
2197c478bd9Sstevel@tonic-gate 	int error;
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate 	error = vfs_setfsops(fstype, pcfs_vfsops_template, NULL);
2227c478bd9Sstevel@tonic-gate 	if (error != 0) {
2237c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "pcfsinit: bad vfs ops template");
2247c478bd9Sstevel@tonic-gate 		return (error);
2257c478bd9Sstevel@tonic-gate 	}
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 	error = vn_make_ops("pcfs", pcfs_fvnodeops_template, &pcfs_fvnodeops);
2287c478bd9Sstevel@tonic-gate 	if (error != 0) {
2297c478bd9Sstevel@tonic-gate 		(void) vfs_freevfsops_by_type(fstype);
2307c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "pcfsinit: bad file vnode ops template");
2317c478bd9Sstevel@tonic-gate 		return (error);
2327c478bd9Sstevel@tonic-gate 	}
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate 	error = vn_make_ops("pcfsd", pcfs_dvnodeops_template, &pcfs_dvnodeops);
2357c478bd9Sstevel@tonic-gate 	if (error != 0) {
2367c478bd9Sstevel@tonic-gate 		(void) vfs_freevfsops_by_type(fstype);
2377c478bd9Sstevel@tonic-gate 		vn_freevnodeops(pcfs_fvnodeops);
2387c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "pcfsinit: bad dir vnode ops template");
2397c478bd9Sstevel@tonic-gate 		return (error);
2407c478bd9Sstevel@tonic-gate 	}
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate 	pcfstype = fstype;
2437c478bd9Sstevel@tonic-gate 	(void) pc_init();
2447c478bd9Sstevel@tonic-gate 	return (0);
2457c478bd9Sstevel@tonic-gate }
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate static struct pcfs *pc_mounttab = NULL;
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate extern struct pcfs_args pc_tz;
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate /*
2527c478bd9Sstevel@tonic-gate  *  Define some special logical drives we use internal to this file.
2537c478bd9Sstevel@tonic-gate  */
2547c478bd9Sstevel@tonic-gate #define	BOOT_PARTITION_DRIVE	99
2557c478bd9Sstevel@tonic-gate #define	PRIMARY_DOS_DRIVE	1
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate /*
2587c478bd9Sstevel@tonic-gate  * pc_mount system call
2597c478bd9Sstevel@tonic-gate  */
2607c478bd9Sstevel@tonic-gate static int
2617c478bd9Sstevel@tonic-gate pcfs_mount(
2627c478bd9Sstevel@tonic-gate 	struct vfs *vfsp,
2637c478bd9Sstevel@tonic-gate 	struct vnode *mvp,
2647c478bd9Sstevel@tonic-gate 	struct mounta *uap,
2657c478bd9Sstevel@tonic-gate 	struct cred *cr)
2667c478bd9Sstevel@tonic-gate {
2677c478bd9Sstevel@tonic-gate 	struct pcfs *fsp;
2687c478bd9Sstevel@tonic-gate 	struct vnode *bvp;
2697c478bd9Sstevel@tonic-gate 	struct vnode *devvp;
2707c478bd9Sstevel@tonic-gate 	struct pathname special;
2717c478bd9Sstevel@tonic-gate 	daddr_t dosstart;
2727c478bd9Sstevel@tonic-gate 	dev_t pseudodev;
2737c478bd9Sstevel@tonic-gate 	dev_t xdev;
2747c478bd9Sstevel@tonic-gate 	char *spnp;
2757c478bd9Sstevel@tonic-gate 	char *data = uap->dataptr;
2767c478bd9Sstevel@tonic-gate 	int datalen = uap->datalen;
2777c478bd9Sstevel@tonic-gate 	int dos_ldrive = 0;
2787c478bd9Sstevel@tonic-gate 	int error;
2797c478bd9Sstevel@tonic-gate 	int fattype;
2807c478bd9Sstevel@tonic-gate 	int spnlen;
2817c478bd9Sstevel@tonic-gate 	int wantbootpart = 0;
2827c478bd9Sstevel@tonic-gate 	struct vioc_info info;
2837c478bd9Sstevel@tonic-gate 	int rval;		/* set but not used */
2847c478bd9Sstevel@tonic-gate 	minor_t	minor;
2857c478bd9Sstevel@tonic-gate 	int oflag, aflag;
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate 	if ((error = secpolicy_fs_mount(cr, mvp, vfsp)) != 0)
2887c478bd9Sstevel@tonic-gate 		return (error);
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 	PC_DPRINTF0(4, "pcfs_mount\n");
2917c478bd9Sstevel@tonic-gate 	if (mvp->v_type != VDIR) {
2927c478bd9Sstevel@tonic-gate 		return (ENOTDIR);
2937c478bd9Sstevel@tonic-gate 	}
2947c478bd9Sstevel@tonic-gate 	mutex_enter(&mvp->v_lock);
2957c478bd9Sstevel@tonic-gate 	if ((uap->flags & MS_REMOUNT) == 0 &&
2967c478bd9Sstevel@tonic-gate 	    (uap->flags & MS_OVERLAY) == 0 &&
2977c478bd9Sstevel@tonic-gate 	    (mvp->v_count != 1 || (mvp->v_flag & VROOT))) {
2987c478bd9Sstevel@tonic-gate 		mutex_exit(&mvp->v_lock);
2997c478bd9Sstevel@tonic-gate 		return (EBUSY);
3007c478bd9Sstevel@tonic-gate 	}
3017c478bd9Sstevel@tonic-gate 	mutex_exit(&mvp->v_lock);
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate 	/*
3047c478bd9Sstevel@tonic-gate 	 * The caller is responsible for making sure to always
3057c478bd9Sstevel@tonic-gate 	 * pass in sizeof(struct pcfs_args) (or the old one).
3067c478bd9Sstevel@tonic-gate 	 * Doing this is the only way to know an EINVAL return
3077c478bd9Sstevel@tonic-gate 	 * from mount(2) is due to the "not a DOS filesystem"
3087c478bd9Sstevel@tonic-gate 	 * EINVAL that pc_verify/pc_getfattype could return.
3097c478bd9Sstevel@tonic-gate 	 */
3107c478bd9Sstevel@tonic-gate 	if ((datalen != sizeof (struct pcfs_args)) &&
3117c478bd9Sstevel@tonic-gate 	    (datalen != sizeof (struct old_pcfs_args))) {
3127c478bd9Sstevel@tonic-gate 		return (EINVAL);
3137c478bd9Sstevel@tonic-gate 	} else {
3147c478bd9Sstevel@tonic-gate 		struct pcfs_args tmp_tz;
3157c478bd9Sstevel@tonic-gate 		int hidden = 0;
3167c478bd9Sstevel@tonic-gate 		int foldcase = 0;
3177c478bd9Sstevel@tonic-gate 
3187c478bd9Sstevel@tonic-gate 		tmp_tz.flags = 0;
3197c478bd9Sstevel@tonic-gate 		if (copyin(data, &tmp_tz, datalen)) {
3207c478bd9Sstevel@tonic-gate 			return (EFAULT);
3217c478bd9Sstevel@tonic-gate 		}
3227c478bd9Sstevel@tonic-gate 		if (datalen == sizeof (struct pcfs_args)) {
3237c478bd9Sstevel@tonic-gate 			hidden = tmp_tz.flags & PCFS_MNT_HIDDEN;
3247c478bd9Sstevel@tonic-gate 			foldcase = tmp_tz.flags & PCFS_MNT_FOLDCASE;
3257c478bd9Sstevel@tonic-gate 		}
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate 		if (hidden)
3287c478bd9Sstevel@tonic-gate 			vfs_setmntopt(vfsp, MNTOPT_PCFS_HIDDEN,	NULL, 0);
3297c478bd9Sstevel@tonic-gate 		if (foldcase)
3307c478bd9Sstevel@tonic-gate 			vfs_setmntopt(vfsp, MNTOPT_PCFS_FOLDCASE, NULL, 0);
3317c478bd9Sstevel@tonic-gate 		/*
3327c478bd9Sstevel@tonic-gate 		 * more than one pc filesystem can be mounted on x86
3337c478bd9Sstevel@tonic-gate 		 * so the pc_tz structure is now a critical region
3347c478bd9Sstevel@tonic-gate 		 */
3357c478bd9Sstevel@tonic-gate 		mutex_enter(&pcfslock);
3367c478bd9Sstevel@tonic-gate 		if (pc_mounttab == NULL)
3377c478bd9Sstevel@tonic-gate 			bcopy(&tmp_tz, &pc_tz, sizeof (struct pcfs_args));
3387c478bd9Sstevel@tonic-gate 		mutex_exit(&pcfslock);
3397c478bd9Sstevel@tonic-gate 	}
3407c478bd9Sstevel@tonic-gate 	/*
3417c478bd9Sstevel@tonic-gate 	 * Resolve path name of special file being mounted.
3427c478bd9Sstevel@tonic-gate 	 */
3437c478bd9Sstevel@tonic-gate 	if (error = pn_get(uap->spec, UIO_USERSPACE, &special)) {
3447c478bd9Sstevel@tonic-gate 		return (error);
3457c478bd9Sstevel@tonic-gate 	}
3467c478bd9Sstevel@tonic-gate 	if (error =
3477c478bd9Sstevel@tonic-gate 	    lookupname(special.pn_path, UIO_SYSSPACE, FOLLOW, NULLVPP, &bvp)) {
3487c478bd9Sstevel@tonic-gate 		/*
3497c478bd9Sstevel@tonic-gate 		 * look for suffix to special
3507c478bd9Sstevel@tonic-gate 		 * which indicates a request to mount the solaris boot
3517c478bd9Sstevel@tonic-gate 		 * partition, or a DOS logical drive on the hard disk
3527c478bd9Sstevel@tonic-gate 		 */
3537c478bd9Sstevel@tonic-gate 		spnlen = special.pn_pathlen;
3547c478bd9Sstevel@tonic-gate 
3557c478bd9Sstevel@tonic-gate 		if (spnlen > 5) {
3567c478bd9Sstevel@tonic-gate 			spnp = special.pn_path + spnlen - 5;
3577c478bd9Sstevel@tonic-gate 			if (*spnp++ == ':' && *spnp++ == 'b' &&
3587c478bd9Sstevel@tonic-gate 			    *spnp++ == 'o' && *spnp++ == 'o' &&
3597c478bd9Sstevel@tonic-gate 			    *spnp++ == 't') {
3607c478bd9Sstevel@tonic-gate 				/*
3617c478bd9Sstevel@tonic-gate 				 * Looks as if they want to mount
3627c478bd9Sstevel@tonic-gate 				 * the Solaris boot partition
3637c478bd9Sstevel@tonic-gate 				 */
3647c478bd9Sstevel@tonic-gate 				wantbootpart = 1;
3657c478bd9Sstevel@tonic-gate 				dos_ldrive = BOOT_PARTITION_DRIVE;
3667c478bd9Sstevel@tonic-gate 				spnp = special.pn_path + spnlen - 5;
3677c478bd9Sstevel@tonic-gate 				*spnp = '\0';
3687c478bd9Sstevel@tonic-gate 				error = lookupname(special.pn_path,
3697c478bd9Sstevel@tonic-gate 				    UIO_SYSSPACE, FOLLOW, NULLVPP, &bvp);
3707c478bd9Sstevel@tonic-gate 			}
3717c478bd9Sstevel@tonic-gate 		}
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate 		if (!wantbootpart) {
3747c478bd9Sstevel@tonic-gate 			spnp = special.pn_path + spnlen - 1;
3757c478bd9Sstevel@tonic-gate 			if (spnlen > 2 && *spnp >= 'c' && *spnp <= 'z') {
3767c478bd9Sstevel@tonic-gate 				spnlen--;
3777c478bd9Sstevel@tonic-gate 				dos_ldrive = *spnp-- - 'c' + 1;
3787c478bd9Sstevel@tonic-gate 			} else if (spnlen > 2 && *spnp >= '0' && *spnp <= '9') {
3797c478bd9Sstevel@tonic-gate 				spnlen--;
3807c478bd9Sstevel@tonic-gate 				dos_ldrive = *spnp-- - '0';
3817c478bd9Sstevel@tonic-gate 				if (spnlen > 2 && *spnp >= '0' &&
3827c478bd9Sstevel@tonic-gate 				    *spnp <= '9') {
3837c478bd9Sstevel@tonic-gate 					spnlen--;
3847c478bd9Sstevel@tonic-gate 					dos_ldrive += 10 * (*spnp-- - '0');
3857c478bd9Sstevel@tonic-gate 				}
3867c478bd9Sstevel@tonic-gate 			}
3877c478bd9Sstevel@tonic-gate 			if (spnlen > 1 && dos_ldrive && dos_ldrive <= 24 &&
3887c478bd9Sstevel@tonic-gate 			    *spnp == ':') {
3897c478bd9Sstevel@tonic-gate 				/*
3907c478bd9Sstevel@tonic-gate 				 * remove suffix so that we have a real
3917c478bd9Sstevel@tonic-gate 				 * device name
3927c478bd9Sstevel@tonic-gate 				 */
3937c478bd9Sstevel@tonic-gate 				*spnp = '\0';
3947c478bd9Sstevel@tonic-gate 				error = lookupname(special.pn_path,
3957c478bd9Sstevel@tonic-gate 				    UIO_SYSSPACE, FOLLOW, NULLVPP, &bvp);
3967c478bd9Sstevel@tonic-gate 			}
3977c478bd9Sstevel@tonic-gate 		}
3987c478bd9Sstevel@tonic-gate 		if (error) {
3997c478bd9Sstevel@tonic-gate 			pn_free(&special);
4007c478bd9Sstevel@tonic-gate 			return (error);
4017c478bd9Sstevel@tonic-gate 		}
4027c478bd9Sstevel@tonic-gate 	}
4037c478bd9Sstevel@tonic-gate 	pn_free(&special);
4047c478bd9Sstevel@tonic-gate 	if (bvp->v_type != VBLK) {
4057c478bd9Sstevel@tonic-gate 		VN_RELE(bvp);
4067c478bd9Sstevel@tonic-gate 		return (ENOTBLK);
4077c478bd9Sstevel@tonic-gate 	}
4087c478bd9Sstevel@tonic-gate 	xdev = bvp->v_rdev;
4097c478bd9Sstevel@tonic-gate 	/*
4107c478bd9Sstevel@tonic-gate 	 * Verify caller's permission to open the device special file.
4117c478bd9Sstevel@tonic-gate 	 */
4127c478bd9Sstevel@tonic-gate 	if ((vfsp->vfs_flag & VFS_RDONLY) != 0 ||
4137c478bd9Sstevel@tonic-gate 	    ((uap->flags & MS_RDONLY) != 0)) {
4147c478bd9Sstevel@tonic-gate 		oflag = FREAD;
4157c478bd9Sstevel@tonic-gate 		aflag = VREAD;
4167c478bd9Sstevel@tonic-gate 	} else {
4177c478bd9Sstevel@tonic-gate 		oflag = FREAD | FWRITE;
4187c478bd9Sstevel@tonic-gate 		aflag = VREAD | VWRITE;
4197c478bd9Sstevel@tonic-gate 	}
4207c478bd9Sstevel@tonic-gate 	if ((error = VOP_ACCESS(bvp, aflag, 0, cr)) != 0 ||
4217c478bd9Sstevel@tonic-gate 	    (error = secpolicy_spec_open(cr, bvp, oflag)) != 0) {
4227c478bd9Sstevel@tonic-gate 		VN_RELE(bvp);
4237c478bd9Sstevel@tonic-gate 		return (error);
4247c478bd9Sstevel@tonic-gate 	}
4257c478bd9Sstevel@tonic-gate 
4267c478bd9Sstevel@tonic-gate 	VN_RELE(bvp);
4277c478bd9Sstevel@tonic-gate 	if (getmajor(xdev) >= devcnt) {
4287c478bd9Sstevel@tonic-gate 		return (ENXIO);
4297c478bd9Sstevel@tonic-gate 	}
4307c478bd9Sstevel@tonic-gate 	/*
4317c478bd9Sstevel@tonic-gate 	 * Ensure that this device (or logical drive) isn't already mounted,
4327c478bd9Sstevel@tonic-gate 	 * unless this is a REMOUNT request
4337c478bd9Sstevel@tonic-gate 	 */
4347c478bd9Sstevel@tonic-gate 	if (dos_ldrive) {
4357c478bd9Sstevel@tonic-gate 		mutex_enter(&pcfslock);
4367c478bd9Sstevel@tonic-gate 		for (fsp = pc_mounttab; fsp; fsp = fsp->pcfs_nxt)
4377c478bd9Sstevel@tonic-gate 			if (fsp->pcfs_xdev == xdev &&
4387c478bd9Sstevel@tonic-gate 			    fsp->pcfs_ldrv == dos_ldrive) {
4397c478bd9Sstevel@tonic-gate 				mutex_exit(&pcfslock);
4407c478bd9Sstevel@tonic-gate 				if (uap->flags & MS_REMOUNT) {
4417c478bd9Sstevel@tonic-gate 					return (0);
4427c478bd9Sstevel@tonic-gate 				} else {
4437c478bd9Sstevel@tonic-gate 					return (EBUSY);
4447c478bd9Sstevel@tonic-gate 				}
4457c478bd9Sstevel@tonic-gate 			}
4467c478bd9Sstevel@tonic-gate 		/*
4477c478bd9Sstevel@tonic-gate 		 * Assign a unique device number for the vfs
4487c478bd9Sstevel@tonic-gate 		 * The old way (getudev() + a constantly incrementing
4497c478bd9Sstevel@tonic-gate 		 * major number) was wrong because it changes vfs_dev
4507c478bd9Sstevel@tonic-gate 		 * across mounts and reboots, which breaks nfs file handles.
4517c478bd9Sstevel@tonic-gate 		 * UFS just uses the real dev_t. We can't do that because
4527c478bd9Sstevel@tonic-gate 		 * of the way pcfs opens fdisk partitons (the :c and :d
4537c478bd9Sstevel@tonic-gate 		 * partitions are on the same dev_t). Though that _might_
4547c478bd9Sstevel@tonic-gate 		 * actually be ok, since the file handle contains an
4557c478bd9Sstevel@tonic-gate 		 * absolute block number, it's probably better to make them
4567c478bd9Sstevel@tonic-gate 		 * different. So I think we should retain the original
4577c478bd9Sstevel@tonic-gate 		 * dev_t, but come up with a different minor number based
4587c478bd9Sstevel@tonic-gate 		 * on the logical drive that will _always_ come up the same.
4597c478bd9Sstevel@tonic-gate 		 * For now, we steal the upper 6 bits.
4607c478bd9Sstevel@tonic-gate 		 */
4617c478bd9Sstevel@tonic-gate #ifdef notdef
4627c478bd9Sstevel@tonic-gate 		/* what should we do here? */
4637c478bd9Sstevel@tonic-gate 		if (((getminor(xdev) >> 12) & 0x3F) != 0)
4647c478bd9Sstevel@tonic-gate 			printf("whoops - upper bits used!\n");
4657c478bd9Sstevel@tonic-gate #endif
4667c478bd9Sstevel@tonic-gate 		minor = ((dos_ldrive << 12) | getminor(xdev)) & MAXMIN32;
4677c478bd9Sstevel@tonic-gate 		pseudodev = makedevice(getmajor(xdev), minor);
4687c478bd9Sstevel@tonic-gate 		if (vfs_devmounting(pseudodev, vfsp)) {
4697c478bd9Sstevel@tonic-gate 			mutex_exit(&pcfslock);
4707c478bd9Sstevel@tonic-gate 			return (EBUSY);
4717c478bd9Sstevel@tonic-gate 		}
4727c478bd9Sstevel@tonic-gate 		if (vfs_devismounted(pseudodev)) {
4737c478bd9Sstevel@tonic-gate 			mutex_exit(&pcfslock);
4747c478bd9Sstevel@tonic-gate 			if (uap->flags & MS_REMOUNT) {
4757c478bd9Sstevel@tonic-gate 				return (0);
4767c478bd9Sstevel@tonic-gate 			} else {
4777c478bd9Sstevel@tonic-gate 				return (EBUSY);
4787c478bd9Sstevel@tonic-gate 			}
4797c478bd9Sstevel@tonic-gate 		}
4807c478bd9Sstevel@tonic-gate 		mutex_exit(&pcfslock);
4817c478bd9Sstevel@tonic-gate 	} else {
4827c478bd9Sstevel@tonic-gate 		if (vfs_devmounting(xdev, vfsp)) {
4837c478bd9Sstevel@tonic-gate 			return (EBUSY);
4847c478bd9Sstevel@tonic-gate 		}
4857c478bd9Sstevel@tonic-gate 		if (vfs_devismounted(xdev))
4867c478bd9Sstevel@tonic-gate 			if (uap->flags & MS_REMOUNT) {
4877c478bd9Sstevel@tonic-gate 				return (0);
4887c478bd9Sstevel@tonic-gate 			} else {
4897c478bd9Sstevel@tonic-gate 				return (EBUSY);
4907c478bd9Sstevel@tonic-gate 			}
4917c478bd9Sstevel@tonic-gate 		pseudodev = xdev;
4927c478bd9Sstevel@tonic-gate 	}
4937c478bd9Sstevel@tonic-gate 
4947c478bd9Sstevel@tonic-gate 	if (uap->flags & MS_RDONLY) {
4957c478bd9Sstevel@tonic-gate 		vfsp->vfs_flag |= VFS_RDONLY;
4967c478bd9Sstevel@tonic-gate 		vfs_setmntopt(vfsp, MNTOPT_RO, NULL, 0);
4977c478bd9Sstevel@tonic-gate 	}
4987c478bd9Sstevel@tonic-gate 
4997c478bd9Sstevel@tonic-gate 	/*
5007c478bd9Sstevel@tonic-gate 	 * Mount the filesystem
5017c478bd9Sstevel@tonic-gate 	 */
5027c478bd9Sstevel@tonic-gate 	devvp = makespecvp(xdev, VBLK);
5037c478bd9Sstevel@tonic-gate 	if (IS_SWAPVP(devvp)) {
5047c478bd9Sstevel@tonic-gate 		VN_RELE(devvp);
5057c478bd9Sstevel@tonic-gate 		return (EBUSY);
5067c478bd9Sstevel@tonic-gate 	}
5077c478bd9Sstevel@tonic-gate 
5087c478bd9Sstevel@tonic-gate 	/*
5097c478bd9Sstevel@tonic-gate 	 * special handling for PCMCIA memory card
510*90c30842Sjmcp 	 * with pseudo floppies organization
5117c478bd9Sstevel@tonic-gate 	 */
512*90c30842Sjmcp 	if (dos_ldrive == 0 && pcfs_pseudo_floppy(xdev)) {
5137c478bd9Sstevel@tonic-gate 		dosstart = (daddr_t)0;
5147c478bd9Sstevel@tonic-gate 		fattype = PCFS_PCMCIA_NO_CIS;
5157c478bd9Sstevel@tonic-gate 	} else {
5167c478bd9Sstevel@tonic-gate 		if (error = pc_getfattype(devvp, dos_ldrive, &dosstart,
5177c478bd9Sstevel@tonic-gate 		    &fattype)) {
5187c478bd9Sstevel@tonic-gate 			VN_RELE(devvp);
5197c478bd9Sstevel@tonic-gate 			return (error);
5207c478bd9Sstevel@tonic-gate 		}
5217c478bd9Sstevel@tonic-gate 	}
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate 	(void) VOP_PUTPAGE(devvp, (offset_t)0, (uint_t)0, B_INVAL, cr);
5247c478bd9Sstevel@tonic-gate 	fsp = kmem_zalloc((uint_t)sizeof (struct pcfs), KM_SLEEP);
5257c478bd9Sstevel@tonic-gate 	fsp->pcfs_vfs = vfsp;
5267c478bd9Sstevel@tonic-gate 	fsp->pcfs_flags = fattype;
5277c478bd9Sstevel@tonic-gate 	fsp->pcfs_devvp = devvp;
5287c478bd9Sstevel@tonic-gate 	fsp->pcfs_xdev = xdev;
5297c478bd9Sstevel@tonic-gate 	fsp->pcfs_ldrv = dos_ldrive;
5307c478bd9Sstevel@tonic-gate 	fsp->pcfs_dosstart = dosstart;
5317c478bd9Sstevel@tonic-gate 	mutex_init(&fsp->pcfs_lock, NULL, MUTEX_DEFAULT, NULL);
5327c478bd9Sstevel@tonic-gate 
5337c478bd9Sstevel@tonic-gate 	/* set the "nocheck" flag if volmgt is managing this volume */
5347c478bd9Sstevel@tonic-gate 	info.vii_pathlen = 0;
5357c478bd9Sstevel@tonic-gate 	info.vii_devpath = 0;
5367c478bd9Sstevel@tonic-gate 	error = cdev_ioctl(fsp->pcfs_xdev, VOLIOCINFO, (intptr_t)&info,
5377c478bd9Sstevel@tonic-gate 	    FKIOCTL|FREAD, kcred, &rval);
5387c478bd9Sstevel@tonic-gate 	if (error == 0) {
5397c478bd9Sstevel@tonic-gate 		fsp->pcfs_flags |= PCFS_NOCHK;
5407c478bd9Sstevel@tonic-gate 	}
5417c478bd9Sstevel@tonic-gate 
5427c478bd9Sstevel@tonic-gate 	if (vfs_optionisset(vfsp, MNTOPT_PCFS_HIDDEN, NULL))
5437c478bd9Sstevel@tonic-gate 		fsp->pcfs_flags |= PCFS_HIDDEN;
5447c478bd9Sstevel@tonic-gate 	if (vfs_optionisset(vfsp, MNTOPT_PCFS_FOLDCASE, NULL))
5457c478bd9Sstevel@tonic-gate 		fsp->pcfs_flags |= PCFS_FOLDCASE;
5467c478bd9Sstevel@tonic-gate 	vfsp->vfs_dev = pseudodev;
5477c478bd9Sstevel@tonic-gate 	vfsp->vfs_fstype = pcfstype;
5487c478bd9Sstevel@tonic-gate 	vfs_make_fsid(&vfsp->vfs_fsid, pseudodev, pcfstype);
5497c478bd9Sstevel@tonic-gate 	vfsp->vfs_data = (caddr_t)fsp;
5507c478bd9Sstevel@tonic-gate 	vfsp->vfs_bcount = 0;
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate 	error = pc_verify(fsp);
5537c478bd9Sstevel@tonic-gate 	if (error) {
5547c478bd9Sstevel@tonic-gate 		VN_RELE(devvp);
5557c478bd9Sstevel@tonic-gate 		mutex_destroy(&fsp->pcfs_lock);
5567c478bd9Sstevel@tonic-gate 		kmem_free(fsp, (uint_t)sizeof (struct pcfs));
5577c478bd9Sstevel@tonic-gate 		return (error);
5587c478bd9Sstevel@tonic-gate 	}
5597c478bd9Sstevel@tonic-gate 	vfsp->vfs_bsize = fsp->pcfs_clsize;
5607c478bd9Sstevel@tonic-gate 
5617c478bd9Sstevel@tonic-gate 	mutex_enter(&pcfslock);
5627c478bd9Sstevel@tonic-gate 	fsp->pcfs_nxt = pc_mounttab;
5637c478bd9Sstevel@tonic-gate 	pc_mounttab = fsp;
5647c478bd9Sstevel@tonic-gate 	mutex_exit(&pcfslock);
5657c478bd9Sstevel@tonic-gate 	return (0);
5667c478bd9Sstevel@tonic-gate }
5677c478bd9Sstevel@tonic-gate 
5687c478bd9Sstevel@tonic-gate /*
5697c478bd9Sstevel@tonic-gate  * vfs operations
5707c478bd9Sstevel@tonic-gate  */
5717c478bd9Sstevel@tonic-gate 
5727c478bd9Sstevel@tonic-gate /* ARGSUSED */
5737c478bd9Sstevel@tonic-gate static int
5747c478bd9Sstevel@tonic-gate pcfs_unmount(
5757c478bd9Sstevel@tonic-gate 	struct vfs *vfsp,
5767c478bd9Sstevel@tonic-gate 	int flag,
5777c478bd9Sstevel@tonic-gate 	struct cred *cr)
5787c478bd9Sstevel@tonic-gate {
5797c478bd9Sstevel@tonic-gate 	struct pcfs *fsp, *fsp1;
5807c478bd9Sstevel@tonic-gate 
5817c478bd9Sstevel@tonic-gate 	if (secpolicy_fs_unmount(cr, vfsp) != 0)
5827c478bd9Sstevel@tonic-gate 		return (EPERM);
5837c478bd9Sstevel@tonic-gate 
5847c478bd9Sstevel@tonic-gate 	/*
5857c478bd9Sstevel@tonic-gate 	 * forced unmount is not supported by this file system
5867c478bd9Sstevel@tonic-gate 	 * and thus, ENOTSUP, is being returned.
5877c478bd9Sstevel@tonic-gate 	 */
5887c478bd9Sstevel@tonic-gate 	if (flag & MS_FORCE)
5897c478bd9Sstevel@tonic-gate 		return (ENOTSUP);
5907c478bd9Sstevel@tonic-gate 
5917c478bd9Sstevel@tonic-gate 	PC_DPRINTF0(4, "pcfs_unmount\n");
5927c478bd9Sstevel@tonic-gate 	fsp = VFSTOPCFS(vfsp);
5937c478bd9Sstevel@tonic-gate 	/*
5947c478bd9Sstevel@tonic-gate 	 * We don't have to lock fsp because the VVFSLOCK in vfs layer will
5957c478bd9Sstevel@tonic-gate 	 * prevent lookuppn from crossing the mount point.
5967c478bd9Sstevel@tonic-gate 	 */
5977c478bd9Sstevel@tonic-gate 	if (fsp->pcfs_nrefs) {
5987c478bd9Sstevel@tonic-gate 		return (EBUSY);
5997c478bd9Sstevel@tonic-gate 	}
6007c478bd9Sstevel@tonic-gate 
6017c478bd9Sstevel@tonic-gate 	/*
6027c478bd9Sstevel@tonic-gate 	 * Allow an unmount (regardless of state) if the fs instance has
6037c478bd9Sstevel@tonic-gate 	 * been marked as beyond recovery.
6047c478bd9Sstevel@tonic-gate 	 */
6057c478bd9Sstevel@tonic-gate 	if (fsp->pcfs_flags & PCFS_IRRECOV) {
6067c478bd9Sstevel@tonic-gate 		mutex_enter(&pcfslock);
6077c478bd9Sstevel@tonic-gate 		rw_enter(&pcnodes_lock, RW_WRITER);
6087c478bd9Sstevel@tonic-gate 		pc_diskchanged(fsp);
6097c478bd9Sstevel@tonic-gate 		rw_exit(&pcnodes_lock);
6107c478bd9Sstevel@tonic-gate 		mutex_exit(&pcfslock);
6117c478bd9Sstevel@tonic-gate 	}
6127c478bd9Sstevel@tonic-gate 
6137c478bd9Sstevel@tonic-gate 	/* now there should be no pcp node on pcfhead or pcdhead. */
6147c478bd9Sstevel@tonic-gate 
6157c478bd9Sstevel@tonic-gate 	mutex_enter(&pcfslock);
6167c478bd9Sstevel@tonic-gate 	if (fsp == pc_mounttab) {
6177c478bd9Sstevel@tonic-gate 		pc_mounttab = fsp->pcfs_nxt;
6187c478bd9Sstevel@tonic-gate 	} else {
6197c478bd9Sstevel@tonic-gate 		for (fsp1 = pc_mounttab; fsp1 != NULL; fsp1 = fsp1->pcfs_nxt)
6207c478bd9Sstevel@tonic-gate 			if (fsp1->pcfs_nxt == fsp)
6217c478bd9Sstevel@tonic-gate 				fsp1->pcfs_nxt = fsp->pcfs_nxt;
6227c478bd9Sstevel@tonic-gate 	}
6237c478bd9Sstevel@tonic-gate 
6247c478bd9Sstevel@tonic-gate 	if (fsp->pcfs_fatp != (uchar_t *)0) {
6257c478bd9Sstevel@tonic-gate 		pc_invalfat(fsp);
6267c478bd9Sstevel@tonic-gate 	}
6277c478bd9Sstevel@tonic-gate 	mutex_exit(&pcfslock);
6287c478bd9Sstevel@tonic-gate 
6297c478bd9Sstevel@tonic-gate 	VN_RELE(fsp->pcfs_devvp);
6307c478bd9Sstevel@tonic-gate 	mutex_destroy(&fsp->pcfs_lock);
6317c478bd9Sstevel@tonic-gate 	kmem_free(fsp, (uint_t)sizeof (struct pcfs));
6327c478bd9Sstevel@tonic-gate 	return (0);
6337c478bd9Sstevel@tonic-gate }
6347c478bd9Sstevel@tonic-gate 
6357c478bd9Sstevel@tonic-gate /*
6367c478bd9Sstevel@tonic-gate  * find root of pcfs
6377c478bd9Sstevel@tonic-gate  */
6387c478bd9Sstevel@tonic-gate static int
6397c478bd9Sstevel@tonic-gate pcfs_root(
6407c478bd9Sstevel@tonic-gate 	struct vfs *vfsp,
6417c478bd9Sstevel@tonic-gate 	struct vnode **vpp)
6427c478bd9Sstevel@tonic-gate {
6437c478bd9Sstevel@tonic-gate 	struct pcfs *fsp;
6447c478bd9Sstevel@tonic-gate 	struct pcnode *pcp;
6457c478bd9Sstevel@tonic-gate 	int error;
6467c478bd9Sstevel@tonic-gate 
6477c478bd9Sstevel@tonic-gate 	fsp = VFSTOPCFS(vfsp);
6487c478bd9Sstevel@tonic-gate 	if (error = pc_lockfs(fsp, 0, 0))
6497c478bd9Sstevel@tonic-gate 		return (error);
6507c478bd9Sstevel@tonic-gate 	pcp = pc_getnode(fsp, (daddr_t)0, 0, (struct pcdir *)0);
6517c478bd9Sstevel@tonic-gate 	PC_DPRINTF2(9, "pcfs_root(0x%p) pcp= 0x%p\n",
6527c478bd9Sstevel@tonic-gate 	    (void *)vfsp, (void *)pcp);
6537c478bd9Sstevel@tonic-gate 	pc_unlockfs(fsp);
6547c478bd9Sstevel@tonic-gate 	*vpp = PCTOV(pcp);
6557c478bd9Sstevel@tonic-gate 	pcp->pc_flags |= PC_EXTERNAL;
6567c478bd9Sstevel@tonic-gate 	return (0);
6577c478bd9Sstevel@tonic-gate }
6587c478bd9Sstevel@tonic-gate 
6597c478bd9Sstevel@tonic-gate /*
6607c478bd9Sstevel@tonic-gate  * Get file system statistics.
6617c478bd9Sstevel@tonic-gate  */
6627c478bd9Sstevel@tonic-gate static int
6637c478bd9Sstevel@tonic-gate pcfs_statvfs(
6647c478bd9Sstevel@tonic-gate 	struct vfs *vfsp,
6657c478bd9Sstevel@tonic-gate 	struct statvfs64 *sp)
6667c478bd9Sstevel@tonic-gate {
6677c478bd9Sstevel@tonic-gate 	struct pcfs *fsp;
6687c478bd9Sstevel@tonic-gate 	int error;
6697c478bd9Sstevel@tonic-gate 	dev32_t d32;
6707c478bd9Sstevel@tonic-gate 
6717c478bd9Sstevel@tonic-gate 	fsp = VFSTOPCFS(vfsp);
6727c478bd9Sstevel@tonic-gate 	error = pc_getfat(fsp);
6737c478bd9Sstevel@tonic-gate 	if (error)
6747c478bd9Sstevel@tonic-gate 		return (error);
6757c478bd9Sstevel@tonic-gate 	bzero(sp, sizeof (*sp));
6767c478bd9Sstevel@tonic-gate 	sp->f_bsize = sp->f_frsize = fsp->pcfs_clsize;
6777c478bd9Sstevel@tonic-gate 	sp->f_blocks = (fsblkcnt64_t)fsp->pcfs_ncluster;
6787c478bd9Sstevel@tonic-gate 	sp->f_bavail = sp->f_bfree = (fsblkcnt64_t)pc_freeclusters(fsp);
6797c478bd9Sstevel@tonic-gate 	sp->f_files = (fsfilcnt64_t)-1;
6807c478bd9Sstevel@tonic-gate 	sp->f_ffree = (fsfilcnt64_t)-1;
6817c478bd9Sstevel@tonic-gate 	sp->f_favail = (fsfilcnt64_t)-1;
6827c478bd9Sstevel@tonic-gate #ifdef notdef
6837c478bd9Sstevel@tonic-gate 	(void) cmpldev(&d32, fsp->pcfs_devvp->v_rdev);
6847c478bd9Sstevel@tonic-gate #endif /* notdef */
6857c478bd9Sstevel@tonic-gate 	(void) cmpldev(&d32, vfsp->vfs_dev);
6867c478bd9Sstevel@tonic-gate 	sp->f_fsid = d32;
6877c478bd9Sstevel@tonic-gate 	(void) strcpy(sp->f_basetype, vfssw[vfsp->vfs_fstype].vsw_name);
6887c478bd9Sstevel@tonic-gate 	sp->f_flag = vf_to_stf(vfsp->vfs_flag);
6897c478bd9Sstevel@tonic-gate 	sp->f_namemax = PCFNAMESIZE;
6907c478bd9Sstevel@tonic-gate 	return (0);
6917c478bd9Sstevel@tonic-gate }
6927c478bd9Sstevel@tonic-gate 
6937c478bd9Sstevel@tonic-gate static int
6947c478bd9Sstevel@tonic-gate pc_syncfsnodes(struct pcfs *fsp)
6957c478bd9Sstevel@tonic-gate {
6967c478bd9Sstevel@tonic-gate 	struct pchead *hp;
6977c478bd9Sstevel@tonic-gate 	struct pcnode *pcp;
6987c478bd9Sstevel@tonic-gate 	int error;
6997c478bd9Sstevel@tonic-gate 
7007c478bd9Sstevel@tonic-gate 	PC_DPRINTF0(7, "pcfs_syncfsnodes\n");
7017c478bd9Sstevel@tonic-gate 	if (error = pc_lockfs(fsp, 0, 0))
7027c478bd9Sstevel@tonic-gate 		return (error);
7037c478bd9Sstevel@tonic-gate 
7047c478bd9Sstevel@tonic-gate 	if (!(error = pc_syncfat(fsp))) {
7057c478bd9Sstevel@tonic-gate 		hp = pcfhead;
7067c478bd9Sstevel@tonic-gate 		while (hp < & pcfhead [ NPCHASH ]) {
7077c478bd9Sstevel@tonic-gate 			rw_enter(&pcnodes_lock, RW_READER);
7087c478bd9Sstevel@tonic-gate 			pcp = hp->pch_forw;
7097c478bd9Sstevel@tonic-gate 			while (pcp != (struct pcnode *)hp) {
7107c478bd9Sstevel@tonic-gate 				if (VFSTOPCFS(PCTOV(pcp) -> v_vfsp) == fsp)
7117c478bd9Sstevel@tonic-gate 					if (error = pc_nodesync(pcp))
7127c478bd9Sstevel@tonic-gate 						break;
7137c478bd9Sstevel@tonic-gate 				pcp = pcp -> pc_forw;
7147c478bd9Sstevel@tonic-gate 			}
7157c478bd9Sstevel@tonic-gate 			rw_exit(&pcnodes_lock);
7167c478bd9Sstevel@tonic-gate 			if (error)
7177c478bd9Sstevel@tonic-gate 				break;
7187c478bd9Sstevel@tonic-gate 			hp++;
7197c478bd9Sstevel@tonic-gate 		}
7207c478bd9Sstevel@tonic-gate 	}
7217c478bd9Sstevel@tonic-gate 	pc_unlockfs(fsp);
7227c478bd9Sstevel@tonic-gate 	return (error);
7237c478bd9Sstevel@tonic-gate }
7247c478bd9Sstevel@tonic-gate 
7257c478bd9Sstevel@tonic-gate /*
7267c478bd9Sstevel@tonic-gate  * Flush any pending I/O.
7277c478bd9Sstevel@tonic-gate  */
7287c478bd9Sstevel@tonic-gate /*ARGSUSED*/
7297c478bd9Sstevel@tonic-gate static int
7307c478bd9Sstevel@tonic-gate pcfs_sync(
7317c478bd9Sstevel@tonic-gate 	struct vfs *vfsp,
7327c478bd9Sstevel@tonic-gate 	short flag,
7337c478bd9Sstevel@tonic-gate 	struct cred *cr)
7347c478bd9Sstevel@tonic-gate {
7357c478bd9Sstevel@tonic-gate 	struct pcfs *fsp;
7367c478bd9Sstevel@tonic-gate 	int error = 0;
7377c478bd9Sstevel@tonic-gate 
7387c478bd9Sstevel@tonic-gate 	/* this prevents the filesystem from being umounted. */
7397c478bd9Sstevel@tonic-gate 	mutex_enter(&pcfslock);
7407c478bd9Sstevel@tonic-gate 	if (vfsp != NULL) {
7417c478bd9Sstevel@tonic-gate 		fsp = VFSTOPCFS(vfsp);
7427c478bd9Sstevel@tonic-gate 		if (!(fsp->pcfs_flags & PCFS_IRRECOV)) {
7437c478bd9Sstevel@tonic-gate 			error = pc_syncfsnodes(fsp);
7447c478bd9Sstevel@tonic-gate 		} else {
7457c478bd9Sstevel@tonic-gate 			rw_enter(&pcnodes_lock, RW_WRITER);
7467c478bd9Sstevel@tonic-gate 			pc_diskchanged(fsp);
7477c478bd9Sstevel@tonic-gate 			rw_exit(&pcnodes_lock);
7487c478bd9Sstevel@tonic-gate 			error = EIO;
7497c478bd9Sstevel@tonic-gate 		}
7507c478bd9Sstevel@tonic-gate 	} else {
7517c478bd9Sstevel@tonic-gate 		fsp = pc_mounttab;
7527c478bd9Sstevel@tonic-gate 		while (fsp != NULL) {
7537c478bd9Sstevel@tonic-gate 			if (fsp->pcfs_flags & PCFS_IRRECOV) {
7547c478bd9Sstevel@tonic-gate 				rw_enter(&pcnodes_lock, RW_WRITER);
7557c478bd9Sstevel@tonic-gate 				pc_diskchanged(fsp);
7567c478bd9Sstevel@tonic-gate 				rw_exit(&pcnodes_lock);
7577c478bd9Sstevel@tonic-gate 				error = EIO;
7587c478bd9Sstevel@tonic-gate 				break;
7597c478bd9Sstevel@tonic-gate 			}
7607c478bd9Sstevel@tonic-gate 			error = pc_syncfsnodes(fsp);
7617c478bd9Sstevel@tonic-gate 			if (error) break;
7627c478bd9Sstevel@tonic-gate 			fsp = fsp->pcfs_nxt;
7637c478bd9Sstevel@tonic-gate 		}
7647c478bd9Sstevel@tonic-gate 	}
7657c478bd9Sstevel@tonic-gate 	mutex_exit(&pcfslock);
7667c478bd9Sstevel@tonic-gate 	return (error);
7677c478bd9Sstevel@tonic-gate }
7687c478bd9Sstevel@tonic-gate 
7697c478bd9Sstevel@tonic-gate int
7707c478bd9Sstevel@tonic-gate pc_lockfs(struct pcfs *fsp, int diskchanged, int releasing)
7717c478bd9Sstevel@tonic-gate {
7727c478bd9Sstevel@tonic-gate 	if ((fsp->pcfs_flags & PCFS_IRRECOV) && !releasing)
7737c478bd9Sstevel@tonic-gate 		return (EIO);
7747c478bd9Sstevel@tonic-gate 
7757c478bd9Sstevel@tonic-gate 	if ((fsp->pcfs_flags & PCFS_LOCKED) && (fsp->pcfs_owner == curthread)) {
7767c478bd9Sstevel@tonic-gate 		fsp->pcfs_count++;
7777c478bd9Sstevel@tonic-gate 	} else {
7787c478bd9Sstevel@tonic-gate 		mutex_enter(&fsp->pcfs_lock);
7797c478bd9Sstevel@tonic-gate 		if (fsp->pcfs_flags & PCFS_LOCKED)
7807c478bd9Sstevel@tonic-gate 			panic("pc_lockfs");
7817c478bd9Sstevel@tonic-gate 		/*
7827c478bd9Sstevel@tonic-gate 		 * We check the IRRECOV bit again just in case somebody
7837c478bd9Sstevel@tonic-gate 		 * snuck past the initial check but then got held up before
7847c478bd9Sstevel@tonic-gate 		 * they could grab the lock.  (And in the meantime someone
7857c478bd9Sstevel@tonic-gate 		 * had grabbed the lock and set the bit)
7867c478bd9Sstevel@tonic-gate 		 */
7877c478bd9Sstevel@tonic-gate 		if (!diskchanged && !(fsp->pcfs_flags & PCFS_IRRECOV))
7887c478bd9Sstevel@tonic-gate 			(void) pc_getfat(fsp);
7897c478bd9Sstevel@tonic-gate 		fsp->pcfs_flags |= PCFS_LOCKED;
7907c478bd9Sstevel@tonic-gate 		fsp->pcfs_owner = curthread;
7917c478bd9Sstevel@tonic-gate 		fsp->pcfs_count++;
7927c478bd9Sstevel@tonic-gate 	}
7937c478bd9Sstevel@tonic-gate 	return (0);
7947c478bd9Sstevel@tonic-gate }
7957c478bd9Sstevel@tonic-gate 
7967c478bd9Sstevel@tonic-gate void
7977c478bd9Sstevel@tonic-gate pc_unlockfs(struct pcfs *fsp)
7987c478bd9Sstevel@tonic-gate {
7997c478bd9Sstevel@tonic-gate 
8007c478bd9Sstevel@tonic-gate 	if ((fsp->pcfs_flags & PCFS_LOCKED) == 0)
8017c478bd9Sstevel@tonic-gate 		panic("pc_unlockfs");
8027c478bd9Sstevel@tonic-gate 	if (--fsp->pcfs_count < 0)
8037c478bd9Sstevel@tonic-gate 		panic("pc_unlockfs: count");
8047c478bd9Sstevel@tonic-gate 	if (fsp->pcfs_count == 0) {
8057c478bd9Sstevel@tonic-gate 		fsp->pcfs_flags &= ~PCFS_LOCKED;
8067c478bd9Sstevel@tonic-gate 		fsp->pcfs_owner = 0;
8077c478bd9Sstevel@tonic-gate 		mutex_exit(&fsp->pcfs_lock);
8087c478bd9Sstevel@tonic-gate 	}
8097c478bd9Sstevel@tonic-gate }
8107c478bd9Sstevel@tonic-gate 
8117c478bd9Sstevel@tonic-gate /*
8127c478bd9Sstevel@tonic-gate  * isDosDrive()
8137c478bd9Sstevel@tonic-gate  *	Boolean function.  Give it the systid field for an fdisk partition
8147c478bd9Sstevel@tonic-gate  *	and it decides if that's a systid that describes a DOS drive.  We
8157c478bd9Sstevel@tonic-gate  *	use systid values defined in sys/dktp/fdisk.h.
8167c478bd9Sstevel@tonic-gate  */
8177c478bd9Sstevel@tonic-gate static int
8187c478bd9Sstevel@tonic-gate isDosDrive(uchar_t checkMe)
8197c478bd9Sstevel@tonic-gate {
8207c478bd9Sstevel@tonic-gate 	return ((checkMe == DOSOS12) || (checkMe == DOSOS16) ||
8217c478bd9Sstevel@tonic-gate 	    (checkMe == DOSHUGE) || (checkMe == FDISK_WINDOWS) ||
8227c478bd9Sstevel@tonic-gate 	    (checkMe == FDISK_EXT_WIN) || (checkMe == FDISK_FAT95) ||
8237c478bd9Sstevel@tonic-gate 	    (checkMe == DIAGPART));
8247c478bd9Sstevel@tonic-gate }
8257c478bd9Sstevel@tonic-gate 
8267c478bd9Sstevel@tonic-gate /*
8277c478bd9Sstevel@tonic-gate  * isDosExtended()
8287c478bd9Sstevel@tonic-gate  *	Boolean function.  Give it the systid field for an fdisk partition
8297c478bd9Sstevel@tonic-gate  *	and it decides if that's a systid that describes an extended DOS
8307c478bd9Sstevel@tonic-gate  *	partition.
8317c478bd9Sstevel@tonic-gate  */
8327c478bd9Sstevel@tonic-gate static int
8337c478bd9Sstevel@tonic-gate isDosExtended(uchar_t checkMe)
8347c478bd9Sstevel@tonic-gate {
8357c478bd9Sstevel@tonic-gate 	return ((checkMe == EXTDOS) || (checkMe == FDISK_EXTLBA));
8367c478bd9Sstevel@tonic-gate }
8377c478bd9Sstevel@tonic-gate 
8387c478bd9Sstevel@tonic-gate /*
8397c478bd9Sstevel@tonic-gate  * isBootPart()
8407c478bd9Sstevel@tonic-gate  *	Boolean function.  Give it the systid field for an fdisk partition
8417c478bd9Sstevel@tonic-gate  *	and it decides if that's a systid that describes a Solaris boot
8427c478bd9Sstevel@tonic-gate  *	partition.
8437c478bd9Sstevel@tonic-gate  */
8447c478bd9Sstevel@tonic-gate static int
8457c478bd9Sstevel@tonic-gate isBootPart(uchar_t checkMe)
8467c478bd9Sstevel@tonic-gate {
8477c478bd9Sstevel@tonic-gate 	return (checkMe == X86BOOT);
8487c478bd9Sstevel@tonic-gate }
8497c478bd9Sstevel@tonic-gate 
8507c478bd9Sstevel@tonic-gate /*
8517c478bd9Sstevel@tonic-gate  * noLogicalDrive()
8527c478bd9Sstevel@tonic-gate  *	Display error message about not being able to find a logical
8537c478bd9Sstevel@tonic-gate  *	drive.
8547c478bd9Sstevel@tonic-gate  */
8557c478bd9Sstevel@tonic-gate static void
8567c478bd9Sstevel@tonic-gate noLogicalDrive(int requested)
8577c478bd9Sstevel@tonic-gate {
8587c478bd9Sstevel@tonic-gate 	if (requested == BOOT_PARTITION_DRIVE) {
8597c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "!pcfs: no boot partition");
8607c478bd9Sstevel@tonic-gate 	} else {
8617c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "!pcfs: no such logical drive");
8627c478bd9Sstevel@tonic-gate 	}
8637c478bd9Sstevel@tonic-gate }
8647c478bd9Sstevel@tonic-gate 
8657c478bd9Sstevel@tonic-gate /*
8667c478bd9Sstevel@tonic-gate  * findTheDrive()
8677c478bd9Sstevel@tonic-gate  *	Discover offset of the requested logical drive, and return
8687c478bd9Sstevel@tonic-gate  *	that offset (startSector), the systid of that drive (sysid),
8697c478bd9Sstevel@tonic-gate  *	and a buffer pointer (bp), with the buffer contents being
8707c478bd9Sstevel@tonic-gate  *	the first sector of the logical drive (i.e., the sector that
8717c478bd9Sstevel@tonic-gate  *	contains the BPB for that drive).
8727c478bd9Sstevel@tonic-gate  */
8737c478bd9Sstevel@tonic-gate static int
8747c478bd9Sstevel@tonic-gate findTheDrive(dev_t dev, int askedFor, int *error, buf_t **bp,
8757c478bd9Sstevel@tonic-gate     daddr_t *startSector, uchar_t *sysid)
8767c478bd9Sstevel@tonic-gate {
8777c478bd9Sstevel@tonic-gate 	struct ipart dosp[FD_NUMPART];	/* incore fdisk partition structure */
8787c478bd9Sstevel@tonic-gate 	struct mboot *dosp_ptr;		/* boot structure pointer */
8797c478bd9Sstevel@tonic-gate 	daddr_t lastseek = 0;		/* Disk block we sought previously */
8807c478bd9Sstevel@tonic-gate 	daddr_t diskblk = 0;		/* Disk block to get */
8817c478bd9Sstevel@tonic-gate 	daddr_t xstartsect;		/* base of Extended DOS partition */
8827c478bd9Sstevel@tonic-gate 	int logicalDriveCount = 0;	/* Count of logical drives seen */
8837c478bd9Sstevel@tonic-gate 	int extendedPart = -1;		/* index of extended dos partition */
8847c478bd9Sstevel@tonic-gate 	int primaryPart = -1;		/* index of primary dos partition */
8857c478bd9Sstevel@tonic-gate 	int bootPart = -1;		/* index of a Solaris boot partition */
8867c478bd9Sstevel@tonic-gate 	int xnumsect = -1;		/* length of extended DOS partition */
8877c478bd9Sstevel@tonic-gate 	int driveIndex;			/* computed FDISK table index */
8887c478bd9Sstevel@tonic-gate 	int i;
8897c478bd9Sstevel@tonic-gate 	/*
8907c478bd9Sstevel@tonic-gate 	 * Count of drives in the current extended partition's
8917c478bd9Sstevel@tonic-gate 	 * FDISK table, and indexes of the drives themselves.
8927c478bd9Sstevel@tonic-gate 	 */
8937c478bd9Sstevel@tonic-gate 	int extndDrives[FD_NUMPART];
8947c478bd9Sstevel@tonic-gate 	int numDrives = 0;
8957c478bd9Sstevel@tonic-gate 
8967c478bd9Sstevel@tonic-gate 	/*
8977c478bd9Sstevel@tonic-gate 	 * Count of drives (beyond primary) in master boot record's
8987c478bd9Sstevel@tonic-gate 	 * FDISK table, and indexes of the drives themselves.
8997c478bd9Sstevel@tonic-gate 	 */
9007c478bd9Sstevel@tonic-gate 	int extraDrives[FD_NUMPART];
9017c478bd9Sstevel@tonic-gate 	int numExtraDrives = 0;
9027c478bd9Sstevel@tonic-gate 
9037c478bd9Sstevel@tonic-gate 	/*
9047c478bd9Sstevel@tonic-gate 	 *  Copy from disk block into memory aligned structure for fdisk usage.
9057c478bd9Sstevel@tonic-gate 	 */
9067c478bd9Sstevel@tonic-gate 	dosp_ptr = (struct mboot *)(*bp)->b_un.b_addr;
9077c478bd9Sstevel@tonic-gate 	bcopy(dosp_ptr->parts, dosp, sizeof (struct ipart) * FD_NUMPART);
9087c478bd9Sstevel@tonic-gate 
9097c478bd9Sstevel@tonic-gate 	/*
9107c478bd9Sstevel@tonic-gate 	 * Get a summary of what is in the Master FDISK table.
9117c478bd9Sstevel@tonic-gate 	 * Normally we expect to find one partition marked as a DOS drive.
9127c478bd9Sstevel@tonic-gate 	 * This partition is the one Windows calls the primary dos partition.
9137c478bd9Sstevel@tonic-gate 	 * If the machine has any logical drives then we also expect
9147c478bd9Sstevel@tonic-gate 	 * to find a partition marked as an extended DOS partition.
9157c478bd9Sstevel@tonic-gate 	 *
9167c478bd9Sstevel@tonic-gate 	 * Sometimes we'll find multiple partitions marked as DOS drives.
9177c478bd9Sstevel@tonic-gate 	 * The Solaris fdisk program allows these partitions
9187c478bd9Sstevel@tonic-gate 	 * to be created, but Windows fdisk no longer does.  We still need
9197c478bd9Sstevel@tonic-gate 	 * to support these, though, since Windows does.  We also need to fix
9207c478bd9Sstevel@tonic-gate 	 * our fdisk to behave like the Windows version.
9217c478bd9Sstevel@tonic-gate 	 *
9227c478bd9Sstevel@tonic-gate 	 * It turns out that some off-the-shelf media have *only* an
9237c478bd9Sstevel@tonic-gate 	 * Extended partition, so we need to deal with that case as well.
9247c478bd9Sstevel@tonic-gate 	 *
9257c478bd9Sstevel@tonic-gate 	 * Only a single (the first) Extended or Boot Partition will
9267c478bd9Sstevel@tonic-gate 	 * be recognized.  Any others will be ignored.
9277c478bd9Sstevel@tonic-gate 	 */
9287c478bd9Sstevel@tonic-gate 	for (i = 0; i < FD_NUMPART; i++) {
9297c478bd9Sstevel@tonic-gate 		if (isDosDrive(dosp[i].systid)) {
9307c478bd9Sstevel@tonic-gate 			if (primaryPart < 0) {
9317c478bd9Sstevel@tonic-gate 				logicalDriveCount++;
9327c478bd9Sstevel@tonic-gate 				primaryPart = i;
9337c478bd9Sstevel@tonic-gate 			} else {
9347c478bd9Sstevel@tonic-gate 				extraDrives[numExtraDrives++] = i;
9357c478bd9Sstevel@tonic-gate 			}
9367c478bd9Sstevel@tonic-gate 			continue;
9377c478bd9Sstevel@tonic-gate 		}
9387c478bd9Sstevel@tonic-gate 		if ((extendedPart < 0) && isDosExtended(dosp[i].systid)) {
9397c478bd9Sstevel@tonic-gate 			extendedPart = i;
9407c478bd9Sstevel@tonic-gate 			continue;
9417c478bd9Sstevel@tonic-gate 		}
9427c478bd9Sstevel@tonic-gate 		if ((bootPart < 0) && isBootPart(dosp[i].systid)) {
9437c478bd9Sstevel@tonic-gate 			bootPart = i;
9447c478bd9Sstevel@tonic-gate 			continue;
9457c478bd9Sstevel@tonic-gate 		}
9467c478bd9Sstevel@tonic-gate 	}
9477c478bd9Sstevel@tonic-gate 
9487c478bd9Sstevel@tonic-gate 	if (askedFor == BOOT_PARTITION_DRIVE) {
9497c478bd9Sstevel@tonic-gate 		if (bootPart < 0) {
9507c478bd9Sstevel@tonic-gate 			noLogicalDrive(askedFor);
9517c478bd9Sstevel@tonic-gate 			*error = EINVAL;
9527c478bd9Sstevel@tonic-gate 			return (0);
9537c478bd9Sstevel@tonic-gate 		}
9547c478bd9Sstevel@tonic-gate 		*sysid = dosp[bootPart].systid;
9557c478bd9Sstevel@tonic-gate 		*startSector = ltohi(dosp[bootPart].relsect);
9567c478bd9Sstevel@tonic-gate 		return (1);
9577c478bd9Sstevel@tonic-gate 	}
9587c478bd9Sstevel@tonic-gate 
9597c478bd9Sstevel@tonic-gate 	if (askedFor == PRIMARY_DOS_DRIVE && primaryPart >= 0) {
9607c478bd9Sstevel@tonic-gate 		*sysid = dosp[primaryPart].systid;
9617c478bd9Sstevel@tonic-gate 		*startSector = ltohi(dosp[primaryPart].relsect);
9627c478bd9Sstevel@tonic-gate 		return (1);
9637c478bd9Sstevel@tonic-gate 	}
9647c478bd9Sstevel@tonic-gate 
9657c478bd9Sstevel@tonic-gate 	/*
9667c478bd9Sstevel@tonic-gate 	 * We are not looking for the C: drive (or the primary drive
9677c478bd9Sstevel@tonic-gate 	 * was not found), so we had better have an extended partition
9687c478bd9Sstevel@tonic-gate 	 * or extra drives in the Master FDISK table.
9697c478bd9Sstevel@tonic-gate 	 */
9707c478bd9Sstevel@tonic-gate 	if ((extendedPart < 0) && (numExtraDrives == 0)) {
9717c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "!pcfs: no extended dos partition");
9727c478bd9Sstevel@tonic-gate 		noLogicalDrive(askedFor);
9737c478bd9Sstevel@tonic-gate 		*error = EINVAL;
9747c478bd9Sstevel@tonic-gate 		return (0);
9757c478bd9Sstevel@tonic-gate 	}
9767c478bd9Sstevel@tonic-gate 
9777c478bd9Sstevel@tonic-gate 	if (extendedPart >= 0) {
9787c478bd9Sstevel@tonic-gate 		diskblk = xstartsect = ltohi(dosp[extendedPart].relsect);
9797c478bd9Sstevel@tonic-gate 		xnumsect = ltohi(dosp[extendedPart].numsect);
9807c478bd9Sstevel@tonic-gate 		do {
9817c478bd9Sstevel@tonic-gate 			/*
9827c478bd9Sstevel@tonic-gate 			 *  If the seek would not cause us to change
9837c478bd9Sstevel@tonic-gate 			 *  position on the drive, then we're out of
9847c478bd9Sstevel@tonic-gate 			 *  extended partitions to examine.
9857c478bd9Sstevel@tonic-gate 			 */
9867c478bd9Sstevel@tonic-gate 			if (diskblk == lastseek)
9877c478bd9Sstevel@tonic-gate 				break;
9887c478bd9Sstevel@tonic-gate 			logicalDriveCount += numDrives;
9897c478bd9Sstevel@tonic-gate 			/*
9907c478bd9Sstevel@tonic-gate 			 *  Seek the next extended partition, and find
9917c478bd9Sstevel@tonic-gate 			 *  logical drives within it.
9927c478bd9Sstevel@tonic-gate 			 */
9937c478bd9Sstevel@tonic-gate 			brelse(*bp);
9947c478bd9Sstevel@tonic-gate 			*bp = bread(dev, diskblk, PC_SAFESECSIZE);
9957c478bd9Sstevel@tonic-gate 			if ((*bp)->b_flags & B_ERROR) {
9967c478bd9Sstevel@tonic-gate 				PC_DPRINTF0(1, "pc_getfattype: read error\n");
9977c478bd9Sstevel@tonic-gate 				*error = EIO;
9987c478bd9Sstevel@tonic-gate 				return (0);
9997c478bd9Sstevel@tonic-gate 			}
10007c478bd9Sstevel@tonic-gate 			lastseek = diskblk;
10017c478bd9Sstevel@tonic-gate 			dosp_ptr = (struct mboot *)(*bp)->b_un.b_addr;
10027c478bd9Sstevel@tonic-gate 			if (ltohs(dosp_ptr->signature) != MBB_MAGIC) {
10037c478bd9Sstevel@tonic-gate 				cmn_err(CE_NOTE, "!pcfs: "
10047c478bd9Sstevel@tonic-gate 				    "extended partition signature err");
10057c478bd9Sstevel@tonic-gate 				*error = EINVAL;
10067c478bd9Sstevel@tonic-gate 				return (0);
10077c478bd9Sstevel@tonic-gate 			}
10087c478bd9Sstevel@tonic-gate 			bcopy(dosp_ptr->parts, dosp,
10097c478bd9Sstevel@tonic-gate 			    sizeof (struct ipart) * FD_NUMPART);
10107c478bd9Sstevel@tonic-gate 			/*
10117c478bd9Sstevel@tonic-gate 			 *  Count up drives, and track where the next
10127c478bd9Sstevel@tonic-gate 			 *  extended partition is in case we need it.  We
10137c478bd9Sstevel@tonic-gate 			 *  are expecting only one extended partition.  If
10147c478bd9Sstevel@tonic-gate 			 *  there is more than one we'll only go to the
10157c478bd9Sstevel@tonic-gate 			 *  first one we see, but warn about ignoring.
10167c478bd9Sstevel@tonic-gate 			 */
10177c478bd9Sstevel@tonic-gate 			numDrives = 0;
10187c478bd9Sstevel@tonic-gate 			for (i = 0; i < FD_NUMPART; i++) {
10197c478bd9Sstevel@tonic-gate 				if (isDosDrive(dosp[i].systid)) {
10207c478bd9Sstevel@tonic-gate 					extndDrives[numDrives++] = i;
10217c478bd9Sstevel@tonic-gate 					continue;
10227c478bd9Sstevel@tonic-gate 				} else if (isDosExtended(dosp[i].systid)) {
10237c478bd9Sstevel@tonic-gate 					if (diskblk != lastseek) {
10247c478bd9Sstevel@tonic-gate 						/*
10257c478bd9Sstevel@tonic-gate 						 * Already found an extended
10267c478bd9Sstevel@tonic-gate 						 * partition in this table.
10277c478bd9Sstevel@tonic-gate 						 */
10287c478bd9Sstevel@tonic-gate 						cmn_err(CE_NOTE,
10297c478bd9Sstevel@tonic-gate 						    "!pcfs: ignoring unexpected"
10307c478bd9Sstevel@tonic-gate 						    " additional extended"
10317c478bd9Sstevel@tonic-gate 						    " partition");
10327c478bd9Sstevel@tonic-gate 						continue;
10337c478bd9Sstevel@tonic-gate 					}
10347c478bd9Sstevel@tonic-gate 					diskblk = xstartsect +
10357c478bd9Sstevel@tonic-gate 					    ltohi(dosp[i].relsect);
10367c478bd9Sstevel@tonic-gate 					continue;
10377c478bd9Sstevel@tonic-gate 				}
10387c478bd9Sstevel@tonic-gate 			}
10397c478bd9Sstevel@tonic-gate 		} while (askedFor > logicalDriveCount + numDrives);
10407c478bd9Sstevel@tonic-gate 
10417c478bd9Sstevel@tonic-gate 		if (askedFor <= logicalDriveCount + numDrives) {
10427c478bd9Sstevel@tonic-gate 			/*
10437c478bd9Sstevel@tonic-gate 			 * The number of logical drives we've found thus
10447c478bd9Sstevel@tonic-gate 			 * far is enough to get us to the one we were
10457c478bd9Sstevel@tonic-gate 			 * searching for.
10467c478bd9Sstevel@tonic-gate 			 */
10477c478bd9Sstevel@tonic-gate 			driveIndex = logicalDriveCount + numDrives - askedFor;
10487c478bd9Sstevel@tonic-gate 			*sysid = dosp[extndDrives[driveIndex]].systid;
10497c478bd9Sstevel@tonic-gate 			*startSector =
10507c478bd9Sstevel@tonic-gate 			    ltohi(dosp[extndDrives[driveIndex]].relsect) +
10517c478bd9Sstevel@tonic-gate 			    lastseek;
10527c478bd9Sstevel@tonic-gate 			if (*startSector > (xstartsect + xnumsect)) {
10537c478bd9Sstevel@tonic-gate 				cmn_err(CE_NOTE, "!pcfs: extended partition "
10547c478bd9Sstevel@tonic-gate 				    "values bad");
10557c478bd9Sstevel@tonic-gate 				*error = EINVAL;
10567c478bd9Sstevel@tonic-gate 				return (0);
10577c478bd9Sstevel@tonic-gate 			}
10587c478bd9Sstevel@tonic-gate 			return (1);
10597c478bd9Sstevel@tonic-gate 		} else {
10607c478bd9Sstevel@tonic-gate 			/*
10617c478bd9Sstevel@tonic-gate 			 * We ran out of extended dos partition
10627c478bd9Sstevel@tonic-gate 			 * drives.  The only hope now is to go
10637c478bd9Sstevel@tonic-gate 			 * back to extra drives defined in the master
10647c478bd9Sstevel@tonic-gate 			 * fdisk table.  But we overwrote that table
10657c478bd9Sstevel@tonic-gate 			 * already, so we must load it in again.
10667c478bd9Sstevel@tonic-gate 			 */
10677c478bd9Sstevel@tonic-gate 			logicalDriveCount += numDrives;
10687c478bd9Sstevel@tonic-gate 			brelse(*bp);
10697c478bd9Sstevel@tonic-gate 			*bp = bread(dev, (daddr_t)0, PC_SAFESECSIZE);
10707c478bd9Sstevel@tonic-gate 			if ((*bp)->b_flags & B_ERROR) {
10717c478bd9Sstevel@tonic-gate 				PC_DPRINTF0(1, "pc_getfattype: read error\n");
10727c478bd9Sstevel@tonic-gate 				*error = EIO;
10737c478bd9Sstevel@tonic-gate 				return (0);
10747c478bd9Sstevel@tonic-gate 			}
10757c478bd9Sstevel@tonic-gate 			dosp_ptr = (struct mboot *)(*bp)->b_un.b_addr;
10767c478bd9Sstevel@tonic-gate 			bcopy(dosp_ptr->parts, dosp,
10777c478bd9Sstevel@tonic-gate 			    sizeof (struct ipart) * FD_NUMPART);
10787c478bd9Sstevel@tonic-gate 		}
10797c478bd9Sstevel@tonic-gate 	}
10807c478bd9Sstevel@tonic-gate 	/*
10817c478bd9Sstevel@tonic-gate 	 *  Still haven't found the drive, is it an extra
10827c478bd9Sstevel@tonic-gate 	 *  drive defined in the main FDISK table?
10837c478bd9Sstevel@tonic-gate 	 */
10847c478bd9Sstevel@tonic-gate 	if (askedFor <= logicalDriveCount + numExtraDrives) {
10857c478bd9Sstevel@tonic-gate 		driveIndex = logicalDriveCount + numExtraDrives - askedFor;
10867c478bd9Sstevel@tonic-gate 		*sysid = dosp[extraDrives[driveIndex]].systid;
10877c478bd9Sstevel@tonic-gate 		*startSector = ltohi(dosp[extraDrives[driveIndex]].relsect);
10887c478bd9Sstevel@tonic-gate 		return (1);
10897c478bd9Sstevel@tonic-gate 	}
10907c478bd9Sstevel@tonic-gate 	/*
10917c478bd9Sstevel@tonic-gate 	 *  Still haven't found the drive, and there is
10927c478bd9Sstevel@tonic-gate 	 *  nowhere else to look.
10937c478bd9Sstevel@tonic-gate 	 */
10947c478bd9Sstevel@tonic-gate 	noLogicalDrive(askedFor);
10957c478bd9Sstevel@tonic-gate 	*error = EINVAL;
10967c478bd9Sstevel@tonic-gate 	return (0);
10977c478bd9Sstevel@tonic-gate }
10987c478bd9Sstevel@tonic-gate 
10997c478bd9Sstevel@tonic-gate /*
11007c478bd9Sstevel@tonic-gate  * Get the FAT type for the DOS medium.
11017c478bd9Sstevel@tonic-gate  *
11027c478bd9Sstevel@tonic-gate  * We look at sector 0 and determine if we are looking at an FDISK table
11037c478bd9Sstevel@tonic-gate  * or a BIOS Parameter Block (BPB).  Most of the time, if its a floppy
11047c478bd9Sstevel@tonic-gate  * we'll be looking at a BPB and if we're looking at a hard drive we'll be
11057c478bd9Sstevel@tonic-gate  * examining an FDISK table.  Those fun exceptions do happen, though.
11067c478bd9Sstevel@tonic-gate  *
11077c478bd9Sstevel@tonic-gate  * If we are looking at a BPB, we can calculate and verify the FAT size.
11087c478bd9Sstevel@tonic-gate  * If we are looking at an FDISK partition table, we scan the partition
11097c478bd9Sstevel@tonic-gate  * table for the requested logical volume.
11107c478bd9Sstevel@tonic-gate  */
11117c478bd9Sstevel@tonic-gate static int
11127c478bd9Sstevel@tonic-gate pc_getfattype(
11137c478bd9Sstevel@tonic-gate 	struct vnode *devvp,
11147c478bd9Sstevel@tonic-gate 	int ldrive,
11157c478bd9Sstevel@tonic-gate 	daddr_t *strtsectp,
11167c478bd9Sstevel@tonic-gate 	int *fattypep)
11177c478bd9Sstevel@tonic-gate {
11187c478bd9Sstevel@tonic-gate 	struct mboot *dosp_ptr;		/* boot structure pointer */
11197c478bd9Sstevel@tonic-gate 	struct bootsec *bootp, *bpbp;	/* for detailed sector examination */
11207c478bd9Sstevel@tonic-gate 	uchar_t *cp;			/* for searching out FAT string */
11217c478bd9Sstevel@tonic-gate 	uint_t overhead;		/* sectors not part of file area */
11227c478bd9Sstevel@tonic-gate 	uint_t numclusters;		/* number of clusters in file area */
11237c478bd9Sstevel@tonic-gate 	uint_t bytesoffat;		/* computed number of bytes in a FAT */
11247c478bd9Sstevel@tonic-gate 	int secsize;			/* Sector size in bytes/sec */
11257c478bd9Sstevel@tonic-gate 	buf_t *bp = NULL;		/* Disk buffer pointer */
11267c478bd9Sstevel@tonic-gate 	int rval = 0;
11277c478bd9Sstevel@tonic-gate 	uchar_t sysid = 0;		/* System ID character */
11287c478bd9Sstevel@tonic-gate 	dev_t	dev = devvp->v_rdev;
11297c478bd9Sstevel@tonic-gate 
11307c478bd9Sstevel@tonic-gate 	*strtsectp = (daddr_t)0;
11317c478bd9Sstevel@tonic-gate 
11327c478bd9Sstevel@tonic-gate 	/*
11337c478bd9Sstevel@tonic-gate 	 * Open the device so we can check out the BPB or FDISK table,
11347c478bd9Sstevel@tonic-gate 	 * then read in the sector.
11357c478bd9Sstevel@tonic-gate 	 */
11367c478bd9Sstevel@tonic-gate 	PC_DPRINTF2(5, "pc_getfattype: dev=%x  ldrive=%x  ", (int)dev, ldrive);
11377c478bd9Sstevel@tonic-gate 	if (rval = VOP_OPEN(&devvp, FREAD, CRED())) {
11387c478bd9Sstevel@tonic-gate 		PC_DPRINTF1(1, "pc_getfattype: open error=%d\n", rval);
11397c478bd9Sstevel@tonic-gate 		return (rval);
11407c478bd9Sstevel@tonic-gate 	}
11417c478bd9Sstevel@tonic-gate 
11427c478bd9Sstevel@tonic-gate 	/*
11437c478bd9Sstevel@tonic-gate 	 *  Read block 0 from device
11447c478bd9Sstevel@tonic-gate 	 */
11457c478bd9Sstevel@tonic-gate 	bp = bread(dev, (daddr_t)0, PC_SAFESECSIZE);
11467c478bd9Sstevel@tonic-gate 	if (bp->b_flags & B_ERROR) {
11477c478bd9Sstevel@tonic-gate 		PC_DPRINTF0(1, "pc_getfattype: read error\n");
11487c478bd9Sstevel@tonic-gate 		rval = EIO;
11497c478bd9Sstevel@tonic-gate 		goto out;
11507c478bd9Sstevel@tonic-gate 	}
11517c478bd9Sstevel@tonic-gate 
11527c478bd9Sstevel@tonic-gate 	/*
11537c478bd9Sstevel@tonic-gate 	 * If this is a logical volume with a FAT file system,
11547c478bd9Sstevel@tonic-gate 	 * then we expect to find a "file system boot sector"
11557c478bd9Sstevel@tonic-gate 	 * (also called a BIOS Perameter Block -- or BPB) in
11567c478bd9Sstevel@tonic-gate 	 * the first physical sector.
11577c478bd9Sstevel@tonic-gate 	 */
11587c478bd9Sstevel@tonic-gate 
11597c478bd9Sstevel@tonic-gate 	/*
11607c478bd9Sstevel@tonic-gate 	 * The word "FAT" is encoded into the BPB beginning at
11617c478bd9Sstevel@tonic-gate 	 * PCFS_TYPESTRING_OFFSET16 in 12 and 16 bit FATs.  It is
11627c478bd9Sstevel@tonic-gate 	 * encoded at FS_TYPESTRING_OFFSET32 in 32 bit FATs.
11637c478bd9Sstevel@tonic-gate 	 */
11647c478bd9Sstevel@tonic-gate 	cp = (uchar_t *)bp->b_un.b_addr;
11657c478bd9Sstevel@tonic-gate 	if (*(cp + PCFS_TYPESTRING_OFFSET16) == 'F' &&
11667c478bd9Sstevel@tonic-gate 	    *(cp + PCFS_TYPESTRING_OFFSET16 + 1) == 'A' &&
11677c478bd9Sstevel@tonic-gate 	    *(cp + PCFS_TYPESTRING_OFFSET16 + 2) == 'T') {
11687c478bd9Sstevel@tonic-gate 		PC_DPRINTF0(5, "Found the FAT string at 12/16 location\n");
11697c478bd9Sstevel@tonic-gate 		/*
11707c478bd9Sstevel@tonic-gate 		 * Compute a bits/fat value
11717c478bd9Sstevel@tonic-gate 		 */
11727c478bd9Sstevel@tonic-gate 		bpbp = (struct bootsec *)bp->b_un.b_addr;
11737c478bd9Sstevel@tonic-gate 		secsize = (int)ltohs(bpbp->bps[0]);
11747c478bd9Sstevel@tonic-gate 		/*
11757c478bd9Sstevel@tonic-gate 		 * Check for bogus sector size -
11767c478bd9Sstevel@tonic-gate 		 *	fat should be at least 1 sector
11777c478bd9Sstevel@tonic-gate 		 * If anything looks weird, we have to bail and try looking
11787c478bd9Sstevel@tonic-gate 		 * for an FDISK table instead.
11797c478bd9Sstevel@tonic-gate 		 */
11807c478bd9Sstevel@tonic-gate 		if (secsize < 512 || (int)ltohs(bpbp->fatsec) < 1 ||
11817c478bd9Sstevel@tonic-gate 		    bpbp->nfat < 1 || bpbp->spcl < 1) {
11827c478bd9Sstevel@tonic-gate 			PC_DPRINTF4(5, "One or more BPB fields bad\n"
11837c478bd9Sstevel@tonic-gate 			    "bytes/sec = %d, sec/fat = %d, numfats = %d, "
11847c478bd9Sstevel@tonic-gate 			    "sec/clust = %d\n", secsize,
11857c478bd9Sstevel@tonic-gate 			    (int)ltohs(bpbp->fatsec), bpbp->nfat, bpbp->spcl);
11867c478bd9Sstevel@tonic-gate 			goto lookforfdisk;
11877c478bd9Sstevel@tonic-gate 		}
11887c478bd9Sstevel@tonic-gate 
11897c478bd9Sstevel@tonic-gate 		overhead = bpbp->nfat * ltohs(bpbp->fatsec);
11907c478bd9Sstevel@tonic-gate 		overhead += ltohs(bpbp->res_sec[0]);
11917c478bd9Sstevel@tonic-gate 		overhead += (ltohs(bpbp->rdirents[0]) *
11927c478bd9Sstevel@tonic-gate 		    sizeof (struct pcdir)) / secsize;
11937c478bd9Sstevel@tonic-gate 
11947c478bd9Sstevel@tonic-gate 		numclusters = ((ltohs(bpbp->numsect[0]) ?
11957c478bd9Sstevel@tonic-gate 		    ltohs(bpbp->numsect[0]) : ltohi(bpbp->totalsec)) -
11967c478bd9Sstevel@tonic-gate 		    overhead) / bpbp->spcl;
11977c478bd9Sstevel@tonic-gate 
11987c478bd9Sstevel@tonic-gate 		/*
11997c478bd9Sstevel@tonic-gate 		 * If the number of clusters looks bad, go look for an
12007c478bd9Sstevel@tonic-gate 		 * FDISK table.
12017c478bd9Sstevel@tonic-gate 		 */
12027c478bd9Sstevel@tonic-gate 		if (numclusters < 1) {
12037c478bd9Sstevel@tonic-gate 			PC_DPRINTF1(5, "num clusters is bad ( = %d )\n",
12047c478bd9Sstevel@tonic-gate 			    numclusters);
12057c478bd9Sstevel@tonic-gate 			goto lookforfdisk;
12067c478bd9Sstevel@tonic-gate 		}
12077c478bd9Sstevel@tonic-gate 
12087c478bd9Sstevel@tonic-gate 		/*
12097c478bd9Sstevel@tonic-gate 		 * The number of bytes of FAT determines the maximum number
12107c478bd9Sstevel@tonic-gate 		 * of entries of a given size that FAT can contain.
12117c478bd9Sstevel@tonic-gate 		 * The FAT can only contain (bytes of FAT)*8/12 12-bit entries
12127c478bd9Sstevel@tonic-gate 		 * and (bytes of FAT)*8/16 16-bit entries.
12137c478bd9Sstevel@tonic-gate 		 */
12147c478bd9Sstevel@tonic-gate 		bytesoffat = ltohs(bpbp->fatsec) * secsize;
12157c478bd9Sstevel@tonic-gate 		PC_DPRINTF1(5, "Computed bytes of fat = %u\n", bytesoffat);
12167c478bd9Sstevel@tonic-gate 		if ((bytesoffat * 2 / 3) >= numclusters &&
12177c478bd9Sstevel@tonic-gate 		    *(cp + PCFS_TYPESTRING_OFFSET16 + 4) == '2') {
12187c478bd9Sstevel@tonic-gate 			PC_DPRINTF0(4, "pc_getfattype: 12-bit FAT\n");
12197c478bd9Sstevel@tonic-gate 			*fattypep = 0;
12207c478bd9Sstevel@tonic-gate 			rval = 0;
12217c478bd9Sstevel@tonic-gate 			goto out;
12227c478bd9Sstevel@tonic-gate 		} else if (*(cp + PCFS_TYPESTRING_OFFSET16 + 4) == '6') {
12237c478bd9Sstevel@tonic-gate 			/*
12247c478bd9Sstevel@tonic-gate 			 * this check can result in a false positive, where
12257c478bd9Sstevel@tonic-gate 			 * we believe a FAT12 filesystem to be a FAT16 one
12267c478bd9Sstevel@tonic-gate 			 * (if the type recorded in the header block lies).
12277c478bd9Sstevel@tonic-gate 			 * we recover from being lied to, in 'pc_getfat' by
12287c478bd9Sstevel@tonic-gate 			 * Forcing fat12 over fat16, if
12297c478bd9Sstevel@tonic-gate 			 *    'pcfs_fatsec <= 12' and
12307c478bd9Sstevel@tonic-gate 			 *    '(byteoffat * 2 / 3) >= numclusters'
12317c478bd9Sstevel@tonic-gate 			 * the obvious check would have been:
12327c478bd9Sstevel@tonic-gate 			 * 	else if ((bytesoffat / 2) >= numclusters &&
12337c478bd9Sstevel@tonic-gate 			 * 	*(cp + PCFS_TYPESTRING_OFFSET16 + 4) == '6')
12347c478bd9Sstevel@tonic-gate 			 */
12357c478bd9Sstevel@tonic-gate 			PC_DPRINTF0(4, "pc_getfattype: 16-bit FAT\n");
12367c478bd9Sstevel@tonic-gate 			*fattypep = PCFS_FAT16;
12377c478bd9Sstevel@tonic-gate 			rval = 0;
12387c478bd9Sstevel@tonic-gate 			goto out;
12397c478bd9Sstevel@tonic-gate 		}
12407c478bd9Sstevel@tonic-gate 		goto lookforfdisk;
12417c478bd9Sstevel@tonic-gate 	} else if (*(cp + PCFS_TYPESTRING_OFFSET32) == 'F' &&
12427c478bd9Sstevel@tonic-gate 	    *(cp + PCFS_TYPESTRING_OFFSET32 + 1) == 'A' &&
12437c478bd9Sstevel@tonic-gate 	    *(cp + PCFS_TYPESTRING_OFFSET32 + 2) == 'T') {
12447c478bd9Sstevel@tonic-gate 		PC_DPRINTF0(5, "Found the FAT string at 32 location\n");
12457c478bd9Sstevel@tonic-gate 		bpbp = (struct bootsec *)bp->b_un.b_addr;
12467c478bd9Sstevel@tonic-gate 		if ((int)ltohs(bpbp->fatsec) != 0) {
12477c478bd9Sstevel@tonic-gate 			/*
12487c478bd9Sstevel@tonic-gate 			 * Not a good sign, we expect it to be zero if
12497c478bd9Sstevel@tonic-gate 			 * this is really a FAT32 BPB.  All we can do
12507c478bd9Sstevel@tonic-gate 			 * is consider the string an anomaly, and go look
12517c478bd9Sstevel@tonic-gate 			 * for an FDISK table.
12527c478bd9Sstevel@tonic-gate 			 */
12537c478bd9Sstevel@tonic-gate 			PC_DPRINTF0(5, "But secs/fat non-zero\n");
12547c478bd9Sstevel@tonic-gate 			goto lookforfdisk;
12557c478bd9Sstevel@tonic-gate 		}
12567c478bd9Sstevel@tonic-gate 		PC_DPRINTF0(4, "pc_getfattype: 32-bit FAT\n");
12577c478bd9Sstevel@tonic-gate 		*fattypep = PCFS_FAT32;
12587c478bd9Sstevel@tonic-gate 		rval = 0;
12597c478bd9Sstevel@tonic-gate 		goto out;
12607c478bd9Sstevel@tonic-gate 	} else {
12617c478bd9Sstevel@tonic-gate 		/*
12627c478bd9Sstevel@tonic-gate 		 *  We've got some legacy cases (like the stuff fdformat
12637c478bd9Sstevel@tonic-gate 		 *  produces!).  Basically this is pre-MSDOS4.0 FATs.
12647c478bd9Sstevel@tonic-gate 		 *
12657c478bd9Sstevel@tonic-gate 		 *  We'll declare a match if:
12667c478bd9Sstevel@tonic-gate 		 *	1. Bytes/Sector and other fields seem reasonable
12677c478bd9Sstevel@tonic-gate 		 *	2. The media byte matches a known one.
12687c478bd9Sstevel@tonic-gate 		 *
12697c478bd9Sstevel@tonic-gate 		 *  If the media byte indicates a floppy we'll
12707c478bd9Sstevel@tonic-gate 		 *  assume FAT12, otherwise we'll assume FAT16.
12717c478bd9Sstevel@tonic-gate 		 */
12727c478bd9Sstevel@tonic-gate 		bpbp = (struct bootsec *)bp->b_un.b_addr;
12737c478bd9Sstevel@tonic-gate 		secsize = (int)ltohs(bpbp->bps[0]);
12747c478bd9Sstevel@tonic-gate 		if (secsize && secsize % 512 == 0 &&
12757c478bd9Sstevel@tonic-gate 		    ltohs(bpbp->fatsec) > 0 && bpbp->nfat > 0 &&
12767c478bd9Sstevel@tonic-gate 		    bpbp->spcl > 0 && ltohs(bpbp->res_sec[0]) >= 1 &&
12777c478bd9Sstevel@tonic-gate 		    ltohs(bpbp->numsect[0]) > 0) {
12787c478bd9Sstevel@tonic-gate 			switch (bpbp->mediadesriptor) {
12797c478bd9Sstevel@tonic-gate 			case SS8SPT:
12807c478bd9Sstevel@tonic-gate 			case DS8SPT:
12817c478bd9Sstevel@tonic-gate 			case SS9SPT:
12827c478bd9Sstevel@tonic-gate 			case DS9SPT:
12837c478bd9Sstevel@tonic-gate 			case DS18SPT:
12847c478bd9Sstevel@tonic-gate 			case DS9_15SPT:
12857c478bd9Sstevel@tonic-gate 				*fattypep = 0;
12867c478bd9Sstevel@tonic-gate 				rval = 0;
12877c478bd9Sstevel@tonic-gate 				goto out;
12887c478bd9Sstevel@tonic-gate 			case MD_FIXED:
12897c478bd9Sstevel@tonic-gate 				*fattypep = PCFS_FAT16;
12907c478bd9Sstevel@tonic-gate 				rval = 0;
12917c478bd9Sstevel@tonic-gate 				goto out;
12927c478bd9Sstevel@tonic-gate 			default:
12937c478bd9Sstevel@tonic-gate 				goto lookforfdisk;
12947c478bd9Sstevel@tonic-gate 			}
12957c478bd9Sstevel@tonic-gate 		}
12967c478bd9Sstevel@tonic-gate 	}
12977c478bd9Sstevel@tonic-gate 
12987c478bd9Sstevel@tonic-gate lookforfdisk:
12997c478bd9Sstevel@tonic-gate 	/*
13007c478bd9Sstevel@tonic-gate 	 *  If we got here then we didn't find a BPB.
13017c478bd9Sstevel@tonic-gate 	 *  We now assume we are looking at the start of a hard drive,
13027c478bd9Sstevel@tonic-gate 	 *  where the first sector will be a Master Boot Record (MBR).
13037c478bd9Sstevel@tonic-gate 	 *  The MBR contains a partition table (also called an FDISK
13047c478bd9Sstevel@tonic-gate 	 *  table) and should end with a signature word (MBB_MAGIC).
13057c478bd9Sstevel@tonic-gate 	 *
13067c478bd9Sstevel@tonic-gate 	 *  Check signature at end of boot block for good value.
13077c478bd9Sstevel@tonic-gate 	 *  If not then error with invalid request.
13087c478bd9Sstevel@tonic-gate 	 */
13097c478bd9Sstevel@tonic-gate 	dosp_ptr = (struct mboot *)bp->b_un.b_addr;
13107c478bd9Sstevel@tonic-gate 	if (ltohs(dosp_ptr->signature) != MBB_MAGIC) {
13117c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "!pcfs: MBR signature error");
13127c478bd9Sstevel@tonic-gate 		rval = EINVAL;
13137c478bd9Sstevel@tonic-gate 		goto out;
13147c478bd9Sstevel@tonic-gate 	}
13157c478bd9Sstevel@tonic-gate 	if (ldrive <= 0) {
13167c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "!pcfs: no logical drive specified");
13177c478bd9Sstevel@tonic-gate 		rval = EINVAL;
13187c478bd9Sstevel@tonic-gate 		goto out;
13197c478bd9Sstevel@tonic-gate 	}
13207c478bd9Sstevel@tonic-gate 
13217c478bd9Sstevel@tonic-gate 	if (findTheDrive(dev, ldrive, &rval, &bp, strtsectp, &sysid) == 0)
13227c478bd9Sstevel@tonic-gate 		goto out;
13237c478bd9Sstevel@tonic-gate 
13247c478bd9Sstevel@tonic-gate 	/*
13257c478bd9Sstevel@tonic-gate 	 * Check the sysid value of the logical drive.
13267c478bd9Sstevel@tonic-gate 	 * Return the correct value for the type of FAT found.
13277c478bd9Sstevel@tonic-gate 	 * Else return a value of -1 for unknown FAT type.
13287c478bd9Sstevel@tonic-gate 	 */
13297c478bd9Sstevel@tonic-gate 	if ((sysid == DOS_FAT32) || (sysid == DOS_FAT32_LBA)) {
13307c478bd9Sstevel@tonic-gate 		*fattypep = PCFS_FAT32 | PCFS_NOCHK;
13317c478bd9Sstevel@tonic-gate 		PC_DPRINTF0(4, "pc_getfattype: 32-bit FAT\n");
13327c478bd9Sstevel@tonic-gate 	} else if ((sysid == DOS_SYSFAT16) || (sysid == DOS_SYSHUGE) ||
13337c478bd9Sstevel@tonic-gate 	    (sysid == DIAGPART) ||
13347c478bd9Sstevel@tonic-gate 	    (sysid == DOS_FAT16P_LBA) || (sysid == DOS_FAT16_LBA)) {
13357c478bd9Sstevel@tonic-gate 		*fattypep = PCFS_FAT16 | PCFS_NOCHK;
13367c478bd9Sstevel@tonic-gate 		PC_DPRINTF0(4, "pc_getfattype: 16-bit FAT\n");
13377c478bd9Sstevel@tonic-gate 	} else if (sysid == DOS_SYSFAT12) {
13387c478bd9Sstevel@tonic-gate 		*fattypep = PCFS_NOCHK;
13397c478bd9Sstevel@tonic-gate 		PC_DPRINTF0(4, "pc_getfattype: 12-bit FAT\n");
13407c478bd9Sstevel@tonic-gate 	} else if (sysid == X86BOOT) {
13417c478bd9Sstevel@tonic-gate 		brelse(bp);
13427c478bd9Sstevel@tonic-gate 		bp = bread(dev, *strtsectp, PC_SAFESECSIZE);
13437c478bd9Sstevel@tonic-gate 		if (bp->b_flags & B_ERROR) {
13447c478bd9Sstevel@tonic-gate 			PC_DPRINTF0(1, "pc_getfattype: read error\n");
13457c478bd9Sstevel@tonic-gate 			rval = EIO;
13467c478bd9Sstevel@tonic-gate 			goto out;
13477c478bd9Sstevel@tonic-gate 		}
13487c478bd9Sstevel@tonic-gate 		bootp = (struct bootsec *)bp->b_un.b_addr;
13497c478bd9Sstevel@tonic-gate 
13507c478bd9Sstevel@tonic-gate 		/* get the sector size - may be more than 512 bytes */
13517c478bd9Sstevel@tonic-gate 		secsize = (int)ltohs(bootp->bps[0]);
13527c478bd9Sstevel@tonic-gate 		/*
13537c478bd9Sstevel@tonic-gate 		 * Check for bogus sector size -
13547c478bd9Sstevel@tonic-gate 		 *	fat should be at least 1 sector
13557c478bd9Sstevel@tonic-gate 		 */
13567c478bd9Sstevel@tonic-gate 		if (secsize < 512 || (int)ltohs(bootp->fatsec) < 1 ||
13577c478bd9Sstevel@tonic-gate 		    bootp->nfat < 1 || bootp->spcl < 1) {
13587c478bd9Sstevel@tonic-gate 			cmn_err(CE_NOTE, "!pcfs: FAT size error");
13597c478bd9Sstevel@tonic-gate 			rval = EINVAL;
13607c478bd9Sstevel@tonic-gate 			goto out;
13617c478bd9Sstevel@tonic-gate 		}
13627c478bd9Sstevel@tonic-gate 
13637c478bd9Sstevel@tonic-gate 		overhead = bootp->nfat * ltohs(bootp->fatsec);
13647c478bd9Sstevel@tonic-gate 		overhead += ltohs(bootp->res_sec[0]);
13657c478bd9Sstevel@tonic-gate 		overhead += (ltohs(bootp->rdirents[0]) *
13667c478bd9Sstevel@tonic-gate 		    sizeof (struct pcdir)) / secsize;
13677c478bd9Sstevel@tonic-gate 
13687c478bd9Sstevel@tonic-gate 		numclusters = ((ltohs(bootp->numsect[0]) ?
13697c478bd9Sstevel@tonic-gate 		    ltohs(bootp->numsect[0]) : ltohi(bootp->totalsec)) -
13707c478bd9Sstevel@tonic-gate 		    overhead) / bootp->spcl;
13717c478bd9Sstevel@tonic-gate 
13727c478bd9Sstevel@tonic-gate 		if (numclusters > DOS_F12MAXC) {
13737c478bd9Sstevel@tonic-gate 			PC_DPRINTF0(4, "pc_getfattype: 16-bit FAT BOOTPART\n");
13747c478bd9Sstevel@tonic-gate 			*fattypep = PCFS_FAT16 | PCFS_NOCHK | PCFS_BOOTPART;
13757c478bd9Sstevel@tonic-gate 		} else {
13767c478bd9Sstevel@tonic-gate 			PC_DPRINTF0(4, "pc_getfattype: 12-bit FAT BOOTPART\n");
13777c478bd9Sstevel@tonic-gate 			*fattypep = PCFS_NOCHK | PCFS_BOOTPART;
13787c478bd9Sstevel@tonic-gate 		}
13797c478bd9Sstevel@tonic-gate 	} else {
13807c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "!pcfs: unknown FAT type");
13817c478bd9Sstevel@tonic-gate 		rval = EINVAL;
13827c478bd9Sstevel@tonic-gate 	}
13837c478bd9Sstevel@tonic-gate 
13847c478bd9Sstevel@tonic-gate /*
13857c478bd9Sstevel@tonic-gate  *   Release the buffer used
13867c478bd9Sstevel@tonic-gate  */
13877c478bd9Sstevel@tonic-gate out:
13887c478bd9Sstevel@tonic-gate 	if (bp != NULL)
13897c478bd9Sstevel@tonic-gate 		brelse(bp);
13907c478bd9Sstevel@tonic-gate 	(void) VOP_CLOSE(devvp, FREAD, 1, (offset_t)0, CRED());
13917c478bd9Sstevel@tonic-gate 	return (rval);
13927c478bd9Sstevel@tonic-gate }
13937c478bd9Sstevel@tonic-gate 
13947c478bd9Sstevel@tonic-gate 
13957c478bd9Sstevel@tonic-gate /*
13967c478bd9Sstevel@tonic-gate  * Get the boot parameter block and file allocation table.
13977c478bd9Sstevel@tonic-gate  * If there is an old FAT, invalidate it.
13987c478bd9Sstevel@tonic-gate  */
13997c478bd9Sstevel@tonic-gate int
14007c478bd9Sstevel@tonic-gate pc_getfat(struct pcfs *fsp)
14017c478bd9Sstevel@tonic-gate {
14027c478bd9Sstevel@tonic-gate 	struct vfs *vfsp = PCFSTOVFS(fsp);
14037c478bd9Sstevel@tonic-gate 	struct buf *tp = 0;
14047c478bd9Sstevel@tonic-gate 	struct buf *bp = 0;
14057c478bd9Sstevel@tonic-gate 	uchar_t *fatp = NULL;
14067c478bd9Sstevel@tonic-gate 	uchar_t *fat_changemap = NULL;
14077c478bd9Sstevel@tonic-gate 	struct bootsec *bootp;
14087c478bd9Sstevel@tonic-gate 	struct fat32_bootsec *f32b;
14097c478bd9Sstevel@tonic-gate 	struct vnode *devvp;
14107c478bd9Sstevel@tonic-gate 	int error;
14117c478bd9Sstevel@tonic-gate 	int fatsize;
14127c478bd9Sstevel@tonic-gate 	int fat_changemapsize;
14137c478bd9Sstevel@tonic-gate 	int flags = 0;
14147c478bd9Sstevel@tonic-gate 	int nfat;
14157c478bd9Sstevel@tonic-gate 	int secsize;
14167c478bd9Sstevel@tonic-gate 	int fatsec;
14177c478bd9Sstevel@tonic-gate 
14187c478bd9Sstevel@tonic-gate 	PC_DPRINTF0(5, "pc_getfat\n");
14197c478bd9Sstevel@tonic-gate 	devvp = fsp->pcfs_devvp;
14207c478bd9Sstevel@tonic-gate 	if (fsp->pcfs_fatp) {
14217c478bd9Sstevel@tonic-gate 		/*
14227c478bd9Sstevel@tonic-gate 		 * There is a FAT in core.
14237c478bd9Sstevel@tonic-gate 		 * If there are open file pcnodes or we have modified it or
14247c478bd9Sstevel@tonic-gate 		 * it hasn't timed out yet use the in core FAT.
14257c478bd9Sstevel@tonic-gate 		 * Otherwise invalidate it and get a new one
14267c478bd9Sstevel@tonic-gate 		 */
14277c478bd9Sstevel@tonic-gate #ifdef notdef
14287c478bd9Sstevel@tonic-gate 		if (fsp->pcfs_frefs ||
14297c478bd9Sstevel@tonic-gate 		    (fsp->pcfs_flags & PCFS_FATMOD) ||
14307c478bd9Sstevel@tonic-gate 		    (gethrestime_sec() < fsp->pcfs_fattime)) {
14317c478bd9Sstevel@tonic-gate 			return (0);
14327c478bd9Sstevel@tonic-gate 		} else {
14337c478bd9Sstevel@tonic-gate 			mutex_enter(&pcfslock);
14347c478bd9Sstevel@tonic-gate 			pc_invalfat(fsp);
14357c478bd9Sstevel@tonic-gate 			mutex_exit(&pcfslock);
14367c478bd9Sstevel@tonic-gate 		}
14377c478bd9Sstevel@tonic-gate #endif /* notdef */
14387c478bd9Sstevel@tonic-gate 		return (0);
14397c478bd9Sstevel@tonic-gate 	}
14407c478bd9Sstevel@tonic-gate 	/*
14417c478bd9Sstevel@tonic-gate 	 * Open block device mounted on.
14427c478bd9Sstevel@tonic-gate 	 */
14437c478bd9Sstevel@tonic-gate 	error = VOP_OPEN(&devvp,
14447c478bd9Sstevel@tonic-gate 	    (vfsp->vfs_flag & VFS_RDONLY) ? FREAD : FREAD|FWRITE,
14457c478bd9Sstevel@tonic-gate 	    CRED());
14467c478bd9Sstevel@tonic-gate 	if (error) {
14477c478bd9Sstevel@tonic-gate 		PC_DPRINTF1(1, "pc_getfat: open error=%d\n", error);
14487c478bd9Sstevel@tonic-gate 		return (error);
14497c478bd9Sstevel@tonic-gate 	}
14507c478bd9Sstevel@tonic-gate 	/*
14517c478bd9Sstevel@tonic-gate 	 * Get boot parameter block and check it for validity
14527c478bd9Sstevel@tonic-gate 	 */
14537c478bd9Sstevel@tonic-gate 	tp = bread(fsp->pcfs_xdev, fsp->pcfs_dosstart, PC_SAFESECSIZE);
14547c478bd9Sstevel@tonic-gate 	if (tp->b_flags & (B_ERROR | B_STALE)) {
14557c478bd9Sstevel@tonic-gate 		PC_DPRINTF0(1, "pc_getfat: boot block error\n");
14567c478bd9Sstevel@tonic-gate 		flags = tp->b_flags & B_ERROR;
14577c478bd9Sstevel@tonic-gate 		error = EIO;
14587c478bd9Sstevel@tonic-gate 		goto out;
14597c478bd9Sstevel@tonic-gate 	}
14607c478bd9Sstevel@tonic-gate 	tp->b_flags |= B_STALE | B_AGE;
14617c478bd9Sstevel@tonic-gate 	bootp = (struct bootsec *)tp->b_un.b_addr;
14627c478bd9Sstevel@tonic-gate 
14637c478bd9Sstevel@tonic-gate 	/* get the sector size - may be more than 512 bytes */
14647c478bd9Sstevel@tonic-gate 	secsize = (int)ltohs(bootp->bps[0]);
14657c478bd9Sstevel@tonic-gate 	/* check for bogus sector size - fat should be at least 1 sector */
14667c478bd9Sstevel@tonic-gate 	if (IS_FAT32(fsp)) {
14677c478bd9Sstevel@tonic-gate 		f32b = (struct fat32_bootsec *)bootp;
14687c478bd9Sstevel@tonic-gate 		fatsec = ltohi(f32b->f_fatlength);
14697c478bd9Sstevel@tonic-gate 	} else {
14707c478bd9Sstevel@tonic-gate 		fatsec = ltohs(bootp->fatsec);
14717c478bd9Sstevel@tonic-gate 	}
14727c478bd9Sstevel@tonic-gate 	if (secsize < 512 || fatsec < 1 || bootp->nfat < 1) {
14737c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "!pcfs: FAT size error");
14747c478bd9Sstevel@tonic-gate 		error = EINVAL;
14757c478bd9Sstevel@tonic-gate 		goto out;
14767c478bd9Sstevel@tonic-gate 	}
14777c478bd9Sstevel@tonic-gate 
14787c478bd9Sstevel@tonic-gate 	switch (bootp->mediadesriptor) {
14797c478bd9Sstevel@tonic-gate 	default:
14807c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "!pcfs: media-descriptor error, 0x%x",
14817c478bd9Sstevel@tonic-gate 		    bootp->mediadesriptor);
14827c478bd9Sstevel@tonic-gate 		error = EINVAL;
14837c478bd9Sstevel@tonic-gate 		goto out;
14847c478bd9Sstevel@tonic-gate 
14857c478bd9Sstevel@tonic-gate 	case MD_FIXED:
14867c478bd9Sstevel@tonic-gate 		/*
1487*90c30842Sjmcp 		 * PCMCIA pseudo floppy is type MD_FIXED,
14887c478bd9Sstevel@tonic-gate 		 * but is accessed like a floppy
14897c478bd9Sstevel@tonic-gate 		 */
14907c478bd9Sstevel@tonic-gate 		if (!(fsp->pcfs_flags & PCFS_PCMCIA_NO_CIS)) {
14917c478bd9Sstevel@tonic-gate 			fsp->pcfs_flags |= PCFS_NOCHK;
14927c478bd9Sstevel@tonic-gate 		}
14937c478bd9Sstevel@tonic-gate 		/* FALLTHRU */
14947c478bd9Sstevel@tonic-gate 	case SS8SPT:
14957c478bd9Sstevel@tonic-gate 	case DS8SPT:
14967c478bd9Sstevel@tonic-gate 	case SS9SPT:
14977c478bd9Sstevel@tonic-gate 	case DS9SPT:
14987c478bd9Sstevel@tonic-gate 	case DS18SPT:
14997c478bd9Sstevel@tonic-gate 	case DS9_15SPT:
15007c478bd9Sstevel@tonic-gate 		fsp->pcfs_secsize = secsize;
15017c478bd9Sstevel@tonic-gate 		fsp->pcfs_sdshift = secsize / DEV_BSIZE - 1;
15027c478bd9Sstevel@tonic-gate 		fsp->pcfs_entps = secsize / sizeof (struct pcdir);
15037c478bd9Sstevel@tonic-gate 		fsp->pcfs_spcl = (int)bootp->spcl;
15047c478bd9Sstevel@tonic-gate 		fsp->pcfs_fatsec = fatsec;
15057c478bd9Sstevel@tonic-gate 		fsp->pcfs_spt = (int)ltohs(bootp->spt);
15067c478bd9Sstevel@tonic-gate 		fsp->pcfs_rdirsec = (int)ltohs(bootp->rdirents[0])
15077c478bd9Sstevel@tonic-gate 		    * sizeof (struct pcdir) / secsize;
15087c478bd9Sstevel@tonic-gate 		fsp->pcfs_clsize = fsp->pcfs_spcl * secsize;
15097c478bd9Sstevel@tonic-gate 		fsp->pcfs_fatstart = fsp->pcfs_dosstart +
15107c478bd9Sstevel@tonic-gate 		    (daddr_t)ltohs(bootp->res_sec[0]);
15117c478bd9Sstevel@tonic-gate 		fsp->pcfs_rdirstart = fsp->pcfs_fatstart +
15127c478bd9Sstevel@tonic-gate 		    (bootp->nfat * fsp->pcfs_fatsec);
15137c478bd9Sstevel@tonic-gate 		fsp->pcfs_datastart = fsp->pcfs_rdirstart + fsp->pcfs_rdirsec;
15147c478bd9Sstevel@tonic-gate 		if (IS_FAT32(fsp))
15157c478bd9Sstevel@tonic-gate 			fsp->pcfs_rdirstart = ltohi(f32b->f_rootcluster);
15167c478bd9Sstevel@tonic-gate 		fsp->pcfs_ncluster = (((int)(ltohs(bootp->numsect[0]) ?
15177c478bd9Sstevel@tonic-gate 		    ltohs(bootp->numsect[0]) : ltohi(bootp->totalsec))) -
15187c478bd9Sstevel@tonic-gate 		    fsp->pcfs_datastart + fsp->pcfs_dosstart) / fsp->pcfs_spcl;
15197c478bd9Sstevel@tonic-gate 		fsp->pcfs_numfat = (int)bootp->nfat;
15207c478bd9Sstevel@tonic-gate 		fsp->pcfs_nxfrecls = PCF_FIRSTCLUSTER;
15217c478bd9Sstevel@tonic-gate 		break;
15227c478bd9Sstevel@tonic-gate 	}
15237c478bd9Sstevel@tonic-gate 
15247c478bd9Sstevel@tonic-gate 	/*
15257c478bd9Sstevel@tonic-gate 	 * Get FAT and check it for validity
15267c478bd9Sstevel@tonic-gate 	 */
15277c478bd9Sstevel@tonic-gate 	fatsize = fsp->pcfs_fatsec * fsp->pcfs_secsize;
15287c478bd9Sstevel@tonic-gate 	fatp = kmem_alloc(fatsize, KM_SLEEP);
15297c478bd9Sstevel@tonic-gate 	error = pc_readfat(fsp, fatp, fsp->pcfs_fatstart, fatsize);
15307c478bd9Sstevel@tonic-gate 	if (error) {
15317c478bd9Sstevel@tonic-gate 		flags = B_ERROR;
15327c478bd9Sstevel@tonic-gate 		goto out;
15337c478bd9Sstevel@tonic-gate 	}
15347c478bd9Sstevel@tonic-gate 	fat_changemapsize = (fatsize / fsp->pcfs_clsize) + 1;
15357c478bd9Sstevel@tonic-gate 	fat_changemap = kmem_zalloc(fat_changemapsize, KM_SLEEP);
15367c478bd9Sstevel@tonic-gate 
15377c478bd9Sstevel@tonic-gate 	if (fatp[0] != bootp->mediadesriptor ||
15387c478bd9Sstevel@tonic-gate 	    fatp[1] != 0xFF || fatp[2] != 0xFF) {
15397c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "!pcfs: FAT signature error");
15407c478bd9Sstevel@tonic-gate 		error = EINVAL;
15417c478bd9Sstevel@tonic-gate 		goto out;
15427c478bd9Sstevel@tonic-gate 	}
15437c478bd9Sstevel@tonic-gate 	/*
15447c478bd9Sstevel@tonic-gate 	 * Checking for fatsec and number of supported clusters, should
15457c478bd9Sstevel@tonic-gate 	 * actually determine a FAT12/FAT media. See pc_getfattype().
15467c478bd9Sstevel@tonic-gate 	 * fatp[3] != 0xFF is necessary for FAT validity.
15477c478bd9Sstevel@tonic-gate 	 */
15487c478bd9Sstevel@tonic-gate 	if (fsp->pcfs_flags & PCFS_FAT16) {
15497c478bd9Sstevel@tonic-gate 		if ((fsp->pcfs_fatsec <= 12) &&
15507c478bd9Sstevel@tonic-gate 		    ((fatsize * 2 / 3) >= fsp->pcfs_ncluster)) {
15517c478bd9Sstevel@tonic-gate 			/*
15527c478bd9Sstevel@tonic-gate 			 * We have a 12-bit FAT, rather than a 16-bit FAT.
15537c478bd9Sstevel@tonic-gate 			 * Ignore what the fdisk table says.
15547c478bd9Sstevel@tonic-gate 			 */
15557c478bd9Sstevel@tonic-gate 			PC_DPRINTF0(2, "pc_getfattype: forcing 12-bit FAT\n");
15567c478bd9Sstevel@tonic-gate 			fsp->pcfs_flags &= ~PCFS_FAT16;
15577c478bd9Sstevel@tonic-gate 		} else if (fatp[3] != 0xFF) {
15587c478bd9Sstevel@tonic-gate 			cmn_err(CE_NOTE, "!pcfs: FAT signature error");
15597c478bd9Sstevel@tonic-gate 			error = EINVAL;
15607c478bd9Sstevel@tonic-gate 			goto out;
15617c478bd9Sstevel@tonic-gate 		}
15627c478bd9Sstevel@tonic-gate 	}
15637c478bd9Sstevel@tonic-gate 	/*
15647c478bd9Sstevel@tonic-gate 	 * Sanity check our FAT is large enough for the
15657c478bd9Sstevel@tonic-gate 	 * clusters we think we have.
15667c478bd9Sstevel@tonic-gate 	 */
15677c478bd9Sstevel@tonic-gate 	if ((fsp->pcfs_flags & PCFS_FAT16) &&
15687c478bd9Sstevel@tonic-gate 	    ((fatsize / 2) < fsp->pcfs_ncluster)) {
15697c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "!pcfs: FAT too small for number of clusters");
15707c478bd9Sstevel@tonic-gate 		error = EINVAL;
15717c478bd9Sstevel@tonic-gate 		goto out;
15727c478bd9Sstevel@tonic-gate 	}
15737c478bd9Sstevel@tonic-gate 
15747c478bd9Sstevel@tonic-gate 	/*
15757c478bd9Sstevel@tonic-gate 	 * Get alternate FATs and check for consistency
15767c478bd9Sstevel@tonic-gate 	 * This is an inlined version of pc_readfat().
15777c478bd9Sstevel@tonic-gate 	 * Since we're only comparing FAT and alternate FAT,
15787c478bd9Sstevel@tonic-gate 	 * there's no reason to let pc_readfat() copy data out
15797c478bd9Sstevel@tonic-gate 	 * of the buf. Instead, compare in-situ, one cluster
15807c478bd9Sstevel@tonic-gate 	 * at a time.
15817c478bd9Sstevel@tonic-gate 	 */
15827c478bd9Sstevel@tonic-gate 	for (nfat = 1; nfat < fsp->pcfs_numfat; nfat++) {
15837c478bd9Sstevel@tonic-gate 		size_t startsec;
15847c478bd9Sstevel@tonic-gate 		size_t off;
15857c478bd9Sstevel@tonic-gate 
15867c478bd9Sstevel@tonic-gate 		startsec = fsp->pcfs_fatstart + nfat * fsp->pcfs_fatsec;
15877c478bd9Sstevel@tonic-gate 
15887c478bd9Sstevel@tonic-gate 		for (off = 0; off < fatsize; off += fsp->pcfs_clsize) {
15897c478bd9Sstevel@tonic-gate 			bp = bread(fsp->pcfs_xdev, pc_dbdaddr(fsp,
15907c478bd9Sstevel@tonic-gate 				startsec +
15917c478bd9Sstevel@tonic-gate 				pc_cltodb(fsp, pc_lblkno(fsp, off))),
15927c478bd9Sstevel@tonic-gate 				MIN(fsp->pcfs_clsize, fatsize - off));
15937c478bd9Sstevel@tonic-gate 			if (bp->b_flags & (B_ERROR | B_STALE)) {
15947c478bd9Sstevel@tonic-gate 				cmn_err(CE_NOTE,
15957c478bd9Sstevel@tonic-gate 					"!pcfs: alternate FAT #%d read error"
15967c478bd9Sstevel@tonic-gate 					" at byte %ld", nfat, off);
15977c478bd9Sstevel@tonic-gate 				flags = B_ERROR;
15987c478bd9Sstevel@tonic-gate 				error = EIO;
15997c478bd9Sstevel@tonic-gate 				goto out;
16007c478bd9Sstevel@tonic-gate 			}
16017c478bd9Sstevel@tonic-gate 			bp->b_flags |= B_STALE | B_AGE;
16027c478bd9Sstevel@tonic-gate 			if (bcmp(bp->b_un.b_addr,
16037c478bd9Sstevel@tonic-gate 			    fatp + off,
16047c478bd9Sstevel@tonic-gate 			    MIN(fsp->pcfs_clsize, fatsize - off))) {
16057c478bd9Sstevel@tonic-gate 				cmn_err(CE_NOTE,
16067c478bd9Sstevel@tonic-gate 					"!pcfs: alternate FAT #%d corrupted"
16077c478bd9Sstevel@tonic-gate 					" at byte %ld", nfat, off);
16087c478bd9Sstevel@tonic-gate 				flags = B_ERROR;
16097c478bd9Sstevel@tonic-gate 			}
16107c478bd9Sstevel@tonic-gate 			brelse(bp);
16117c478bd9Sstevel@tonic-gate 			bp = NULL;	/* prevent double release */
16127c478bd9Sstevel@tonic-gate 		}
16137c478bd9Sstevel@tonic-gate 	}
16147c478bd9Sstevel@tonic-gate 
16157c478bd9Sstevel@tonic-gate 	fsp->pcfs_fatsize = fatsize;
16167c478bd9Sstevel@tonic-gate 	fsp->pcfs_fatp = fatp;
16177c478bd9Sstevel@tonic-gate 	fsp->pcfs_fat_changemapsize = fat_changemapsize;
16187c478bd9Sstevel@tonic-gate 	fsp->pcfs_fat_changemap = fat_changemap;
16197c478bd9Sstevel@tonic-gate 	fsp->pcfs_fattime = gethrestime_sec() + PCFS_DISKTIMEOUT;
16207c478bd9Sstevel@tonic-gate 	fsp->pcfs_fatjustread = 1;
16217c478bd9Sstevel@tonic-gate 
16227c478bd9Sstevel@tonic-gate 	brelse(tp);
16237c478bd9Sstevel@tonic-gate 	tp = NULL;
16247c478bd9Sstevel@tonic-gate 	if (IS_FAT32(fsp)) {
16257c478bd9Sstevel@tonic-gate 		/* get fsinfo */
16267c478bd9Sstevel@tonic-gate 		struct fat32_boot_fsinfo fsinfo_disk;
16277c478bd9Sstevel@tonic-gate 
16287c478bd9Sstevel@tonic-gate 		fsp->f32fsinfo_sector = ltohs(f32b->f_infosector);
16297c478bd9Sstevel@tonic-gate 		tp = bread(fsp->pcfs_xdev,
16307c478bd9Sstevel@tonic-gate 		    fsp->pcfs_dosstart + pc_dbdaddr(fsp, fsp->f32fsinfo_sector),
16317c478bd9Sstevel@tonic-gate 		    PC_SAFESECSIZE);
16327c478bd9Sstevel@tonic-gate 		if (tp->b_flags & (B_ERROR | B_STALE)) {
16337c478bd9Sstevel@tonic-gate 			cmn_err(CE_NOTE, "!pcfs: error reading fat32 fsinfo");
16347c478bd9Sstevel@tonic-gate 			flags = tp->b_flags & B_ERROR;
16357c478bd9Sstevel@tonic-gate 			brelse(tp);
16367c478bd9Sstevel@tonic-gate 			tp = NULL;
16377c478bd9Sstevel@tonic-gate 			error = EIO;
16387c478bd9Sstevel@tonic-gate 			goto out;
16397c478bd9Sstevel@tonic-gate 		}
16407c478bd9Sstevel@tonic-gate 		tp->b_flags |= B_STALE | B_AGE;
16417c478bd9Sstevel@tonic-gate 		bcopy((void *)(tp->b_un.b_addr + FAT32_BOOT_FSINFO_OFF),
16427c478bd9Sstevel@tonic-gate 		    &fsinfo_disk, sizeof (struct fat32_boot_fsinfo));
16437c478bd9Sstevel@tonic-gate 		brelse(tp);
16447c478bd9Sstevel@tonic-gate 		tp = NULL;
16457c478bd9Sstevel@tonic-gate 
16467c478bd9Sstevel@tonic-gate 		/* translated fields */
16477c478bd9Sstevel@tonic-gate 		fsp->fsinfo_native.fs_signature =
16487c478bd9Sstevel@tonic-gate 		    ltohi(fsinfo_disk.fs_signature);
16497c478bd9Sstevel@tonic-gate 		fsp->fsinfo_native.fs_free_clusters =
16507c478bd9Sstevel@tonic-gate 		    ltohi(fsinfo_disk.fs_free_clusters);
16517c478bd9Sstevel@tonic-gate 		if (fsp->fsinfo_native.fs_signature != FAT32_FS_SIGN) {
16527c478bd9Sstevel@tonic-gate 			cmn_err(CE_NOTE,
16537c478bd9Sstevel@tonic-gate 			    "!pcfs: fat32 fsinfo signature mismatch.");
16547c478bd9Sstevel@tonic-gate 			error = EINVAL;
16557c478bd9Sstevel@tonic-gate 			goto out;
16567c478bd9Sstevel@tonic-gate 		}
16577c478bd9Sstevel@tonic-gate 	}
16587c478bd9Sstevel@tonic-gate 
16597c478bd9Sstevel@tonic-gate 	return (0);
16607c478bd9Sstevel@tonic-gate 
16617c478bd9Sstevel@tonic-gate out:
16627c478bd9Sstevel@tonic-gate 	cmn_err(CE_NOTE, "!pcfs: illegal disk format");
16637c478bd9Sstevel@tonic-gate 	if (tp)
16647c478bd9Sstevel@tonic-gate 		brelse(tp);
16657c478bd9Sstevel@tonic-gate 	if (bp)
16667c478bd9Sstevel@tonic-gate 		brelse(bp);
16677c478bd9Sstevel@tonic-gate 	if (fatp)
16687c478bd9Sstevel@tonic-gate 		kmem_free(fatp, fatsize);
16697c478bd9Sstevel@tonic-gate 	if (fat_changemap)
16707c478bd9Sstevel@tonic-gate 		kmem_free(fat_changemap, fat_changemapsize);
16717c478bd9Sstevel@tonic-gate 
16727c478bd9Sstevel@tonic-gate 	if (flags) {
16737c478bd9Sstevel@tonic-gate 		pc_mark_irrecov(fsp);
16747c478bd9Sstevel@tonic-gate 	}
16757c478bd9Sstevel@tonic-gate 	(void) VOP_CLOSE(devvp, (vfsp->vfs_flag & VFS_RDONLY) ?
16767c478bd9Sstevel@tonic-gate 	    FREAD : FREAD|FWRITE, 1, (offset_t)0, CRED());
16777c478bd9Sstevel@tonic-gate 	return (error);
16787c478bd9Sstevel@tonic-gate }
16797c478bd9Sstevel@tonic-gate 
16807c478bd9Sstevel@tonic-gate int
16817c478bd9Sstevel@tonic-gate pc_syncfat(struct pcfs *fsp)
16827c478bd9Sstevel@tonic-gate {
16837c478bd9Sstevel@tonic-gate 	struct buf *bp;
16847c478bd9Sstevel@tonic-gate 	int nfat;
16857c478bd9Sstevel@tonic-gate 	int	error;
16867c478bd9Sstevel@tonic-gate 	struct fat32_boot_fsinfo fsinfo_disk;
16877c478bd9Sstevel@tonic-gate 
16887c478bd9Sstevel@tonic-gate 	PC_DPRINTF0(7, "pcfs_syncfat\n");
16897c478bd9Sstevel@tonic-gate 	if ((fsp->pcfs_fatp == (uchar_t *)0) ||
16907c478bd9Sstevel@tonic-gate 	    !(fsp->pcfs_flags & PCFS_FATMOD))
16917c478bd9Sstevel@tonic-gate 		return (0);
16927c478bd9Sstevel@tonic-gate 	/*
16937c478bd9Sstevel@tonic-gate 	 * write out all copies of FATs
16947c478bd9Sstevel@tonic-gate 	 */
16957c478bd9Sstevel@tonic-gate 	fsp->pcfs_flags &= ~PCFS_FATMOD;
16967c478bd9Sstevel@tonic-gate 	fsp->pcfs_fattime = gethrestime_sec() + PCFS_DISKTIMEOUT;
16977c478bd9Sstevel@tonic-gate 	for (nfat = 0; nfat < fsp->pcfs_numfat; nfat++) {
16987c478bd9Sstevel@tonic-gate 		error = pc_writefat(fsp,
16997c478bd9Sstevel@tonic-gate 		    fsp->pcfs_fatstart + nfat*fsp->pcfs_fatsec);
17007c478bd9Sstevel@tonic-gate 		if (error) {
17017c478bd9Sstevel@tonic-gate 			pc_mark_irrecov(fsp);
17027c478bd9Sstevel@tonic-gate 			return (EIO);
17037c478bd9Sstevel@tonic-gate 		}
17047c478bd9Sstevel@tonic-gate 	}
17057c478bd9Sstevel@tonic-gate 	pc_clear_fatchanges(fsp);
17067c478bd9Sstevel@tonic-gate 	PC_DPRINTF0(6, "pcfs_syncfat: wrote out FAT\n");
17077c478bd9Sstevel@tonic-gate 	/* write out fsinfo */
17087c478bd9Sstevel@tonic-gate 	if (IS_FAT32(fsp)) {
17097c478bd9Sstevel@tonic-gate 		bp = bread(fsp->pcfs_xdev,
17107c478bd9Sstevel@tonic-gate 		    fsp->pcfs_dosstart + pc_dbdaddr(fsp, fsp->f32fsinfo_sector),
17117c478bd9Sstevel@tonic-gate 		    PC_SAFESECSIZE);
17127c478bd9Sstevel@tonic-gate 		if (bp->b_flags & (B_ERROR | B_STALE)) {
17137c478bd9Sstevel@tonic-gate 			brelse(bp);
17147c478bd9Sstevel@tonic-gate 			return (EIO);
17157c478bd9Sstevel@tonic-gate 		}
17167c478bd9Sstevel@tonic-gate 		bcopy((void *)(bp->b_un.b_addr + FAT32_BOOT_FSINFO_OFF),
17177c478bd9Sstevel@tonic-gate 		    &fsinfo_disk, sizeof (struct fat32_boot_fsinfo));
17187c478bd9Sstevel@tonic-gate 		/* translate fields */
17197c478bd9Sstevel@tonic-gate 		fsinfo_disk.fs_free_clusters =
17207c478bd9Sstevel@tonic-gate 		    htoli(fsp->fsinfo_native.fs_free_clusters);
17217c478bd9Sstevel@tonic-gate 		fsinfo_disk.fs_next_cluster = (uint32_t)FSINFO_UNKNOWN;
17227c478bd9Sstevel@tonic-gate 		bcopy(&fsinfo_disk,
17237c478bd9Sstevel@tonic-gate 		    (void *)(bp->b_un.b_addr + FAT32_BOOT_FSINFO_OFF),
17247c478bd9Sstevel@tonic-gate 		    sizeof (struct fat32_boot_fsinfo));
17257c478bd9Sstevel@tonic-gate 		bwrite2(bp);
17267c478bd9Sstevel@tonic-gate 		error = geterror(bp);
17277c478bd9Sstevel@tonic-gate 		brelse(bp);
17287c478bd9Sstevel@tonic-gate 		if (error) {
17297c478bd9Sstevel@tonic-gate 			pc_mark_irrecov(fsp);
17307c478bd9Sstevel@tonic-gate 			return (EIO);
17317c478bd9Sstevel@tonic-gate 		}
17327c478bd9Sstevel@tonic-gate 	}
17337c478bd9Sstevel@tonic-gate 	return (0);
17347c478bd9Sstevel@tonic-gate }
17357c478bd9Sstevel@tonic-gate 
17367c478bd9Sstevel@tonic-gate void
17377c478bd9Sstevel@tonic-gate pc_invalfat(struct pcfs *fsp)
17387c478bd9Sstevel@tonic-gate {
17397c478bd9Sstevel@tonic-gate 	struct pcfs *xfsp;
17407c478bd9Sstevel@tonic-gate 	int mount_cnt = 0;
17417c478bd9Sstevel@tonic-gate 
17427c478bd9Sstevel@tonic-gate 	PC_DPRINTF0(7, "pc_invalfat\n");
17437c478bd9Sstevel@tonic-gate 	if (fsp->pcfs_fatp == (uchar_t *)0)
17447c478bd9Sstevel@tonic-gate 		panic("pc_invalfat");
17457c478bd9Sstevel@tonic-gate 	/*
17467c478bd9Sstevel@tonic-gate 	 * Release FAT
17477c478bd9Sstevel@tonic-gate 	 */
17487c478bd9Sstevel@tonic-gate 	kmem_free(fsp->pcfs_fatp, fsp->pcfs_fatsize);
17497c478bd9Sstevel@tonic-gate 	fsp->pcfs_fatp = NULL;
17507c478bd9Sstevel@tonic-gate 	kmem_free(fsp->pcfs_fat_changemap, fsp->pcfs_fat_changemapsize);
17517c478bd9Sstevel@tonic-gate 	fsp->pcfs_fat_changemap = NULL;
17527c478bd9Sstevel@tonic-gate 	/*
17537c478bd9Sstevel@tonic-gate 	 * Invalidate all the blocks associated with the device.
17547c478bd9Sstevel@tonic-gate 	 * Not needed if stateless.
17557c478bd9Sstevel@tonic-gate 	 */
17567c478bd9Sstevel@tonic-gate 	for (xfsp = pc_mounttab; xfsp; xfsp = xfsp->pcfs_nxt)
17577c478bd9Sstevel@tonic-gate 		if (xfsp != fsp && xfsp->pcfs_xdev == fsp->pcfs_xdev)
17587c478bd9Sstevel@tonic-gate 			mount_cnt++;
17597c478bd9Sstevel@tonic-gate 
17607c478bd9Sstevel@tonic-gate 	if (!mount_cnt)
17617c478bd9Sstevel@tonic-gate 		binval(fsp->pcfs_xdev);
17627c478bd9Sstevel@tonic-gate 	/*
17637c478bd9Sstevel@tonic-gate 	 * close mounted device
17647c478bd9Sstevel@tonic-gate 	 */
17657c478bd9Sstevel@tonic-gate 	(void) VOP_CLOSE(fsp->pcfs_devvp,
17667c478bd9Sstevel@tonic-gate 	    (PCFSTOVFS(fsp)->vfs_flag & VFS_RDONLY) ? FREAD : FREAD|FWRITE,
17677c478bd9Sstevel@tonic-gate 	    1, (offset_t)0, CRED());
17687c478bd9Sstevel@tonic-gate }
17697c478bd9Sstevel@tonic-gate 
17707c478bd9Sstevel@tonic-gate void
17717c478bd9Sstevel@tonic-gate pc_badfs(struct pcfs *fsp)
17727c478bd9Sstevel@tonic-gate {
17737c478bd9Sstevel@tonic-gate 	cmn_err(CE_WARN, "corrupted PC file system on dev %x.%x\n",
17747c478bd9Sstevel@tonic-gate 	    getmajor(fsp->pcfs_devvp->v_rdev),
17757c478bd9Sstevel@tonic-gate 	    getminor(fsp->pcfs_devvp->v_rdev));
17767c478bd9Sstevel@tonic-gate }
17777c478bd9Sstevel@tonic-gate 
17787c478bd9Sstevel@tonic-gate /*
17797c478bd9Sstevel@tonic-gate  * The problem with supporting NFS on the PCFS filesystem is that there
17807c478bd9Sstevel@tonic-gate  * is no good place to keep the generation number. The only possible
17817c478bd9Sstevel@tonic-gate  * place is inside a directory entry. There are a few words that we
17827c478bd9Sstevel@tonic-gate  * don't use - they store NT & OS/2 attributes, and the creation/last access
17837c478bd9Sstevel@tonic-gate  * time of the file - but it seems wrong to use them. In addition, directory
17847c478bd9Sstevel@tonic-gate  * entries come and go. If a directory is removed completely, its directory
17857c478bd9Sstevel@tonic-gate  * blocks are freed and the generation numbers are lost. Whereas in ufs,
17867c478bd9Sstevel@tonic-gate  * inode blocks are dedicated for inodes, so the generation numbers are
17877c478bd9Sstevel@tonic-gate  * permanently kept on the disk.
17887c478bd9Sstevel@tonic-gate  */
17897c478bd9Sstevel@tonic-gate static int
17907c478bd9Sstevel@tonic-gate pcfs_vget(struct vfs *vfsp, struct vnode **vpp, struct fid *fidp)
17917c478bd9Sstevel@tonic-gate {
17927c478bd9Sstevel@tonic-gate 	struct pcnode *pcp;
17937c478bd9Sstevel@tonic-gate 	struct pc_fid *pcfid;
17947c478bd9Sstevel@tonic-gate 	struct pcfs *fsp;
17957c478bd9Sstevel@tonic-gate 	struct pcdir *ep;
17967c478bd9Sstevel@tonic-gate 	daddr_t eblkno;
17977c478bd9Sstevel@tonic-gate 	int eoffset;
17987c478bd9Sstevel@tonic-gate 	struct buf *bp;
17997c478bd9Sstevel@tonic-gate 	int error;
18007c478bd9Sstevel@tonic-gate 	pc_cluster32_t	cn;
18017c478bd9Sstevel@tonic-gate 
18027c478bd9Sstevel@tonic-gate 	pcfid = (struct pc_fid *)fidp;
18037c478bd9Sstevel@tonic-gate 	fsp = VFSTOPCFS(vfsp);
18047c478bd9Sstevel@tonic-gate 
18057c478bd9Sstevel@tonic-gate 	error = pc_lockfs(fsp, 0, 0);
18067c478bd9Sstevel@tonic-gate 	if (error) {
18077c478bd9Sstevel@tonic-gate 		*vpp = NULL;
18087c478bd9Sstevel@tonic-gate 		return (error);
18097c478bd9Sstevel@tonic-gate 	}
18107c478bd9Sstevel@tonic-gate 
18117c478bd9Sstevel@tonic-gate 	if (pcfid->pcfid_block == 0) {
18127c478bd9Sstevel@tonic-gate 		pcp = pc_getnode(fsp, (daddr_t)0, 0, (struct pcdir *)0);
18137c478bd9Sstevel@tonic-gate 		pcp->pc_flags |= PC_EXTERNAL;
18147c478bd9Sstevel@tonic-gate 		*vpp = PCTOV(pcp);
18157c478bd9Sstevel@tonic-gate 		pc_unlockfs(fsp);
18167c478bd9Sstevel@tonic-gate 		return (0);
18177c478bd9Sstevel@tonic-gate 	}
18187c478bd9Sstevel@tonic-gate 	eblkno = pcfid->pcfid_block;
18197c478bd9Sstevel@tonic-gate 	eoffset = pcfid->pcfid_offset;
18207c478bd9Sstevel@tonic-gate 	if ((pc_dbtocl(fsp,
18217c478bd9Sstevel@tonic-gate 	    eblkno - fsp->pcfs_dosstart) >= fsp->pcfs_ncluster) ||
18227c478bd9Sstevel@tonic-gate 	    (eoffset > fsp->pcfs_clsize)) {
18237c478bd9Sstevel@tonic-gate 		pc_unlockfs(fsp);
18247c478bd9Sstevel@tonic-gate 		*vpp = NULL;
18257c478bd9Sstevel@tonic-gate 		return (EINVAL);
18267c478bd9Sstevel@tonic-gate 	}
18277c478bd9Sstevel@tonic-gate 
18287c478bd9Sstevel@tonic-gate 	if (eblkno >= fsp->pcfs_datastart || (eblkno-fsp->pcfs_rdirstart)
18297c478bd9Sstevel@tonic-gate 	    < (fsp->pcfs_rdirsec & ~(fsp->pcfs_spcl - 1))) {
18307c478bd9Sstevel@tonic-gate 		bp = bread(fsp->pcfs_xdev, eblkno, fsp->pcfs_clsize);
18317c478bd9Sstevel@tonic-gate 	} else {
18327c478bd9Sstevel@tonic-gate 		bp = bread(fsp->pcfs_xdev, eblkno,
18337c478bd9Sstevel@tonic-gate 		    (int)(fsp->pcfs_datastart - eblkno) * fsp->pcfs_secsize);
18347c478bd9Sstevel@tonic-gate 	}
18357c478bd9Sstevel@tonic-gate 	if (bp->b_flags & (B_ERROR | B_STALE)) {
18367c478bd9Sstevel@tonic-gate 		error = geterror(bp);
18377c478bd9Sstevel@tonic-gate 		brelse(bp);
18387c478bd9Sstevel@tonic-gate 		if (error)
18397c478bd9Sstevel@tonic-gate 			pc_mark_irrecov(fsp);
18407c478bd9Sstevel@tonic-gate 		*vpp = NULL;
18417c478bd9Sstevel@tonic-gate 		pc_unlockfs(fsp);
18427c478bd9Sstevel@tonic-gate 		return (error);
18437c478bd9Sstevel@tonic-gate 	}
18447c478bd9Sstevel@tonic-gate 	ep = (struct pcdir *)(bp->b_un.b_addr + eoffset);
18457c478bd9Sstevel@tonic-gate 	/*
18467c478bd9Sstevel@tonic-gate 	 * Ok, if this is a valid file handle that we gave out,
18477c478bd9Sstevel@tonic-gate 	 * then simply ensuring that the creation time matches,
18487c478bd9Sstevel@tonic-gate 	 * the entry has not been deleted, and it has a valid first
18497c478bd9Sstevel@tonic-gate 	 * character should be enough.
18507c478bd9Sstevel@tonic-gate 	 *
18517c478bd9Sstevel@tonic-gate 	 * Unfortunately, verifying that the <blkno, offset> _still_
18527c478bd9Sstevel@tonic-gate 	 * refers to a directory entry is not easy, since we'd have
18537c478bd9Sstevel@tonic-gate 	 * to search _all_ directories starting from root to find it.
18547c478bd9Sstevel@tonic-gate 	 * That's a high price to pay just in case somebody is forging
18557c478bd9Sstevel@tonic-gate 	 * file handles. So instead we verify that as much of the
18567c478bd9Sstevel@tonic-gate 	 * entry is valid as we can:
18577c478bd9Sstevel@tonic-gate 	 *
18587c478bd9Sstevel@tonic-gate 	 * 1. The starting cluster is 0 (unallocated) or valid
18597c478bd9Sstevel@tonic-gate 	 * 2. It is not an LFN entry
18607c478bd9Sstevel@tonic-gate 	 * 3. It is not hidden (unless mounted as such)
18617c478bd9Sstevel@tonic-gate 	 * 4. It is not the label
18627c478bd9Sstevel@tonic-gate 	 */
18637c478bd9Sstevel@tonic-gate 	cn = pc_getstartcluster(fsp, ep);
18647c478bd9Sstevel@tonic-gate 	/*
18657c478bd9Sstevel@tonic-gate 	 * if the starting cluster is valid, but not valid according
18667c478bd9Sstevel@tonic-gate 	 * to pc_validcl(), force it to be to simplify the following if.
18677c478bd9Sstevel@tonic-gate 	 */
18687c478bd9Sstevel@tonic-gate 	if (cn == 0)
18697c478bd9Sstevel@tonic-gate 		cn = PCF_FIRSTCLUSTER;
18707c478bd9Sstevel@tonic-gate 	if (IS_FAT32(fsp)) {
18717c478bd9Sstevel@tonic-gate 		if (cn >= PCF_LASTCLUSTER32)
18727c478bd9Sstevel@tonic-gate 			cn = PCF_FIRSTCLUSTER;
18737c478bd9Sstevel@tonic-gate 	} else {
18747c478bd9Sstevel@tonic-gate 		if (cn >= PCF_LASTCLUSTER)
18757c478bd9Sstevel@tonic-gate 			cn = PCF_FIRSTCLUSTER;
18767c478bd9Sstevel@tonic-gate 	}
18777c478bd9Sstevel@tonic-gate 	if ((!pc_validcl(fsp, cn)) ||
18787c478bd9Sstevel@tonic-gate 	    (PCDL_IS_LFN(ep)) ||
18797c478bd9Sstevel@tonic-gate 	    (PCA_IS_HIDDEN(fsp, ep->pcd_attr)) ||
18807c478bd9Sstevel@tonic-gate 	    ((ep->pcd_attr & PCA_LABEL) == PCA_LABEL)) {
18817c478bd9Sstevel@tonic-gate 		bp->b_flags |= B_STALE | B_AGE;
18827c478bd9Sstevel@tonic-gate 		brelse(bp);
18837c478bd9Sstevel@tonic-gate 		pc_unlockfs(fsp);
18847c478bd9Sstevel@tonic-gate 		return (EINVAL);
18857c478bd9Sstevel@tonic-gate 	}
18867c478bd9Sstevel@tonic-gate 	if ((ep->pcd_crtime.pct_time == pcfid->pcfid_ctime) &&
18877c478bd9Sstevel@tonic-gate 	    (ep->pcd_filename[0] != PCD_ERASED) &&
18887c478bd9Sstevel@tonic-gate 	    (pc_validchar(ep->pcd_filename[0]) ||
18897c478bd9Sstevel@tonic-gate 		(ep->pcd_filename[0] == '.' && ep->pcd_filename[1] == '.'))) {
18907c478bd9Sstevel@tonic-gate 		pcp = pc_getnode(fsp, eblkno, eoffset, ep);
18917c478bd9Sstevel@tonic-gate 		pcp->pc_flags |= PC_EXTERNAL;
18927c478bd9Sstevel@tonic-gate 		*vpp = PCTOV(pcp);
18937c478bd9Sstevel@tonic-gate 	} else {
18947c478bd9Sstevel@tonic-gate 		*vpp = NULL;
18957c478bd9Sstevel@tonic-gate 	}
18967c478bd9Sstevel@tonic-gate 	bp->b_flags |= B_STALE | B_AGE;
18977c478bd9Sstevel@tonic-gate 	brelse(bp);
18987c478bd9Sstevel@tonic-gate 	pc_unlockfs(fsp);
18997c478bd9Sstevel@tonic-gate 	return (0);
19007c478bd9Sstevel@tonic-gate }
19017c478bd9Sstevel@tonic-gate 
19027c478bd9Sstevel@tonic-gate /*
1903*90c30842Sjmcp  * if device is a PCMCIA pseudo floppy, return 1
19047c478bd9Sstevel@tonic-gate  * otherwise, return 0
19057c478bd9Sstevel@tonic-gate  */
19067c478bd9Sstevel@tonic-gate static int
1907*90c30842Sjmcp pcfs_pseudo_floppy(dev_t rdev)
19087c478bd9Sstevel@tonic-gate {
19097c478bd9Sstevel@tonic-gate 	int			error, err;
19107c478bd9Sstevel@tonic-gate 	struct dk_cinfo		info;
19117c478bd9Sstevel@tonic-gate 	ldi_handle_t		lh;
19127c478bd9Sstevel@tonic-gate 	ldi_ident_t		li;
19137c478bd9Sstevel@tonic-gate 
19147c478bd9Sstevel@tonic-gate 	err = ldi_ident_from_mod(&modlinkage, &li);
19157c478bd9Sstevel@tonic-gate 	if (err) {
19167c478bd9Sstevel@tonic-gate 		PC_DPRINTF1(1,
1917*90c30842Sjmcp 		    "pcfs_pseudo_floppy: ldi_ident_from_mod err=%d\n", err);
19187c478bd9Sstevel@tonic-gate 		return (0);
19197c478bd9Sstevel@tonic-gate 	}
19207c478bd9Sstevel@tonic-gate 
19217c478bd9Sstevel@tonic-gate 	err = ldi_open_by_dev(&rdev, OTYP_CHR, FREAD, CRED(), &lh, li);
19227c478bd9Sstevel@tonic-gate 	ldi_ident_release(li);
19237c478bd9Sstevel@tonic-gate 	if (err) {
19247c478bd9Sstevel@tonic-gate 		PC_DPRINTF1(1,
1925*90c30842Sjmcp 		    "pcfs_pseudo_floppy: ldi_open err=%d\n", err);
19267c478bd9Sstevel@tonic-gate 		return (0);
19277c478bd9Sstevel@tonic-gate 	}
19287c478bd9Sstevel@tonic-gate 
19297c478bd9Sstevel@tonic-gate 	/* return value stored in err is purposfully ignored */
19307c478bd9Sstevel@tonic-gate 	error = ldi_ioctl(lh, DKIOCINFO, (intptr_t)&info, FKIOCTL,
19317c478bd9Sstevel@tonic-gate 	    CRED(), &err);
19327c478bd9Sstevel@tonic-gate 
19337c478bd9Sstevel@tonic-gate 	err = ldi_close(lh, FREAD, CRED());
19347c478bd9Sstevel@tonic-gate 	if (err != 0) {
19357c478bd9Sstevel@tonic-gate 		PC_DPRINTF1(1,
1936*90c30842Sjmcp 		    "pcfs_pseudo_floppy: ldi_close err=%d\n", err);
19377c478bd9Sstevel@tonic-gate 		return (0);
19387c478bd9Sstevel@tonic-gate 	}
19397c478bd9Sstevel@tonic-gate 
19407c478bd9Sstevel@tonic-gate 	if ((error == 0) && (info.dki_ctype == DKC_PCMCIA_MEM) &&
19417c478bd9Sstevel@tonic-gate 		(info.dki_flags & DKI_PCMCIA_PFD))
19427c478bd9Sstevel@tonic-gate 		return (1);
19437c478bd9Sstevel@tonic-gate 	else
19447c478bd9Sstevel@tonic-gate 		return (0);
19457c478bd9Sstevel@tonic-gate }
19467c478bd9Sstevel@tonic-gate 
19477c478bd9Sstevel@tonic-gate /*
19487c478bd9Sstevel@tonic-gate  * Unfortunately, FAT32 fat's can be pretty big (On a 1 gig jaz drive, about
19497c478bd9Sstevel@tonic-gate  * a meg), so we can't bread() it all in at once. This routine reads a
19507c478bd9Sstevel@tonic-gate  * fat a chunk at a time.
19517c478bd9Sstevel@tonic-gate  */
19527c478bd9Sstevel@tonic-gate static int
19537c478bd9Sstevel@tonic-gate pc_readfat(struct pcfs *fsp, uchar_t *fatp, daddr_t start, size_t fatsize)
19547c478bd9Sstevel@tonic-gate {
19557c478bd9Sstevel@tonic-gate 	struct buf *bp;
19567c478bd9Sstevel@tonic-gate 	size_t off;
19577c478bd9Sstevel@tonic-gate 	size_t readsize;
19587c478bd9Sstevel@tonic-gate 
19597c478bd9Sstevel@tonic-gate 	readsize = fsp->pcfs_clsize;
19607c478bd9Sstevel@tonic-gate 	for (off = 0; off < fatsize; off += readsize, fatp += readsize) {
19617c478bd9Sstevel@tonic-gate 		if (readsize > (fatsize - off))
19627c478bd9Sstevel@tonic-gate 			readsize = fatsize - off;
19637c478bd9Sstevel@tonic-gate 		bp = bread(fsp->pcfs_xdev,
19647c478bd9Sstevel@tonic-gate 		    pc_dbdaddr(fsp, start +
19657c478bd9Sstevel@tonic-gate 			pc_cltodb(fsp, pc_lblkno(fsp, off))),
19667c478bd9Sstevel@tonic-gate 		    readsize);
19677c478bd9Sstevel@tonic-gate 		if (bp->b_flags & (B_ERROR | B_STALE)) {
19687c478bd9Sstevel@tonic-gate 			brelse(bp);
19697c478bd9Sstevel@tonic-gate 			return (EIO);
19707c478bd9Sstevel@tonic-gate 		}
19717c478bd9Sstevel@tonic-gate 		bp->b_flags |= B_STALE | B_AGE;
19727c478bd9Sstevel@tonic-gate 		bcopy(bp->b_un.b_addr, fatp, readsize);
19737c478bd9Sstevel@tonic-gate 		brelse(bp);
19747c478bd9Sstevel@tonic-gate 	}
19757c478bd9Sstevel@tonic-gate 	return (0);
19767c478bd9Sstevel@tonic-gate }
19777c478bd9Sstevel@tonic-gate 
19787c478bd9Sstevel@tonic-gate /*
19797c478bd9Sstevel@tonic-gate  * We write the FAT out a _lot_, in order to make sure that it
19807c478bd9Sstevel@tonic-gate  * is up-to-date. But on a FAT32 system (large drive, small clusters)
19817c478bd9Sstevel@tonic-gate  * the FAT might be a couple of megabytes, and writing it all out just
19827c478bd9Sstevel@tonic-gate  * because we created or deleted a small file is painful (especially
19837c478bd9Sstevel@tonic-gate  * since we do it for each alternate FAT too). So instead, for FAT16 and
19847c478bd9Sstevel@tonic-gate  * FAT32 we only write out the bit that has changed. We don't clear
19857c478bd9Sstevel@tonic-gate  * the 'updated' fields here because the caller might be writing out
19867c478bd9Sstevel@tonic-gate  * several FATs, so the caller must use pc_clear_fatchanges() after
19877c478bd9Sstevel@tonic-gate  * all FATs have been updated.
19887c478bd9Sstevel@tonic-gate  */
19897c478bd9Sstevel@tonic-gate static int
19907c478bd9Sstevel@tonic-gate pc_writefat(struct pcfs *fsp, daddr_t start)
19917c478bd9Sstevel@tonic-gate {
19927c478bd9Sstevel@tonic-gate 	struct buf *bp;
19937c478bd9Sstevel@tonic-gate 	size_t off;
19947c478bd9Sstevel@tonic-gate 	size_t writesize;
19957c478bd9Sstevel@tonic-gate 	int	error;
19967c478bd9Sstevel@tonic-gate 	uchar_t *fatp = fsp->pcfs_fatp;
19977c478bd9Sstevel@tonic-gate 	size_t fatsize = fsp->pcfs_fatsize;
19987c478bd9Sstevel@tonic-gate 
19997c478bd9Sstevel@tonic-gate 	writesize = fsp->pcfs_clsize;
20007c478bd9Sstevel@tonic-gate 	for (off = 0; off < fatsize; off += writesize, fatp += writesize) {
20017c478bd9Sstevel@tonic-gate 		if (writesize > (fatsize - off))
20027c478bd9Sstevel@tonic-gate 			writesize = fatsize - off;
20037c478bd9Sstevel@tonic-gate 		if (!pc_fat_is_changed(fsp, pc_lblkno(fsp, off))) {
20047c478bd9Sstevel@tonic-gate 			continue;
20057c478bd9Sstevel@tonic-gate 		}
20067c478bd9Sstevel@tonic-gate 		bp = ngeteblk(writesize);
20077c478bd9Sstevel@tonic-gate 		bp->b_edev = fsp->pcfs_xdev;
20087c478bd9Sstevel@tonic-gate 		bp->b_dev = cmpdev(bp->b_edev);
20097c478bd9Sstevel@tonic-gate 		bp->b_blkno = pc_dbdaddr(fsp, start +
20107c478bd9Sstevel@tonic-gate 		    pc_cltodb(fsp, pc_lblkno(fsp, off)));
20117c478bd9Sstevel@tonic-gate 		bcopy(fatp, bp->b_un.b_addr, writesize);
20127c478bd9Sstevel@tonic-gate 		bwrite2(bp);
20137c478bd9Sstevel@tonic-gate 		error = geterror(bp);
20147c478bd9Sstevel@tonic-gate 		brelse(bp);
20157c478bd9Sstevel@tonic-gate 		if (error) {
20167c478bd9Sstevel@tonic-gate 			return (error);
20177c478bd9Sstevel@tonic-gate 		}
20187c478bd9Sstevel@tonic-gate 	}
20197c478bd9Sstevel@tonic-gate 	return (0);
20207c478bd9Sstevel@tonic-gate }
20217c478bd9Sstevel@tonic-gate 
20227c478bd9Sstevel@tonic-gate /*
20237c478bd9Sstevel@tonic-gate  * Mark the FAT cluster that 'cn' is stored in as modified.
20247c478bd9Sstevel@tonic-gate  */
20257c478bd9Sstevel@tonic-gate void
20267c478bd9Sstevel@tonic-gate pc_mark_fat_updated(struct pcfs *fsp, pc_cluster32_t cn)
20277c478bd9Sstevel@tonic-gate {
20287c478bd9Sstevel@tonic-gate 	pc_cluster32_t	bn;
20297c478bd9Sstevel@tonic-gate 	size_t		size;
20307c478bd9Sstevel@tonic-gate 
20317c478bd9Sstevel@tonic-gate 	/* which fat block is the cluster number stored in? */
20327c478bd9Sstevel@tonic-gate 	if (IS_FAT32(fsp)) {
20337c478bd9Sstevel@tonic-gate 		size = sizeof (pc_cluster32_t);
20347c478bd9Sstevel@tonic-gate 		bn = pc_lblkno(fsp, cn * size);
20357c478bd9Sstevel@tonic-gate 		fsp->pcfs_fat_changemap[bn] = 1;
20367c478bd9Sstevel@tonic-gate 	} else if (IS_FAT16(fsp)) {
20377c478bd9Sstevel@tonic-gate 		size = sizeof (pc_cluster16_t);
20387c478bd9Sstevel@tonic-gate 		bn = pc_lblkno(fsp, cn * size);
20397c478bd9Sstevel@tonic-gate 		fsp->pcfs_fat_changemap[bn] = 1;
20407c478bd9Sstevel@tonic-gate 	} else {
20417c478bd9Sstevel@tonic-gate 		offset_t off;
20427c478bd9Sstevel@tonic-gate 		pc_cluster32_t nbn;
20437c478bd9Sstevel@tonic-gate 
20447c478bd9Sstevel@tonic-gate 		ASSERT(IS_FAT12(fsp));
20457c478bd9Sstevel@tonic-gate 		off = cn + (cn >> 1);
20467c478bd9Sstevel@tonic-gate 		bn = pc_lblkno(fsp, off);
20477c478bd9Sstevel@tonic-gate 		fsp->pcfs_fat_changemap[bn] = 1;
20487c478bd9Sstevel@tonic-gate 		/* does this field wrap into the next fat cluster? */
20497c478bd9Sstevel@tonic-gate 		nbn = pc_lblkno(fsp, off + 1);
20507c478bd9Sstevel@tonic-gate 		if (nbn != bn) {
20517c478bd9Sstevel@tonic-gate 			fsp->pcfs_fat_changemap[nbn] = 1;
20527c478bd9Sstevel@tonic-gate 		}
20537c478bd9Sstevel@tonic-gate 	}
20547c478bd9Sstevel@tonic-gate }
20557c478bd9Sstevel@tonic-gate 
20567c478bd9Sstevel@tonic-gate /*
20577c478bd9Sstevel@tonic-gate  * return whether the FAT cluster 'bn' is updated and needs to
20587c478bd9Sstevel@tonic-gate  * be written out.
20597c478bd9Sstevel@tonic-gate  */
20607c478bd9Sstevel@tonic-gate int
20617c478bd9Sstevel@tonic-gate pc_fat_is_changed(struct pcfs *fsp, pc_cluster32_t bn)
20627c478bd9Sstevel@tonic-gate {
20637c478bd9Sstevel@tonic-gate 	return (fsp->pcfs_fat_changemap[bn] == 1);
20647c478bd9Sstevel@tonic-gate }
2065