msdosfsmount.h revision 30354
130354Sphk/*	$Id: msdosfsmount.h,v 1.11 1997/03/03 17:36:11 bde Exp $ */
22893Sdfr/*	$NetBSD: msdosfsmount.h,v 1.7 1994/08/21 18:44:17 ws Exp $	*/
32893Sdfr
42893Sdfr/*-
52893Sdfr * Copyright (C) 1994 Wolfgang Solfrank.
62893Sdfr * Copyright (C) 1994 TooLs GmbH.
72893Sdfr * All rights reserved.
82893Sdfr * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
92893Sdfr *
102893Sdfr * Redistribution and use in source and binary forms, with or without
112893Sdfr * modification, are permitted provided that the following conditions
122893Sdfr * are met:
132893Sdfr * 1. Redistributions of source code must retain the above copyright
142893Sdfr *    notice, this list of conditions and the following disclaimer.
152893Sdfr * 2. Redistributions in binary form must reproduce the above copyright
162893Sdfr *    notice, this list of conditions and the following disclaimer in the
172893Sdfr *    documentation and/or other materials provided with the distribution.
182893Sdfr * 3. All advertising materials mentioning features or use of this software
192893Sdfr *    must display the following acknowledgement:
202893Sdfr *	This product includes software developed by TooLs GmbH.
212893Sdfr * 4. The name of TooLs GmbH may not be used to endorse or promote products
222893Sdfr *    derived from this software without specific prior written permission.
232893Sdfr *
242893Sdfr * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
252893Sdfr * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
262893Sdfr * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
272893Sdfr * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
282893Sdfr * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
292893Sdfr * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
302893Sdfr * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
312893Sdfr * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
322893Sdfr * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
332893Sdfr * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
342893Sdfr */
352893Sdfr/*
362893Sdfr * Written by Paul Popelka (paulp@uts.amdahl.com)
378876Srgrimes *
382893Sdfr * You can do anything you want with this software, just don't say you wrote
392893Sdfr * it, and don't remove this notice.
408876Srgrimes *
412893Sdfr * This software is provided "as is".
428876Srgrimes *
432893Sdfr * The author supplies this software to be publicly redistributed on the
442893Sdfr * understanding that the author is not responsible for the correct
452893Sdfr * functioning of this software in any circumstances and is not liable for
462893Sdfr * any damages caused by this software.
478876Srgrimes *
482893Sdfr * October 1992
492893Sdfr */
502893Sdfr
5123351Sbde#ifndef _MSDOSFS_MSDOSFSMOUNT_H_
5223351Sbde#define	_MSDOSFS_MSDOSFSMOUNT_H_
5323351Sbde
5423351Sbde#ifdef KERNEL
5523351Sbde
5630354Sphk#ifdef MALLOC_DECLARE
5730354SphkMALLOC_DECLARE(M_MSDOSFSMNT);
5830354Sphk#endif
5930354Sphk
602893Sdfr/*
612893Sdfr * Layout of the mount control block for a msdos file system.
622893Sdfr */
632893Sdfrstruct msdosfsmount {
642893Sdfr	struct mount *pm_mountp;/* vfs mount struct for this fs */
652893Sdfr	dev_t pm_dev;		/* block special device mounted */
662893Sdfr	uid_t pm_mounter;	/* uid of the user who mounted the FS */
672893Sdfr	uid_t pm_uid;		/* uid to set as owner of the files */
682893Sdfr	gid_t pm_gid;		/* gid to set as owner of the files */
692893Sdfr	mode_t pm_mask;		/* mask to and with file protection bits */
702893Sdfr	struct vnode *pm_devvp;	/* vnode for block device mntd */
712893Sdfr	struct bpb50 pm_bpb;	/* BIOS parameter blk for this fs */
722893Sdfr	u_long pm_fatblk;	/* block # of first FAT */
732893Sdfr	u_long pm_rootdirblk;	/* block # of root directory */
742893Sdfr	u_long pm_rootdirsize;	/* size in blocks (not clusters) */
752893Sdfr	u_long pm_firstcluster;	/* block number of first cluster */
762893Sdfr	u_long pm_nmbrofclusters;	/* # of clusters in filesystem */
772893Sdfr	u_long pm_maxcluster;	/* maximum cluster number */
782893Sdfr	u_long pm_freeclustercount;	/* number of free clusters */
792893Sdfr	u_long pm_bnshift;	/* shift file offset right this amount to get a block number */
802893Sdfr	u_long pm_brbomask;	/* and a file offset with this mask to get block rel offset */
812893Sdfr	u_long pm_cnshift;	/* shift file offset right this amount to get a cluster number */
822893Sdfr	u_long pm_crbomask;	/* and a file offset with this mask to get cluster rel offset */
832893Sdfr	u_long pm_bpcluster;	/* bytes per cluster */
842893Sdfr	u_long pm_depclust;	/* directory entries per cluster */
852893Sdfr	u_long pm_fmod;		/* ~0 if fs is modified, this can rollover to 0	*/
862893Sdfr	u_long pm_fatblocksize;	/* size of fat blocks in bytes */
872893Sdfr	u_long pm_fatblocksec;	/* size of fat blocks in sectors */
882893Sdfr	u_long pm_fatsize;	/* size of fat in bytes */
892893Sdfr	u_int *pm_inusemap;	/* ptr to bitmap of in-use clusters */
902893Sdfr	char pm_ronly;		/* read only if non-zero */
9113765Smpp	char pm_waitonfat;	/* wait for writes of the fat to complete, when 0 use bdwrite, else use bwrite */
922893Sdfr	struct netexport pm_export;	/* export information */
932893Sdfr};
942893Sdfr
952893Sdfr/* Number of bits in one pm_inusemap item: */
962893Sdfr#define	N_INUSEBITS	(8 * sizeof(u_int))
972893Sdfr
982893Sdfr/*
992893Sdfr * How to compute pm_cnshift and pm_crbomask.
1008876Srgrimes *
1018876Srgrimes * pm_crbomask = (pm_SectPerClust * pm_BytesPerSect) - 1
1028876Srgrimes * if (bytesperclust == * 0)
1038876Srgrimes * 	return EBADBLKSZ;
1048876Srgrimes * bit = 1;
1058876Srgrimes * for (i = 0; i < 32; i++) {
1068876Srgrimes *	if (bit & bytesperclust) {
1078876Srgrimes *		if (bit ^ bytesperclust)
1088876Srgrimes *			return EBADBLKSZ;
1098876Srgrimes *		pm_cnshift = * i;
1108876Srgrimes *		break;
1118876Srgrimes *	}
1128876Srgrimes *	bit <<= 1;
1132893Sdfr * }
1142893Sdfr */
1152893Sdfr
1162893Sdfr/*
1172893Sdfr * Shorthand for fields in the bpb contained in the msdosfsmount structure.
1182893Sdfr */
1192893Sdfr#define	pm_BytesPerSec	pm_bpb.bpbBytesPerSec
1202893Sdfr#define	pm_SectPerClust	pm_bpb.bpbSecPerClust
1212893Sdfr#define	pm_ResSectors	pm_bpb.bpbResSectors
1222893Sdfr#define	pm_FATs		pm_bpb.bpbFATs
1232893Sdfr#define	pm_RootDirEnts	pm_bpb.bpbRootDirEnts
1242893Sdfr#define	pm_Sectors	pm_bpb.bpbSectors
1252893Sdfr#define	pm_Media	pm_bpb.bpbMedia
1262893Sdfr#define	pm_FATsecs	pm_bpb.bpbFATsecs
1272893Sdfr#define	pm_SecPerTrack	pm_bpb.bpbSecPerTrack
1282893Sdfr#define	pm_Heads	pm_bpb.bpbHeads
1292893Sdfr#define	pm_HiddenSects	pm_bpb.bpbHiddenSecs
1302893Sdfr#define	pm_HugeSectors	pm_bpb.bpbHugeSectors
1312893Sdfr
1322893Sdfr/*
1332893Sdfr * Map a cluster number into a filesystem relative block number.
1342893Sdfr */
1352893Sdfr#define	cntobn(pmp, cn) \
1362893Sdfr	((((cn)-CLUST_FIRST) * (pmp)->pm_SectPerClust) + (pmp)->pm_firstcluster)
1372893Sdfr
1382893Sdfr/*
1392893Sdfr * Map a filesystem relative block number back into a cluster number.
1402893Sdfr */
1412893Sdfr#define	bntocn(pmp, bn) \
1422893Sdfr	((((bn) - pmp->pm_firstcluster)/ (pmp)->pm_SectPerClust) + CLUST_FIRST)
1432893Sdfr
1442893Sdfr/*
1452893Sdfr * Calculate block number for directory entry in root dir, offset dirofs
1462893Sdfr */
1472893Sdfr#define	roottobn(pmp, dirofs) \
1482893Sdfr	(((dirofs) / (pmp)->pm_depclust) * (pmp)->pm_SectPerClust \
1492893Sdfr	+ (pmp)->pm_rootdirblk)
1502893Sdfr
1512893Sdfr/*
1522893Sdfr * Calculate block number for directory entry at cluster dirclu, offset
1532893Sdfr * dirofs
1542893Sdfr */
1552893Sdfr#define	detobn(pmp, dirclu, dirofs) \
1562893Sdfr	((dirclu) == MSDOSFSROOT \
1572893Sdfr	 ? roottobn((pmp), (dirofs)) \
1582893Sdfr	 : cntobn((pmp), (dirclu)))
1592893Sdfr
1602893Sdfr/*
1612893Sdfr * Convert pointer to buffer -> pointer to direntry
1622893Sdfr */
1632893Sdfr#define	bptoep(pmp, bp, dirofs) \
1642893Sdfr	((struct direntry *)((bp)->b_data)	\
1652893Sdfr	 + (dirofs) % (pmp)->pm_depclust)
1662893Sdfr
1672893Sdfr
1682893Sdfr/*
1692893Sdfr * Convert filesize to block number
1702893Sdfr */
1712893Sdfr#define de_blk(pmp, off) \
1722893Sdfr	((off) >> (pmp)->pm_cnshift)
1732893Sdfr
1742893Sdfr/*
1752893Sdfr * Clusters required to hold size bytes
1762893Sdfr */
1772893Sdfr#define	de_clcount(pmp, size) \
1782893Sdfr	(((size) + (pmp)->pm_bpcluster - 1) >> (pmp)->pm_cnshift)
1792893Sdfr
18022601Smppint msdosfs_init __P((struct vfsconf *vfsp));
18122521Sdyson
18223351Sbde#endif /* KERNEL */
18323351Sbde
18422521Sdyson/*
18522521Sdyson *  Arguments to mount MSDOS filesystems.
18622521Sdyson */
18722521Sdysonstruct msdosfs_args {
18822521Sdyson	char	*fspec;		/* blocks special holding the fs to mount */
18922521Sdyson	struct	export_args export;	/* network export information */
19022521Sdyson	uid_t	uid;		/* uid that owns msdosfs files */
19122521Sdyson	gid_t	gid;		/* gid that owns msdosfs files */
19222521Sdyson	mode_t	mask;		/* mask to be applied for msdosfs perms */
19322521Sdyson};
19422521Sdyson
19523351Sbde#endif /* !_MSDOSFS_MSDOSFSMOUNT_H_ */
196