xref: /freebsd/sys/fs/msdosfs/msdosfsmount.h (revision 952a6212d9abd0f11fe608fe552437a24822d41f)
1952a6212SJordan K. Hubbard /*	$Id: msdosfsmount.h,v 1.12 1997/10/12 20:25:02 phk Exp $ */
2952a6212SJordan K. Hubbard /*	$NetBSD: msdosfsmount.h,v 1.17 1997/11/17 15:37:07 ws Exp $	*/
327a0bc89SDoug Rabson 
427a0bc89SDoug Rabson /*-
5952a6212SJordan K. Hubbard  * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
6952a6212SJordan K. Hubbard  * Copyright (C) 1994, 1995, 1997 TooLs GmbH.
727a0bc89SDoug Rabson  * All rights reserved.
827a0bc89SDoug Rabson  * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
927a0bc89SDoug Rabson  *
1027a0bc89SDoug Rabson  * Redistribution and use in source and binary forms, with or without
1127a0bc89SDoug Rabson  * modification, are permitted provided that the following conditions
1227a0bc89SDoug Rabson  * are met:
1327a0bc89SDoug Rabson  * 1. Redistributions of source code must retain the above copyright
1427a0bc89SDoug Rabson  *    notice, this list of conditions and the following disclaimer.
1527a0bc89SDoug Rabson  * 2. Redistributions in binary form must reproduce the above copyright
1627a0bc89SDoug Rabson  *    notice, this list of conditions and the following disclaimer in the
1727a0bc89SDoug Rabson  *    documentation and/or other materials provided with the distribution.
1827a0bc89SDoug Rabson  * 3. All advertising materials mentioning features or use of this software
1927a0bc89SDoug Rabson  *    must display the following acknowledgement:
2027a0bc89SDoug Rabson  *	This product includes software developed by TooLs GmbH.
2127a0bc89SDoug Rabson  * 4. The name of TooLs GmbH may not be used to endorse or promote products
2227a0bc89SDoug Rabson  *    derived from this software without specific prior written permission.
2327a0bc89SDoug Rabson  *
2427a0bc89SDoug Rabson  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
2527a0bc89SDoug Rabson  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2627a0bc89SDoug Rabson  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2727a0bc89SDoug Rabson  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2827a0bc89SDoug Rabson  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2927a0bc89SDoug Rabson  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
3027a0bc89SDoug Rabson  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
3127a0bc89SDoug Rabson  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
3227a0bc89SDoug Rabson  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
3327a0bc89SDoug Rabson  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3427a0bc89SDoug Rabson  */
3527a0bc89SDoug Rabson /*
3627a0bc89SDoug Rabson  * Written by Paul Popelka (paulp@uts.amdahl.com)
3727a0bc89SDoug Rabson  *
3827a0bc89SDoug Rabson  * You can do anything you want with this software, just don't say you wrote
3927a0bc89SDoug Rabson  * it, and don't remove this notice.
4027a0bc89SDoug Rabson  *
4127a0bc89SDoug Rabson  * This software is provided "as is".
4227a0bc89SDoug Rabson  *
4327a0bc89SDoug Rabson  * The author supplies this software to be publicly redistributed on the
4427a0bc89SDoug Rabson  * understanding that the author is not responsible for the correct
4527a0bc89SDoug Rabson  * functioning of this software in any circumstances and is not liable for
4627a0bc89SDoug Rabson  * any damages caused by this software.
4727a0bc89SDoug Rabson  *
4827a0bc89SDoug Rabson  * October 1992
4927a0bc89SDoug Rabson  */
5027a0bc89SDoug Rabson 
5160e0f7e2SBruce Evans #ifndef _MSDOSFS_MSDOSFSMOUNT_H_
5260e0f7e2SBruce Evans #define	_MSDOSFS_MSDOSFSMOUNT_H_
5360e0f7e2SBruce Evans 
5460e0f7e2SBruce Evans #ifdef KERNEL
5560e0f7e2SBruce Evans 
56a1c995b6SPoul-Henning Kamp #ifdef MALLOC_DECLARE
57a1c995b6SPoul-Henning Kamp MALLOC_DECLARE(M_MSDOSFSMNT);
58a1c995b6SPoul-Henning Kamp #endif
59a1c995b6SPoul-Henning Kamp 
6027a0bc89SDoug Rabson /*
6127a0bc89SDoug Rabson  * Layout of the mount control block for a msdos file system.
6227a0bc89SDoug Rabson  */
6327a0bc89SDoug Rabson struct msdosfsmount {
6427a0bc89SDoug Rabson 	struct mount *pm_mountp;/* vfs mount struct for this fs */
6527a0bc89SDoug Rabson 	dev_t pm_dev;		/* block special device mounted */
6627a0bc89SDoug Rabson 	uid_t pm_uid;		/* uid to set as owner of the files */
6727a0bc89SDoug Rabson 	gid_t pm_gid;		/* gid to set as owner of the files */
6827a0bc89SDoug Rabson 	mode_t pm_mask;		/* mask to and with file protection bits */
6927a0bc89SDoug Rabson 	struct vnode *pm_devvp;	/* vnode for block device mntd */
7027a0bc89SDoug Rabson 	struct bpb50 pm_bpb;	/* BIOS parameter blk for this fs */
71952a6212SJordan K. Hubbard 	u_long pm_FATsecs;	/* actual number of fat sectors */
7227a0bc89SDoug Rabson 	u_long pm_fatblk;	/* block # of first FAT */
73952a6212SJordan K. Hubbard 	u_long pm_rootdirblk;	/* block # (cluster # for FAT32) of root directory number */
7427a0bc89SDoug Rabson 	u_long pm_rootdirsize;	/* size in blocks (not clusters) */
7527a0bc89SDoug Rabson 	u_long pm_firstcluster;	/* block number of first cluster */
7627a0bc89SDoug Rabson 	u_long pm_nmbrofclusters;	/* # of clusters in filesystem */
7727a0bc89SDoug Rabson 	u_long pm_maxcluster;	/* maximum cluster number */
7827a0bc89SDoug Rabson 	u_long pm_freeclustercount;	/* number of free clusters */
7927a0bc89SDoug Rabson 	u_long pm_cnshift;	/* shift file offset right this amount to get a cluster number */
8027a0bc89SDoug Rabson 	u_long pm_crbomask;	/* and a file offset with this mask to get cluster rel offset */
81952a6212SJordan K. Hubbard 	u_long pm_bnshift;	/* shift file offset right this amount to get a block number */
8227a0bc89SDoug Rabson 	u_long pm_bpcluster;	/* bytes per cluster */
8327a0bc89SDoug Rabson 	u_long pm_fmod;		/* ~0 if fs is modified, this can rollover to 0	*/
8427a0bc89SDoug Rabson 	u_long pm_fatblocksize;	/* size of fat blocks in bytes */
8527a0bc89SDoug Rabson 	u_long pm_fatblocksec;	/* size of fat blocks in sectors */
8627a0bc89SDoug Rabson 	u_long pm_fatsize;	/* size of fat in bytes */
87952a6212SJordan K. Hubbard 	u_long pm_fatmask;	/* mask to use for fat numbers */
88952a6212SJordan K. Hubbard 	u_long pm_fsinfo;	/* fsinfo block number */
89952a6212SJordan K. Hubbard 	u_long pm_nxtfree;	/* next free cluster in fsinfo block */
90952a6212SJordan K. Hubbard 	u_int pm_fatmult;	/* these 2 values are used in fat */
91952a6212SJordan K. Hubbard 	u_int pm_fatdiv;	/*	offset computation */
92952a6212SJordan K. Hubbard 	u_int pm_curfat;	/* current fat for FAT32 (0 otherwise) */
9327a0bc89SDoug Rabson 	u_int *pm_inusemap;	/* ptr to bitmap of in-use clusters */
94952a6212SJordan K. Hubbard 	u_int pm_flags;		/* see below */
9527a0bc89SDoug Rabson 	struct netexport pm_export;	/* export information */
9627a0bc89SDoug Rabson };
97952a6212SJordan K. Hubbard /* Byte offset in FAT on filesystem pmp, cluster cn */
98952a6212SJordan K. Hubbard #define	FATOFS(pmp, cn)	((cn) * (pmp)->pm_fatmult / (pmp)->pm_fatdiv)
99952a6212SJordan K. Hubbard 
100952a6212SJordan K. Hubbard 
101952a6212SJordan K. Hubbard #define	VFSTOMSDOSFS(mp)	((struct msdosfsmount *)mp->mnt_data)
10227a0bc89SDoug Rabson 
10327a0bc89SDoug Rabson /* Number of bits in one pm_inusemap item: */
10427a0bc89SDoug Rabson #define	N_INUSEBITS	(8 * sizeof(u_int))
10527a0bc89SDoug Rabson 
10627a0bc89SDoug Rabson /*
10727a0bc89SDoug Rabson  * Shorthand for fields in the bpb contained in the msdosfsmount structure.
10827a0bc89SDoug Rabson  */
10927a0bc89SDoug Rabson #define	pm_BytesPerSec	pm_bpb.bpbBytesPerSec
11027a0bc89SDoug Rabson #define	pm_ResSectors	pm_bpb.bpbResSectors
11127a0bc89SDoug Rabson #define	pm_FATs		pm_bpb.bpbFATs
11227a0bc89SDoug Rabson #define	pm_RootDirEnts	pm_bpb.bpbRootDirEnts
11327a0bc89SDoug Rabson #define	pm_Sectors	pm_bpb.bpbSectors
11427a0bc89SDoug Rabson #define	pm_Media	pm_bpb.bpbMedia
11527a0bc89SDoug Rabson #define	pm_SecPerTrack	pm_bpb.bpbSecPerTrack
11627a0bc89SDoug Rabson #define	pm_Heads	pm_bpb.bpbHeads
11727a0bc89SDoug Rabson #define	pm_HiddenSects	pm_bpb.bpbHiddenSecs
11827a0bc89SDoug Rabson #define	pm_HugeSectors	pm_bpb.bpbHugeSectors
11927a0bc89SDoug Rabson 
12027a0bc89SDoug Rabson /*
121952a6212SJordan K. Hubbard  * Convert pointer to buffer -> pointer to direntry
122952a6212SJordan K. Hubbard  */
123952a6212SJordan K. Hubbard #define	bptoep(pmp, bp, dirofs) \
124952a6212SJordan K. Hubbard 	((struct direntry *)(((bp)->b_data)	\
125952a6212SJordan K. Hubbard 	 + ((dirofs) & (pmp)->pm_crbomask)))
126952a6212SJordan K. Hubbard 
127952a6212SJordan K. Hubbard /*
128952a6212SJordan K. Hubbard  * Convert block number to cluster number
129952a6212SJordan K. Hubbard  */
130952a6212SJordan K. Hubbard #define	de_bn2cn(pmp, bn) \
131952a6212SJordan K. Hubbard 	((bn) >> ((pmp)->pm_cnshift - (pmp)->pm_bnshift))
132952a6212SJordan K. Hubbard 
133952a6212SJordan K. Hubbard /*
134952a6212SJordan K. Hubbard  * Convert cluster number to block number
135952a6212SJordan K. Hubbard  */
136952a6212SJordan K. Hubbard #define	de_cn2bn(pmp, cn) \
137952a6212SJordan K. Hubbard 	((cn) << ((pmp)->pm_cnshift - (pmp)->pm_bnshift))
138952a6212SJordan K. Hubbard 
139952a6212SJordan K. Hubbard /*
140952a6212SJordan K. Hubbard  * Convert file offset to cluster number
141952a6212SJordan K. Hubbard  */
142952a6212SJordan K. Hubbard #define de_cluster(pmp, off) \
143952a6212SJordan K. Hubbard 	((off) >> (pmp)->pm_cnshift)
144952a6212SJordan K. Hubbard 
145952a6212SJordan K. Hubbard /*
146952a6212SJordan K. Hubbard  * Clusters required to hold size bytes
147952a6212SJordan K. Hubbard  */
148952a6212SJordan K. Hubbard #define	de_clcount(pmp, size) \
149952a6212SJordan K. Hubbard 	(((size) + (pmp)->pm_bpcluster - 1) >> (pmp)->pm_cnshift)
150952a6212SJordan K. Hubbard 
151952a6212SJordan K. Hubbard /*
152952a6212SJordan K. Hubbard  * Convert file offset to block number
153952a6212SJordan K. Hubbard  */
154952a6212SJordan K. Hubbard #define de_blk(pmp, off) \
155952a6212SJordan K. Hubbard 	(de_cn2bn(pmp, de_cluster((pmp), (off))))
156952a6212SJordan K. Hubbard 
157952a6212SJordan K. Hubbard /*
158952a6212SJordan K. Hubbard  * Convert cluster number to file offset
159952a6212SJordan K. Hubbard  */
160952a6212SJordan K. Hubbard #define	de_cn2off(pmp, cn) \
161952a6212SJordan K. Hubbard 	((cn) << (pmp)->pm_cnshift)
162952a6212SJordan K. Hubbard 
163952a6212SJordan K. Hubbard /*
164952a6212SJordan K. Hubbard  * Convert block number to file offset
165952a6212SJordan K. Hubbard  */
166952a6212SJordan K. Hubbard #define	de_bn2off(pmp, bn) \
167952a6212SJordan K. Hubbard 	((bn) << (pmp)->pm_bnshift)
168952a6212SJordan K. Hubbard /*
16927a0bc89SDoug Rabson  * Map a cluster number into a filesystem relative block number.
17027a0bc89SDoug Rabson  */
17127a0bc89SDoug Rabson #define	cntobn(pmp, cn) \
172952a6212SJordan K. Hubbard 	(de_cn2bn((pmp), (cn)-CLUST_FIRST) + (pmp)->pm_firstcluster)
17327a0bc89SDoug Rabson 
17427a0bc89SDoug Rabson /*
17527a0bc89SDoug Rabson  * Calculate block number for directory entry in root dir, offset dirofs
17627a0bc89SDoug Rabson  */
17727a0bc89SDoug Rabson #define	roottobn(pmp, dirofs) \
178952a6212SJordan K. Hubbard 	(de_blk((pmp), (dirofs)) + (pmp)->pm_rootdirblk)
17927a0bc89SDoug Rabson 
18027a0bc89SDoug Rabson /*
18127a0bc89SDoug Rabson  * Calculate block number for directory entry at cluster dirclu, offset
18227a0bc89SDoug Rabson  * dirofs
18327a0bc89SDoug Rabson  */
18427a0bc89SDoug Rabson #define	detobn(pmp, dirclu, dirofs) \
18527a0bc89SDoug Rabson 	((dirclu) == MSDOSFSROOT \
18627a0bc89SDoug Rabson 	 ? roottobn((pmp), (dirofs)) \
18727a0bc89SDoug Rabson 	 : cntobn((pmp), (dirclu)))
18827a0bc89SDoug Rabson 
1898092a8e1SMike Pritchard int msdosfs_init __P((struct vfsconf *vfsp));
190952a6212SJordan K. Hubbard int msdosfs_mountroot __P((void));
191996c772fSJohn Dyson 
19260e0f7e2SBruce Evans #endif /* KERNEL */
19360e0f7e2SBruce Evans 
194996c772fSJohn Dyson /*
195996c772fSJohn Dyson  *  Arguments to mount MSDOS filesystems.
196996c772fSJohn Dyson  */
197996c772fSJohn Dyson struct msdosfs_args {
198996c772fSJohn Dyson 	char	*fspec;		/* blocks special holding the fs to mount */
199996c772fSJohn Dyson 	struct	export_args export;	/* network export information */
200996c772fSJohn Dyson 	uid_t	uid;		/* uid that owns msdosfs files */
201996c772fSJohn Dyson 	gid_t	gid;		/* gid that owns msdosfs files */
202996c772fSJohn Dyson 	mode_t	mask;		/* mask to be applied for msdosfs perms */
203952a6212SJordan K. Hubbard 	int	flags;		/* see below */
204952a6212SJordan K. Hubbard 	int magic;		/* version number */
205996c772fSJohn Dyson };
206996c772fSJohn Dyson 
207952a6212SJordan K. Hubbard /*
208952a6212SJordan K. Hubbard  * Msdosfs mount options:
209952a6212SJordan K. Hubbard  */
210952a6212SJordan K. Hubbard #define	MSDOSFSMNT_SHORTNAME	1	/* Force old DOS short names only */
211952a6212SJordan K. Hubbard #define	MSDOSFSMNT_LONGNAME	2	/* Force Win'95 long names */
212952a6212SJordan K. Hubbard #define	MSDOSFSMNT_NOWIN95	4	/* Completely ignore Win95 entries */
213952a6212SJordan K. Hubbard #ifndef __FreeBSD__
214952a6212SJordan K. Hubbard #define	MSDOSFSMNT_GEMDOSFS	8	/* This is a gemdos-flavour */
215952a6212SJordan K. Hubbard #endif
216952a6212SJordan K. Hubbard /* All flags above: */
217952a6212SJordan K. Hubbard #define	MSDOSFSMNT_MNTOPT \
218952a6212SJordan K. Hubbard 	(MSDOSFSMNT_SHORTNAME|MSDOSFSMNT_LONGNAME|MSDOSFSMNT_NOWIN95 \
219952a6212SJordan K. Hubbard 	 /*|MSDOSFSMNT_GEMDOSFS*/)
220952a6212SJordan K. Hubbard #define	MSDOSFSMNT_RONLY	0x80000000	/* mounted read-only	*/
221952a6212SJordan K. Hubbard #define	MSDOSFSMNT_WAITONFAT	0x40000000	/* mounted synchronous	*/
222952a6212SJordan K. Hubbard #define	MSDOSFS_FATMIRROR	0x20000000	/* FAT is mirrored */
223952a6212SJordan K. Hubbard 
224952a6212SJordan K. Hubbard #define MSDOSFS_ARGSMAGIC	0xe4eff300
225952a6212SJordan K. Hubbard 
22660e0f7e2SBruce Evans #endif /* !_MSDOSFS_MSDOSFSMOUNT_H_ */
227