msdosfs_vfsops.c revision 1.7.4.3 1 1.7.4.2 tls /*-
2 1.7.4.2 tls * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
3 1.7.4.2 tls * Copyright (C) 1994, 1995, 1997 TooLs GmbH.
4 1.7.4.2 tls * All rights reserved.
5 1.7.4.2 tls * Original code by Paul Popelka (paulp (at) uts.amdahl.com) (see below).
6 1.7.4.2 tls *
7 1.7.4.2 tls * Redistribution and use in source and binary forms, with or without
8 1.7.4.2 tls * modification, are permitted provided that the following conditions
9 1.7.4.2 tls * are met:
10 1.7.4.2 tls * 1. Redistributions of source code must retain the above copyright
11 1.7.4.2 tls * notice, this list of conditions and the following disclaimer.
12 1.7.4.2 tls * 2. Redistributions in binary form must reproduce the above copyright
13 1.7.4.2 tls * notice, this list of conditions and the following disclaimer in the
14 1.7.4.2 tls * documentation and/or other materials provided with the distribution.
15 1.7.4.2 tls * 3. All advertising materials mentioning features or use of this software
16 1.7.4.2 tls * must display the following acknowledgement:
17 1.7.4.2 tls * This product includes software developed by TooLs GmbH.
18 1.7.4.2 tls * 4. The name of TooLs GmbH may not be used to endorse or promote products
19 1.7.4.2 tls * derived from this software without specific prior written permission.
20 1.7.4.2 tls *
21 1.7.4.2 tls * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
22 1.7.4.2 tls * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.7.4.2 tls * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.7.4.2 tls * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 1.7.4.2 tls * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 1.7.4.2 tls * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 1.7.4.2 tls * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 1.7.4.2 tls * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 1.7.4.2 tls * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30 1.7.4.2 tls * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.7.4.2 tls */
32 1.7.4.2 tls /*
33 1.7.4.2 tls * Written by Paul Popelka (paulp (at) uts.amdahl.com)
34 1.7.4.2 tls *
35 1.7.4.2 tls * You can do anything you want with this software, just don't say you wrote
36 1.7.4.2 tls * it, and don't remove this notice.
37 1.7.4.2 tls *
38 1.7.4.2 tls * This software is provided "as is".
39 1.7.4.2 tls *
40 1.7.4.2 tls * The author supplies this software to be publicly redistributed on the
41 1.7.4.2 tls * understanding that the author is not responsible for the correct
42 1.7.4.2 tls * functioning of this software in any circumstances and is not liable for
43 1.7.4.2 tls * any damages caused by this software.
44 1.7.4.2 tls *
45 1.7.4.2 tls * October 1992
46 1.7.4.2 tls */
47 1.7.4.2 tls
48 1.7.4.2 tls #if HAVE_NBTOOL_CONFIG_H
49 1.7.4.2 tls #include "nbtool_config.h"
50 1.7.4.2 tls #endif
51 1.7.4.2 tls
52 1.7.4.2 tls #include <sys/cdefs.h>
53 1.7.4.2 tls __KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.7.4.3 2014/08/20 00:05:09 tls Exp $");
54 1.7.4.2 tls
55 1.7.4.2 tls #include <sys/param.h>
56 1.7.4.2 tls
57 1.7.4.2 tls #include <ffs/buf.h>
58 1.7.4.2 tls
59 1.7.4.2 tls #include <fs/msdosfs/bpb.h>
60 1.7.4.2 tls #include <fs/msdosfs/bootsect.h>
61 1.7.4.2 tls #include <fs/msdosfs/direntry.h>
62 1.7.4.2 tls #include <fs/msdosfs/denode.h>
63 1.7.4.2 tls #include <fs/msdosfs/msdosfsmount.h>
64 1.7.4.2 tls #include <fs/msdosfs/fat.h>
65 1.7.4.2 tls
66 1.7.4.2 tls #include <stdio.h>
67 1.7.4.2 tls #include <errno.h>
68 1.7.4.2 tls #include <stdlib.h>
69 1.7.4.2 tls #include <string.h>
70 1.7.4.2 tls #include <util.h>
71 1.7.4.2 tls
72 1.7.4.2 tls #include "makefs.h"
73 1.7.4.2 tls #include "msdos.h"
74 1.7.4.2 tls #include "mkfs_msdos.h"
75 1.7.4.2 tls
76 1.7.4.2 tls #ifdef MSDOSFS_DEBUG
77 1.7.4.2 tls #define DPRINTF(a) printf a
78 1.7.4.2 tls #else
79 1.7.4.2 tls #define DPRINTF(a)
80 1.7.4.2 tls #endif
81 1.7.4.2 tls
82 1.7.4.2 tls struct msdosfsmount *
83 1.7.4.2 tls msdosfs_mount(struct vnode *devvp, int flags)
84 1.7.4.2 tls {
85 1.7.4.2 tls struct msdosfsmount *pmp = NULL;
86 1.7.4.2 tls struct buf *bp;
87 1.7.4.2 tls union bootsector *bsp;
88 1.7.4.2 tls struct byte_bpb33 *b33;
89 1.7.4.2 tls struct byte_bpb50 *b50;
90 1.7.4.2 tls struct byte_bpb710 *b710;
91 1.7.4.2 tls uint8_t SecPerClust;
92 1.7.4.2 tls int ronly = 0, error, tmp;
93 1.7.4.2 tls int bsize;
94 1.7.4.2 tls struct msdos_options *m = devvp->fs->fs_specific;
95 1.7.4.2 tls uint64_t psize = m->create_size;
96 1.7.4.2 tls unsigned secsize = 512;
97 1.7.4.2 tls
98 1.7.4.2 tls DPRINTF(("%s(bread 0)\n", __func__));
99 1.7.4.2 tls if ((error = bread(devvp, 0, secsize, NULL, 0, &bp)) != 0)
100 1.7.4.2 tls goto error_exit;
101 1.7.4.2 tls
102 1.7.4.2 tls bsp = (union bootsector *)bp->b_data;
103 1.7.4.2 tls b33 = (struct byte_bpb33 *)bsp->bs33.bsBPB;
104 1.7.4.2 tls b50 = (struct byte_bpb50 *)bsp->bs50.bsBPB;
105 1.7.4.2 tls b710 = (struct byte_bpb710 *)bsp->bs710.bsBPB;
106 1.7.4.2 tls
107 1.7.4.2 tls if (!(flags & MSDOSFSMNT_GEMDOSFS)) {
108 1.7.4.2 tls if (bsp->bs50.bsBootSectSig0 != BOOTSIG0
109 1.7.4.2 tls || bsp->bs50.bsBootSectSig1 != BOOTSIG1) {
110 1.7.4.2 tls DPRINTF(("bootsig0 %d bootsig1 %d\n",
111 1.7.4.2 tls bsp->bs50.bsBootSectSig0,
112 1.7.4.2 tls bsp->bs50.bsBootSectSig1));
113 1.7.4.2 tls error = EINVAL;
114 1.7.4.2 tls goto error_exit;
115 1.7.4.2 tls }
116 1.7.4.2 tls bsize = 0;
117 1.7.4.2 tls } else
118 1.7.4.2 tls bsize = 512;
119 1.7.4.2 tls
120 1.7.4.2 tls pmp = ecalloc(1, sizeof *pmp);
121 1.7.4.2 tls /*
122 1.7.4.2 tls * Compute several useful quantities from the bpb in the
123 1.7.4.2 tls * bootsector. Copy in the dos 5 variant of the bpb then fix up
124 1.7.4.2 tls * the fields that are different between dos 5 and dos 3.3.
125 1.7.4.2 tls */
126 1.7.4.2 tls SecPerClust = b50->bpbSecPerClust;
127 1.7.4.2 tls pmp->pm_BytesPerSec = getushort(b50->bpbBytesPerSec);
128 1.7.4.2 tls pmp->pm_ResSectors = getushort(b50->bpbResSectors);
129 1.7.4.2 tls pmp->pm_FATs = b50->bpbFATs;
130 1.7.4.2 tls pmp->pm_RootDirEnts = getushort(b50->bpbRootDirEnts);
131 1.7.4.2 tls pmp->pm_Sectors = getushort(b50->bpbSectors);
132 1.7.4.2 tls pmp->pm_FATsecs = getushort(b50->bpbFATsecs);
133 1.7.4.2 tls pmp->pm_SecPerTrack = getushort(b50->bpbSecPerTrack);
134 1.7.4.2 tls pmp->pm_Heads = getushort(b50->bpbHeads);
135 1.7.4.2 tls pmp->pm_Media = b50->bpbMedia;
136 1.7.4.2 tls
137 1.7.4.2 tls DPRINTF(("%s(BytesPerSec=%u, ResSectors=%u, FATs=%d, RootDirEnts=%u, "
138 1.7.4.2 tls "Sectors=%u, FATsecs=%lu, SecPerTrack=%u, Heads=%u, Media=%u)\n",
139 1.7.4.2 tls __func__, pmp->pm_BytesPerSec, pmp->pm_ResSectors, pmp->pm_FATs,
140 1.7.4.2 tls pmp->pm_RootDirEnts, pmp->pm_Sectors, pmp->pm_FATsecs,
141 1.7.4.2 tls pmp->pm_SecPerTrack, pmp->pm_Heads, pmp->pm_Media));
142 1.7.4.2 tls if (!(flags & MSDOSFSMNT_GEMDOSFS)) {
143 1.7.4.2 tls /* XXX - We should probably check more values here */
144 1.7.4.2 tls if (!pmp->pm_BytesPerSec || !SecPerClust
145 1.7.4.2 tls || pmp->pm_SecPerTrack > 63) {
146 1.7.4.2 tls DPRINTF(("bytespersec %d secperclust %d "
147 1.7.4.2 tls "secpertrack %d\n",
148 1.7.4.2 tls pmp->pm_BytesPerSec, SecPerClust,
149 1.7.4.2 tls pmp->pm_SecPerTrack));
150 1.7.4.2 tls error = EINVAL;
151 1.7.4.2 tls goto error_exit;
152 1.7.4.2 tls }
153 1.7.4.2 tls }
154 1.7.4.2 tls
155 1.7.4.2 tls if (pmp->pm_Sectors == 0) {
156 1.7.4.2 tls pmp->pm_HiddenSects = getulong(b50->bpbHiddenSecs);
157 1.7.4.2 tls pmp->pm_HugeSectors = getulong(b50->bpbHugeSectors);
158 1.7.4.2 tls } else {
159 1.7.4.2 tls pmp->pm_HiddenSects = getushort(b33->bpbHiddenSecs);
160 1.7.4.2 tls pmp->pm_HugeSectors = pmp->pm_Sectors;
161 1.7.4.2 tls }
162 1.7.4.2 tls
163 1.7.4.2 tls if (pmp->pm_RootDirEnts == 0) {
164 1.7.4.2 tls unsigned short vers = getushort(b710->bpbFSVers);
165 1.7.4.2 tls /*
166 1.7.4.2 tls * Some say that bsBootSectSig[23] must be zero, but
167 1.7.4.2 tls * Windows does not require this and some digital cameras
168 1.7.4.2 tls * do not set these to zero. Therefore, do not insist.
169 1.7.4.2 tls */
170 1.7.4.2 tls if (pmp->pm_Sectors || pmp->pm_FATsecs || vers) {
171 1.7.4.2 tls DPRINTF(("sectors %d fatsecs %lu vers %d\n",
172 1.7.4.2 tls pmp->pm_Sectors, pmp->pm_FATsecs, vers));
173 1.7.4.2 tls error = EINVAL;
174 1.7.4.2 tls goto error_exit;
175 1.7.4.2 tls }
176 1.7.4.2 tls pmp->pm_fatmask = FAT32_MASK;
177 1.7.4.2 tls pmp->pm_fatmult = 4;
178 1.7.4.2 tls pmp->pm_fatdiv = 1;
179 1.7.4.2 tls pmp->pm_FATsecs = getulong(b710->bpbBigFATsecs);
180 1.7.4.2 tls
181 1.7.4.2 tls /* mirrorring is enabled if the FATMIRROR bit is not set */
182 1.7.4.2 tls if ((getushort(b710->bpbExtFlags) & FATMIRROR) == 0)
183 1.7.4.2 tls pmp->pm_flags |= MSDOSFS_FATMIRROR;
184 1.7.4.2 tls else
185 1.7.4.2 tls pmp->pm_curfat = getushort(b710->bpbExtFlags) & FATNUM;
186 1.7.4.2 tls } else
187 1.7.4.2 tls pmp->pm_flags |= MSDOSFS_FATMIRROR;
188 1.7.4.2 tls
189 1.7.4.2 tls if (flags & MSDOSFSMNT_GEMDOSFS) {
190 1.7.4.2 tls if (FAT32(pmp)) {
191 1.7.4.2 tls DPRINTF(("FAT32 for GEMDOS\n"));
192 1.7.4.2 tls /*
193 1.7.4.2 tls * GEMDOS doesn't know FAT32.
194 1.7.4.2 tls */
195 1.7.4.2 tls error = EINVAL;
196 1.7.4.2 tls goto error_exit;
197 1.7.4.2 tls }
198 1.7.4.2 tls
199 1.7.4.2 tls /*
200 1.7.4.2 tls * Check a few values (could do some more):
201 1.7.4.2 tls * - logical sector size: power of 2, >= block size
202 1.7.4.2 tls * - sectors per cluster: power of 2, >= 1
203 1.7.4.2 tls * - number of sectors: >= 1, <= size of partition
204 1.7.4.2 tls */
205 1.7.4.2 tls if ( (SecPerClust == 0)
206 1.7.4.2 tls || (SecPerClust & (SecPerClust - 1))
207 1.7.4.2 tls || (pmp->pm_BytesPerSec < bsize)
208 1.7.4.2 tls || (pmp->pm_BytesPerSec & (pmp->pm_BytesPerSec - 1))
209 1.7.4.2 tls || (pmp->pm_HugeSectors == 0)
210 1.7.4.2 tls || (pmp->pm_HugeSectors * (pmp->pm_BytesPerSec / bsize)
211 1.7.4.2 tls > psize)) {
212 1.7.4.2 tls DPRINTF(("consistency checks for GEMDOS\n"));
213 1.7.4.2 tls error = EINVAL;
214 1.7.4.2 tls goto error_exit;
215 1.7.4.2 tls }
216 1.7.4.2 tls /*
217 1.7.4.2 tls * XXX - Many parts of the msdosfs driver seem to assume that
218 1.7.4.2 tls * the number of bytes per logical sector (BytesPerSec) will
219 1.7.4.2 tls * always be the same as the number of bytes per disk block
220 1.7.4.2 tls * Let's pretend it is.
221 1.7.4.2 tls */
222 1.7.4.2 tls tmp = pmp->pm_BytesPerSec / bsize;
223 1.7.4.2 tls pmp->pm_BytesPerSec = bsize;
224 1.7.4.2 tls pmp->pm_HugeSectors *= tmp;
225 1.7.4.2 tls pmp->pm_HiddenSects *= tmp;
226 1.7.4.2 tls pmp->pm_ResSectors *= tmp;
227 1.7.4.2 tls pmp->pm_Sectors *= tmp;
228 1.7.4.2 tls pmp->pm_FATsecs *= tmp;
229 1.7.4.2 tls SecPerClust *= tmp;
230 1.7.4.2 tls }
231 1.7.4.2 tls
232 1.7.4.2 tls /* Check that fs has nonzero FAT size */
233 1.7.4.2 tls if (pmp->pm_FATsecs == 0) {
234 1.7.4.2 tls DPRINTF(("FATsecs is 0\n"));
235 1.7.4.2 tls error = EINVAL;
236 1.7.4.2 tls goto error_exit;
237 1.7.4.2 tls }
238 1.7.4.2 tls
239 1.7.4.2 tls pmp->pm_fatblk = pmp->pm_ResSectors;
240 1.7.4.2 tls if (FAT32(pmp)) {
241 1.7.4.2 tls pmp->pm_rootdirblk = getulong(b710->bpbRootClust);
242 1.7.4.2 tls pmp->pm_firstcluster = pmp->pm_fatblk
243 1.7.4.2 tls + (pmp->pm_FATs * pmp->pm_FATsecs);
244 1.7.4.2 tls pmp->pm_fsinfo = getushort(b710->bpbFSInfo);
245 1.7.4.2 tls } else {
246 1.7.4.2 tls pmp->pm_rootdirblk = pmp->pm_fatblk +
247 1.7.4.2 tls (pmp->pm_FATs * pmp->pm_FATsecs);
248 1.7.4.2 tls pmp->pm_rootdirsize = (pmp->pm_RootDirEnts * sizeof(struct direntry)
249 1.7.4.2 tls + pmp->pm_BytesPerSec - 1)
250 1.7.4.2 tls / pmp->pm_BytesPerSec;/* in sectors */
251 1.7.4.2 tls pmp->pm_firstcluster = pmp->pm_rootdirblk + pmp->pm_rootdirsize;
252 1.7.4.2 tls }
253 1.7.4.2 tls
254 1.7.4.2 tls pmp->pm_nmbrofclusters = (pmp->pm_HugeSectors - pmp->pm_firstcluster) /
255 1.7.4.2 tls SecPerClust;
256 1.7.4.2 tls pmp->pm_maxcluster = pmp->pm_nmbrofclusters + 1;
257 1.7.4.2 tls pmp->pm_fatsize = pmp->pm_FATsecs * pmp->pm_BytesPerSec;
258 1.7.4.2 tls
259 1.7.4.2 tls if (flags & MSDOSFSMNT_GEMDOSFS) {
260 1.7.4.2 tls if (pmp->pm_nmbrofclusters <= (0xff0 - 2)) {
261 1.7.4.2 tls pmp->pm_fatmask = FAT12_MASK;
262 1.7.4.2 tls pmp->pm_fatmult = 3;
263 1.7.4.2 tls pmp->pm_fatdiv = 2;
264 1.7.4.2 tls } else {
265 1.7.4.2 tls pmp->pm_fatmask = FAT16_MASK;
266 1.7.4.2 tls pmp->pm_fatmult = 2;
267 1.7.4.2 tls pmp->pm_fatdiv = 1;
268 1.7.4.2 tls }
269 1.7.4.2 tls } else if (pmp->pm_fatmask == 0) {
270 1.7.4.2 tls if (pmp->pm_maxcluster
271 1.7.4.2 tls <= ((CLUST_RSRVD - CLUST_FIRST) & FAT12_MASK)) {
272 1.7.4.2 tls /*
273 1.7.4.2 tls * This will usually be a floppy disk. This size makes
274 1.7.4.2 tls * sure that one FAT entry will not be split across
275 1.7.4.2 tls * multiple blocks.
276 1.7.4.2 tls */
277 1.7.4.2 tls pmp->pm_fatmask = FAT12_MASK;
278 1.7.4.2 tls pmp->pm_fatmult = 3;
279 1.7.4.2 tls pmp->pm_fatdiv = 2;
280 1.7.4.2 tls } else {
281 1.7.4.2 tls pmp->pm_fatmask = FAT16_MASK;
282 1.7.4.2 tls pmp->pm_fatmult = 2;
283 1.7.4.2 tls pmp->pm_fatdiv = 1;
284 1.7.4.2 tls }
285 1.7.4.2 tls }
286 1.7.4.2 tls if (FAT12(pmp))
287 1.7.4.2 tls pmp->pm_fatblocksize = 3 * pmp->pm_BytesPerSec;
288 1.7.4.2 tls else
289 1.7.4.2 tls pmp->pm_fatblocksize = MAXBSIZE;
290 1.7.4.2 tls
291 1.7.4.2 tls pmp->pm_fatblocksec = pmp->pm_fatblocksize / pmp->pm_BytesPerSec;
292 1.7.4.2 tls pmp->pm_bnshift = ffs(pmp->pm_BytesPerSec) - 1;
293 1.7.4.2 tls
294 1.7.4.2 tls /*
295 1.7.4.2 tls * Compute mask and shift value for isolating cluster relative byte
296 1.7.4.2 tls * offsets and cluster numbers from a file offset.
297 1.7.4.2 tls */
298 1.7.4.2 tls pmp->pm_bpcluster = SecPerClust * pmp->pm_BytesPerSec;
299 1.7.4.2 tls pmp->pm_crbomask = pmp->pm_bpcluster - 1;
300 1.7.4.2 tls pmp->pm_cnshift = ffs(pmp->pm_bpcluster) - 1;
301 1.7.4.2 tls
302 1.7.4.2 tls DPRINTF(("%s(fatmask=%lu, fatmult=%u, fatdiv=%u, fatblocksize=%lu, "
303 1.7.4.2 tls "fatblocksec=%lu, bnshift=%lu, pbcluster=%lu, crbomask=%lu, "
304 1.7.4.2 tls "cnshift=%lu)\n",
305 1.7.4.2 tls __func__, pmp->pm_fatmask, pmp->pm_fatmult, pmp->pm_fatdiv,
306 1.7.4.2 tls pmp->pm_fatblocksize, pmp->pm_fatblocksec, pmp->pm_bnshift,
307 1.7.4.2 tls pmp->pm_bpcluster, pmp->pm_crbomask, pmp->pm_cnshift));
308 1.7.4.2 tls /*
309 1.7.4.2 tls * Check for valid cluster size
310 1.7.4.2 tls * must be a power of 2
311 1.7.4.2 tls */
312 1.7.4.2 tls if (pmp->pm_bpcluster ^ (1 << pmp->pm_cnshift)) {
313 1.7.4.2 tls DPRINTF(("bpcluster %lu cnshift %lu\n",
314 1.7.4.2 tls pmp->pm_bpcluster, pmp->pm_cnshift));
315 1.7.4.2 tls error = EINVAL;
316 1.7.4.2 tls goto error_exit;
317 1.7.4.2 tls }
318 1.7.4.2 tls
319 1.7.4.2 tls /*
320 1.7.4.2 tls * Release the bootsector buffer.
321 1.7.4.2 tls */
322 1.7.4.2 tls brelse(bp, BC_AGE);
323 1.7.4.2 tls bp = NULL;
324 1.7.4.2 tls
325 1.7.4.2 tls /*
326 1.7.4.2 tls * Check FSInfo.
327 1.7.4.2 tls */
328 1.7.4.2 tls if (pmp->pm_fsinfo) {
329 1.7.4.2 tls struct fsinfo *fp;
330 1.7.4.2 tls
331 1.7.4.2 tls /*
332 1.7.4.2 tls * XXX If the fsinfo block is stored on media with
333 1.7.4.2 tls * 2KB or larger sectors, is the fsinfo structure
334 1.7.4.2 tls * padded at the end or in the middle?
335 1.7.4.2 tls */
336 1.7.4.2 tls DPRINTF(("%s(bread %lu)\n", __func__,
337 1.7.4.2 tls (unsigned long)de_bn2kb(pmp, pmp->pm_fsinfo)));
338 1.7.4.2 tls if ((error = bread(devvp, de_bn2kb(pmp, pmp->pm_fsinfo),
339 1.7.4.2 tls pmp->pm_BytesPerSec, NULL, 0, &bp)) != 0)
340 1.7.4.2 tls goto error_exit;
341 1.7.4.2 tls fp = (struct fsinfo *)bp->b_data;
342 1.7.4.2 tls if (!memcmp(fp->fsisig1, "RRaA", 4)
343 1.7.4.2 tls && !memcmp(fp->fsisig2, "rrAa", 4)
344 1.7.4.2 tls && !memcmp(fp->fsisig3, "\0\0\125\252", 4)
345 1.7.4.2 tls && !memcmp(fp->fsisig4, "\0\0\125\252", 4))
346 1.7.4.2 tls pmp->pm_nxtfree = getulong(fp->fsinxtfree);
347 1.7.4.2 tls else
348 1.7.4.2 tls pmp->pm_fsinfo = 0;
349 1.7.4.2 tls brelse(bp, 0);
350 1.7.4.2 tls bp = NULL;
351 1.7.4.2 tls }
352 1.7.4.2 tls
353 1.7.4.2 tls /*
354 1.7.4.2 tls * Check and validate (or perhaps invalidate?) the fsinfo structure?
355 1.7.4.2 tls * XXX
356 1.7.4.2 tls */
357 1.7.4.2 tls if (pmp->pm_fsinfo) {
358 1.7.4.2 tls if ((pmp->pm_nxtfree == 0xffffffffUL) ||
359 1.7.4.2 tls (pmp->pm_nxtfree > pmp->pm_maxcluster))
360 1.7.4.2 tls pmp->pm_fsinfo = 0;
361 1.7.4.2 tls }
362 1.7.4.2 tls
363 1.7.4.2 tls /*
364 1.7.4.2 tls * Allocate memory for the bitmap of allocated clusters, and then
365 1.7.4.2 tls * fill it in.
366 1.7.4.2 tls */
367 1.7.4.2 tls pmp->pm_inusemap = ecalloc(sizeof(*pmp->pm_inusemap),
368 1.7.4.2 tls ((pmp->pm_maxcluster + N_INUSEBITS) / N_INUSEBITS));
369 1.7.4.2 tls /*
370 1.7.4.2 tls * fillinusemap() needs pm_devvp.
371 1.7.4.2 tls */
372 1.7.4.2 tls pmp->pm_dev = 0;
373 1.7.4.2 tls pmp->pm_devvp = devvp;
374 1.7.4.2 tls
375 1.7.4.2 tls /*
376 1.7.4.2 tls * Have the inuse map filled in.
377 1.7.4.2 tls */
378 1.7.4.2 tls if ((error = fillinusemap(pmp)) != 0) {
379 1.7.4.2 tls DPRINTF(("fillinusemap %d\n", error));
380 1.7.4.2 tls goto error_exit;
381 1.7.4.2 tls }
382 1.7.4.2 tls
383 1.7.4.2 tls /*
384 1.7.4.2 tls * Finish up.
385 1.7.4.2 tls */
386 1.7.4.2 tls if (ronly)
387 1.7.4.2 tls pmp->pm_flags |= MSDOSFSMNT_RONLY;
388 1.7.4.2 tls else
389 1.7.4.2 tls pmp->pm_fmod = 1;
390 1.7.4.2 tls
391 1.7.4.2 tls /*
392 1.7.4.2 tls * If we ever do quotas for DOS filesystems this would be a place
393 1.7.4.2 tls * to fill in the info in the msdosfsmount structure. You dolt,
394 1.7.4.2 tls * quotas on dos filesystems make no sense because files have no
395 1.7.4.2 tls * owners on dos filesystems. of course there is some empty space
396 1.7.4.2 tls * in the directory entry where we could put uid's and gid's.
397 1.7.4.2 tls */
398 1.7.4.2 tls
399 1.7.4.2 tls return pmp;
400 1.7.4.2 tls
401 1.7.4.2 tls error_exit:
402 1.7.4.2 tls if (bp)
403 1.7.4.2 tls brelse(bp, BC_AGE);
404 1.7.4.2 tls if (pmp) {
405 1.7.4.2 tls if (pmp->pm_inusemap)
406 1.7.4.2 tls free(pmp->pm_inusemap);
407 1.7.4.2 tls free(pmp);
408 1.7.4.2 tls }
409 1.7.4.2 tls errno = error;
410 1.7.4.3 tls return NULL;
411 1.7.4.2 tls }
412 1.7.4.2 tls
413 1.7.4.2 tls int
414 1.7.4.2 tls msdosfs_root(struct msdosfsmount *pmp, struct vnode *vp) {
415 1.7.4.2 tls struct denode *ndep;
416 1.7.4.2 tls int error;
417 1.7.4.2 tls
418 1.7.4.2 tls *vp = *pmp->pm_devvp;
419 1.7.4.2 tls if ((error = deget(pmp, MSDOSFSROOT, MSDOSFSROOT_OFS, &ndep)) != 0) {
420 1.7.4.2 tls errno = error;
421 1.7.4.2 tls return -1;
422 1.7.4.2 tls }
423 1.7.4.2 tls vp->v_data = ndep;
424 1.7.4.2 tls return 0;
425 1.7.4.2 tls }
426