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