1 /*	$OpenBSD: msdosfsmount.h,v 1.1 2016/10/18 17:05:30 natano Exp $	*/
2 /*	$NetBSD: msdosfsmount.h,v 1.21 2016/01/30 09:59:27 mlelstv 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 
55 /*
56  * Msdosfs mount options:
57  */
58 #define	MSDOSFSMNT_SHORTNAME	1	/* Force old DOS short names only */
59 #define	MSDOSFSMNT_LONGNAME	2	/* Force Win'95 long names */
60 #define	MSDOSFSMNT_NOWIN95	4	/* Completely ignore Win95 entries */
61 #define MSDOSFSMNT_VERSIONED	16	/* Struct is versioned */
62 
63 /* All flags above: */
64 #define	MSDOSFSMNT_MNTOPT \
65 	(MSDOSFSMNT_SHORTNAME|MSDOSFSMNT_LONGNAME|MSDOSFSMNT_NOWIN95 \
66 	 |MSDOSFSMNT_VERSIONED)
67 
68 #define	MSDOSFSMNT_RONLY	0x80000000	/* mounted read-only	*/
69 #define	MSDOSFSMNT_WAITONFAT	0x40000000	/* mounted synchronous	*/
70 #define	MSDOSFS_FATMIRROR	0x20000000	/* FAT is mirrored */
71 
72 
73 /*
74  * Layout of the mount control block for a MSDOSFS file system.
75  */
76 struct msdosfsmount {
77 	struct mount *pm_mountp;/* vfs mount struct for this fs */
78 	dev_t pm_dev;		/* block special device mounted */
79 	uid_t pm_uid;		/* uid to set as owner of the files */
80 	gid_t pm_gid;		/* gid to set as owner of the files */
81 	mode_t pm_mask;		/* mask to and with file protection bits
82 				   for files */
83 	mode_t pm_dirmask;	/* mask to and with file protection bits
84 				   for directories */
85 	int pm_minuteswest;	/* of Greenwitch */
86 	struct mkfsvnode *pm_devvp;	/* mkfsvnode for block device mntd */
87 	struct bpb50 pm_bpb;	/* BIOS parameter blk for this fs */
88 	u_long pm_FATsecs;	/* actual number of FAT sectors */
89 	u_long pm_fatblk;	/* sector # of first FAT */
90 	u_long pm_rootdirblk;	/* sector # (cluster # for FAT32) of root directory number */
91 	u_long pm_rootdirsize;	/* size in sectors (not clusters) */
92 	u_long pm_firstcluster;	/* sector number of first cluster */
93 	u_long pm_nmbrofclusters;	/* # of clusters in filesystem */
94 	u_long pm_maxcluster;	/* maximum cluster number */
95 	u_long pm_freeclustercount;	/* number of free clusters */
96 	u_long pm_cnshift;	/* shift file offset right this amount to get a cluster number */
97 	u_long pm_crbomask;	/* and a file offset with this mask to get cluster rel offset */
98 	u_long pm_bnshift;	/* shift file offset right this amount to get a sector number */
99 	u_long pm_bpcluster;	/* bytes per cluster */
100 	u_long pm_fmod;		/* ~0 if fs is modified, this can rollover to 0	*/
101 	u_long pm_fatblocksize;	/* size of FAT blocks in bytes */
102 	u_long pm_fatblocksec;	/* size of FAT blocks in sectors */
103 	u_long pm_fatsize;	/* size of FAT in bytes */
104 	u_long pm_fatmask;	/* mask to use for FAT numbers */
105 	u_long pm_fsinfo;	/* fsinfo block number */
106 	u_long pm_nxtfree;	/* next free cluster in fsinfo block */
107 	u_int pm_fatmult;	/* these 2 values are used in FAT */
108 	u_int pm_fatdiv;	/*	offset computation */
109 	u_int pm_curfat;	/* current FAT for FAT32 (0 otherwise) */
110 	u_int *pm_inusemap;	/* ptr to bitmap of in-use clusters */
111 	u_int pm_flags;		/* see below */
112 };
113 /* Byte offset in FAT on filesystem pmp, cluster cn */
114 #define	FATOFS(pmp, cn)	((cn) * (pmp)->pm_fatmult / (pmp)->pm_fatdiv)
115 
116 #define	VFSTOMSDOSFS(mp)	((struct msdosfsmount *)mp->mnt_data)
117 
118 /* Number of bits in one pm_inusemap item: */
119 #define	N_INUSEBITS	(8 * sizeof(u_int))
120 
121 /*
122  * Shorthand for fields in the bpb contained in the msdosfsmount structure.
123  */
124 #define	pm_BytesPerSec	pm_bpb.bpbBytesPerSec
125 #define	pm_ResSectors	pm_bpb.bpbResSectors
126 #define	pm_FATs		pm_bpb.bpbFATs
127 #define	pm_RootDirEnts	pm_bpb.bpbRootDirEnts
128 #define	pm_Sectors	pm_bpb.bpbSectors
129 #define	pm_Media	pm_bpb.bpbMedia
130 #define	pm_SecPerTrack	pm_bpb.bpbSecPerTrack
131 #define	pm_Heads	pm_bpb.bpbHeads
132 #define	pm_HiddenSects	pm_bpb.bpbHiddenSecs
133 #define	pm_HugeSectors	pm_bpb.bpbHugeSectors
134 
135 /*
136  * Convert pointer to buffer -> pointer to direntry
137  */
138 #define	bptoep(pmp, bp, dirofs) \
139 	((struct direntry *)(((char *)(bp)->b_data)	\
140 	 + ((dirofs) & (pmp)->pm_crbomask)))
141 
142 /*
143  * Convert sector number to cluster number
144  */
145 #define	de_bn2cn(pmp, bn) \
146 	((bn) >> ((pmp)->pm_cnshift - (pmp)->pm_bnshift))
147 
148 /*
149  * Convert cluster number to sector number
150  */
151 #define	de_cn2bn(pmp, cn) \
152 	((cn) << ((pmp)->pm_cnshift - (pmp)->pm_bnshift))
153 
154 /*
155  * Convert sector number to kernel block number
156  */
157 #define de_bn2kb(pmp, bn) \
158 	((bn) << ((pmp)->pm_bnshift - DEV_BSHIFT))
159 
160 /*
161  * Convert kernel block number to sector number
162  */
163 #define de_kb2bn(pmp, kb) \
164 	((kb) >> ((pmp)->pm_bnshift - DEV_BSHIFT))
165 
166 /*
167  * Convert file offset to cluster number
168  */
169 #define de_cluster(pmp, off) \
170 	((off) >> (pmp)->pm_cnshift)
171 
172 /*
173  * Clusters required to hold size bytes
174  */
175 #define	de_clcount(pmp, size) \
176 	(((size) + (pmp)->pm_bpcluster - 1) >> (pmp)->pm_cnshift)
177 
178 /*
179  * Convert file offset to sector number
180  */
181 #define de_blk(pmp, off) \
182 	(de_cn2bn(pmp, de_cluster((pmp), (off))))
183 
184 /*
185  * Convert cluster number to file offset
186  */
187 #define	de_cn2off(pmp, cn) \
188 	((cn) << (pmp)->pm_cnshift)
189 
190 /*
191  * Convert sector number to file offset
192  */
193 #define	de_bn2off(pmp, bn) \
194 	((bn) << (pmp)->pm_bnshift)
195 /*
196  * Map a cluster number into a filesystem relative sector number.
197  */
198 #define	cntobn(pmp, cn) \
199 	(de_cn2bn((pmp), (cn)-CLUST_FIRST) + (pmp)->pm_firstcluster)
200 
201 /*
202  * Calculate sector number for directory entry in root dir, offset dirofs
203  */
204 #define	roottobn(pmp, dirofs) \
205 	(de_blk((pmp), (dirofs)) + (pmp)->pm_rootdirblk)
206 
207 /*
208  * Calculate sector number for directory entry at cluster dirclu, offset
209  * dirofs
210  */
211 #define	detobn(pmp, dirclu, dirofs) \
212 	((dirclu) == MSDOSFSROOT \
213 	 ? roottobn((pmp), (dirofs)) \
214 	 : cntobn((pmp), (dirclu)))
215 
216 /*
217  * Prototypes for MSDOSFS virtual filesystem operations
218  */
219 void msdosfs_init(void);
220 void msdosfs_reinit(void);
221 void msdosfs_done(void);
222 
223 
224 #endif /* _MSDOSFS_MSDOSFSMOUNT_H_ */
225