msdosfsmount.h revision 87007
1/* $FreeBSD: head/sys/fs/msdosfs/msdosfsmount.h 87007 2001-11-27 21:00:15Z jhb $ */
2/*	$NetBSD: msdosfsmount.h,v 1.17 1997/11/17 15:37:07 ws Exp $	*/
3
4/*-
5 * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
6 * Copyright (C) 1994, 1995, 1997 TooLs GmbH.
7 * All rights reserved.
8 * Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 *    must display the following acknowledgement:
20 *	This product includes software developed by TooLs GmbH.
21 * 4. The name of TooLs GmbH may not be used to endorse or promote products
22 *    derived from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
30 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35/*
36 * Written by Paul Popelka (paulp@uts.amdahl.com)
37 *
38 * You can do anything you want with this software, just don't say you wrote
39 * it, and don't remove this notice.
40 *
41 * This software is provided "as is".
42 *
43 * The author supplies this software to be publicly redistributed on the
44 * understanding that the author is not responsible for the correct
45 * functioning of this software in any circumstances and is not liable for
46 * any damages caused by this software.
47 *
48 * October 1992
49 */
50
51#ifndef _MSDOSFS_MSDOSFSMOUNT_H_
52#define	_MSDOSFS_MSDOSFSMOUNT_H_
53
54#ifdef _KERNEL
55
56#ifdef MALLOC_DECLARE
57MALLOC_DECLARE(M_MSDOSFSMNT);
58#endif
59
60/*
61 * Layout of the mount control block for a msdos file system.
62 */
63struct msdosfsmount {
64	struct mount *pm_mountp;/* vfs mount struct for this fs */
65	dev_t pm_dev;		/* block special device mounted */
66	uid_t pm_uid;		/* uid to set as owner of the files */
67	gid_t pm_gid;		/* gid to set as owner of the files */
68	mode_t pm_mask;		/* mask to and with file protection bits */
69	struct vnode *pm_devvp;	/* vnode for block device mntd */
70	struct bpb50 pm_bpb;	/* BIOS parameter blk for this fs */
71	u_long pm_BlkPerSec;	/* How many DEV_BSIZE blocks fit inside a physical sector */
72	u_long pm_FATsecs;	/* actual number of fat sectors */
73	u_long pm_fatblk;	/* block # of first FAT */
74	u_long pm_rootdirblk;	/* block # (cluster # for FAT32) of root directory number */
75	u_long pm_rootdirsize;	/* size in blocks (not clusters) */
76	u_long pm_firstcluster;	/* block number of first cluster */
77	u_long pm_maxcluster;	/* maximum cluster number */
78	u_long pm_freeclustercount;	/* number of free clusters */
79	u_long pm_cnshift;	/* shift file offset right this amount to get a cluster number */
80	u_long pm_crbomask;	/* and a file offset with this mask to get cluster rel offset */
81	u_long pm_bnshift;	/* shift file offset right this amount to get a block number */
82	u_long pm_bpcluster;	/* bytes per cluster */
83	u_long pm_fmod;		/* ~0 if fs is modified, this can rollover to 0	*/
84	u_long pm_fatblocksize;	/* size of fat blocks in bytes */
85	u_long pm_fatblocksec;	/* size of fat blocks in sectors */
86	u_long pm_fatsize;	/* size of fat in bytes */
87	u_int32_t pm_fatmask;	/* mask to use for fat numbers */
88	u_long pm_fsinfo;	/* fsinfo block number */
89	u_long pm_nxtfree;	/* next free cluster in fsinfo block */
90	u_int pm_fatmult;	/* these 2 values are used in fat */
91	u_int pm_fatdiv;	/*	offset computation */
92	u_int pm_curfat;	/* current fat for FAT32 (0 otherwise) */
93	u_int *pm_inusemap;	/* ptr to bitmap of in-use clusters */
94	u_int pm_flags;		/* see below */
95	u_int16_t pm_u2w[128];  /* Local->Unicode table */
96	u_int8_t  pm_ul[128];   /* Local upper->lower table */
97	u_int8_t  pm_lu[128];   /* Local lower->upper table */
98	u_int8_t  pm_d2u[128];  /* DOS->local table */
99	u_int8_t  pm_u2d[128];  /* Local->DOS table */
100};
101/* Byte offset in FAT on filesystem pmp, cluster cn */
102#define	FATOFS(pmp, cn)	((cn) * (pmp)->pm_fatmult / (pmp)->pm_fatdiv)
103
104
105#define	VFSTOMSDOSFS(mp)	((struct msdosfsmount *)mp->mnt_data)
106
107/* Number of bits in one pm_inusemap item: */
108#define	N_INUSEBITS	(8 * sizeof(u_int))
109
110/*
111 * Shorthand for fields in the bpb contained in the msdosfsmount structure.
112 */
113#define	pm_BytesPerSec	pm_bpb.bpbBytesPerSec
114#define	pm_ResSectors	pm_bpb.bpbResSectors
115#define	pm_FATs		pm_bpb.bpbFATs
116#define	pm_RootDirEnts	pm_bpb.bpbRootDirEnts
117#define	pm_Sectors	pm_bpb.bpbSectors
118#define	pm_Media	pm_bpb.bpbMedia
119#define	pm_SecPerTrack	pm_bpb.bpbSecPerTrack
120#define	pm_Heads	pm_bpb.bpbHeads
121#define	pm_HiddenSects	pm_bpb.bpbHiddenSecs
122#define	pm_HugeSectors	pm_bpb.bpbHugeSectors
123
124/*
125 * Convert pointer to buffer -> pointer to direntry
126 */
127#define	bptoep(pmp, bp, dirofs) \
128	((struct direntry *)(((bp)->b_data)	\
129	 + ((dirofs) & (pmp)->pm_crbomask)))
130
131/*
132 * Convert block number to cluster number
133 */
134#define	de_bn2cn(pmp, bn) \
135	((bn) >> ((pmp)->pm_cnshift - (pmp)->pm_bnshift))
136
137/*
138 * Convert cluster number to block number
139 */
140#define	de_cn2bn(pmp, cn) \
141	((cn) << ((pmp)->pm_cnshift - (pmp)->pm_bnshift))
142
143/*
144 * Convert file offset to cluster number
145 */
146#define de_cluster(pmp, off) \
147	((off) >> (pmp)->pm_cnshift)
148
149/*
150 * Clusters required to hold size bytes
151 */
152#define	de_clcount(pmp, size) \
153	(((size) + (pmp)->pm_bpcluster - 1) >> (pmp)->pm_cnshift)
154
155/*
156 * Convert file offset to block number
157 */
158#define de_blk(pmp, off) \
159	(de_cn2bn(pmp, de_cluster((pmp), (off))))
160
161/*
162 * Convert cluster number to file offset
163 */
164#define	de_cn2off(pmp, cn) \
165	((cn) << (pmp)->pm_cnshift)
166
167/*
168 * Convert block number to file offset
169 */
170#define	de_bn2off(pmp, bn) \
171	((bn) << (pmp)->pm_bnshift)
172/*
173 * Map a cluster number into a filesystem relative block number.
174 */
175#define	cntobn(pmp, cn) \
176	(de_cn2bn((pmp), (cn)-CLUST_FIRST) + (pmp)->pm_firstcluster)
177
178/*
179 * Calculate block number for directory entry in root dir, offset dirofs
180 */
181#define	roottobn(pmp, dirofs) \
182	(de_blk((pmp), (dirofs)) + (pmp)->pm_rootdirblk)
183
184/*
185 * Calculate block number for directory entry at cluster dirclu, offset
186 * dirofs
187 */
188#define	detobn(pmp, dirclu, dirofs) \
189	((dirclu) == MSDOSFSROOT \
190	 ? roottobn((pmp), (dirofs)) \
191	 : cntobn((pmp), (dirclu)))
192
193/*
194 * Calculate fsinfo block size
195 */
196#define	fsi_size(pmp) \
197	(1024 << ((pmp)->pm_BlkPerSec >> 2))
198
199int msdosfs_init __P((struct vfsconf *vfsp));
200int msdosfs_uninit __P((struct vfsconf *vfsp));
201int msdosfs_mountroot __P((void));
202
203#endif /* _KERNEL */
204
205/*
206 *  Arguments to mount MSDOS filesystems.
207 */
208struct msdosfs_args {
209	char	*fspec;		/* blocks special holding the fs to mount */
210	struct	export_args export;	/* network export information */
211	uid_t	uid;		/* uid that owns msdosfs files */
212	gid_t	gid;		/* gid that owns msdosfs files */
213	mode_t	mask;		/* mask to be applied for msdosfs perms */
214	int	flags;		/* see below */
215	int magic;		/* version number */
216	u_int16_t u2w[128];     /* Local->Unicode table */
217	u_int8_t  ul[128];      /* Local upper->lower table */
218	u_int8_t  lu[128];      /* Local lower->upper table */
219	u_int8_t  d2u[128];     /* DOS->local table */
220	u_int8_t  u2d[128];     /* Local->DOS table */
221};
222
223/*
224 * Msdosfs mount options:
225 */
226#define	MSDOSFSMNT_SHORTNAME	1	/* Force old DOS short names only */
227#define	MSDOSFSMNT_LONGNAME	2	/* Force Win'95 long names */
228#define	MSDOSFSMNT_NOWIN95	4	/* Completely ignore Win95 entries */
229#define MSDOSFSMNT_U2WTABLE     0x10    /* Local->Unicode and local<->DOS   */
230					/* tables loaded                    */
231#define MSDOSFSMNT_ULTABLE      0x20    /* Local upper<->lower table loaded */
232/* All flags above: */
233#define	MSDOSFSMNT_MNTOPT \
234	(MSDOSFSMNT_SHORTNAME|MSDOSFSMNT_LONGNAME|MSDOSFSMNT_NOWIN95 \
235	 /*|MSDOSFSMNT_GEMDOSFS*/|MSDOSFSMNT_U2WTABLE|MSDOSFSMNT_ULTABLE)
236#define	MSDOSFSMNT_RONLY	0x80000000	/* mounted read-only	*/
237#define	MSDOSFSMNT_WAITONFAT	0x40000000	/* mounted synchronous	*/
238#define	MSDOSFS_FATMIRROR	0x20000000	/* FAT is mirrored */
239
240#define MSDOSFS_ARGSMAGIC	0xe4eff300
241
242#endif /* !_MSDOSFS_MSDOSFSMOUNT_H_ */
243