1/*
2 * Copyright (C) 1995, 1997 Wolfgang Solfrank
3 * Copyright (c) 1995 Martin Husemann
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26
27#include <sys/cdefs.h>
28#ifndef lint
29__RCSID("$NetBSD: boot.c,v 1.9 2003/07/24 19:25:46 ws Exp $");
30static const char rcsid[] =
31 "$FreeBSD: head/sbin/fsck_msdosfs/boot.c 203874 2010-02-14 12:31:28Z kib $";
32#endif /* not lint */
33
34#include <stdlib.h>
35#include <string.h>
36#include <stdio.h>
37#include <unistd.h>
38
39#include "ext.h"
40#include "fsutil.h"
41
42int
43readboot(int dosfs, struct bootblock *boot)
44{
45 u_char block[DOSBOOTBLOCKSIZE];
46 u_char fsinfo[2 * DOSBOOTBLOCKSIZE];
47 u_char backup[DOSBOOTBLOCKSIZE];
48 int ret = FSOK;
49 int i;
50
51 if ((size_t)read(dosfs, block, sizeof block) != sizeof block) {
52 perror("could not read boot block");
53 return FSFATAL;
54 }
55
56 if (block[510] != 0x55 || block[511] != 0xaa) {
57 pfatal("Invalid signature in boot block: %02x%02x", block[511], block[510]);
58 return FSFATAL;
59 }
60
61 memset(boot, 0, sizeof *boot);
62 boot->ValidFat = -1;
63
64 /* decode bios parameter block */
65 boot->bpbBytesPerSec = block[11] + (block[12] << 8);
66 boot->bpbSecPerClust = block[13];
67 boot->bpbResSectors = block[14] + (block[15] << 8);
68 boot->bpbFATs = block[16];
69 boot->bpbRootDirEnts = block[17] + (block[18] << 8);
70 boot->bpbSectors = block[19] + (block[20] << 8);
71 boot->bpbMedia = block[21];
72 boot->bpbFATsmall = block[22] + (block[23] << 8);
73 boot->SecPerTrack = block[24] + (block[25] << 8);
74 boot->bpbHeads = block[26] + (block[27] << 8);
75 boot->bpbHiddenSecs = block[28] + (block[29] << 8) + (block[30] << 16) + (block[31] << 24);
76 boot->bpbHugeSectors = block[32] + (block[33] << 8) + (block[34] << 16) + (block[35] << 24);
77
78 boot->FATsecs = boot->bpbFATsmall;
79
80 if (!boot->bpbRootDirEnts)
81 boot->flags |= FAT32;
82 if (boot->flags & FAT32) {
83 boot->FATsecs = block[36] + (block[37] << 8)
84 + (block[38] << 16) + (block[39] << 24);
85 if (block[40] & 0x80)
86 boot->ValidFat = block[40] & 0x0f;
87
88 /* check version number: */
89 if (block[42] || block[43]) {
90 /* Correct? XXX */
91 pfatal("Unknown file system version: %x.%x",
92 block[43], block[42]);
93 return FSFATAL;
94 }
95 boot->bpbRootClust = block[44] + (block[45] << 8)
96 + (block[46] << 16) + (block[47] << 24);
97 boot->bpbFSInfo = block[48] + (block[49] << 8);
98 boot->bpbBackup = block[50] + (block[51] << 8);
99
100 if (lseek(dosfs, boot->bpbFSInfo * boot->bpbBytesPerSec, SEEK_SET)
101 != boot->bpbFSInfo * boot->bpbBytesPerSec
102 || read(dosfs, fsinfo, sizeof fsinfo)
103 != sizeof fsinfo) {
104 perror("could not read fsinfo block");
105 return FSFATAL;
106 }
107 if (memcmp(fsinfo, "RRaA", 4)
108 || memcmp(fsinfo + 0x1e4, "rrAa", 4)
109 || fsinfo[0x1fc]
110 || fsinfo[0x1fd]
111 || fsinfo[0x1fe] != 0x55
112 || fsinfo[0x1ff] != 0xaa
113 || fsinfo[0x3fc]
114 || fsinfo[0x3fd]
115 || fsinfo[0x3fe] != 0x55
116 || fsinfo[0x3ff] != 0xaa) {
117 pwarn("Invalid signature in fsinfo block\n");
118 if (ask(0, "Fix")) {
119 memcpy(fsinfo, "RRaA", 4);
120 memcpy(fsinfo + 0x1e4, "rrAa", 4);
121 fsinfo[0x1fc] = fsinfo[0x1fd] = 0;
122 fsinfo[0x1fe] = 0x55;
123 fsinfo[0x1ff] = 0xaa;
124 fsinfo[0x3fc] = fsinfo[0x3fd] = 0;
125 fsinfo[0x3fe] = 0x55;
126 fsinfo[0x3ff] = 0xaa;
127 if (lseek(dosfs, boot->bpbFSInfo * boot->bpbBytesPerSec, SEEK_SET)
128 != boot->bpbFSInfo * boot->bpbBytesPerSec
129 || write(dosfs, fsinfo, sizeof fsinfo)
130 != sizeof fsinfo) {
131 perror("Unable to write bpbFSInfo");
132 return FSFATAL;
133 }
134 ret = FSBOOTMOD;
135 } else
136 boot->bpbFSInfo = 0;
137 }
138 if (boot->bpbFSInfo) {
139 boot->FSFree = fsinfo[0x1e8] + (fsinfo[0x1e9] << 8)
140 + (fsinfo[0x1ea] << 16)
141 + (fsinfo[0x1eb] << 24);
142 boot->FSNext = fsinfo[0x1ec] + (fsinfo[0x1ed] << 8)
143 + (fsinfo[0x1ee] << 16)
144 + (fsinfo[0x1ef] << 24);
145 }
146
147 if (lseek(dosfs, boot->bpbBackup * boot->bpbBytesPerSec, SEEK_SET)
148 != boot->bpbBackup * boot->bpbBytesPerSec
149 || read(dosfs, backup, sizeof backup) != sizeof backup) {
150 perror("could not read backup bootblock");
151 return FSFATAL;
152 }
153 backup[65] = block[65]; /* XXX */
154 if (memcmp(block + 11, backup + 11, 79)) {
155 /*
156 * XXX We require a reference that explains
157 * that these bytes need to match, or should
158 * drop the check. gdt@NetBSD has observed
159 * filesystems that work fine under Windows XP
160 * and NetBSD that do not match, so the
161 * requirement is suspect. For now, just
162 * print out useful information and continue.
163 */
164 pfatal("backup (block %d) mismatch with primary bootblock:\n",
165 boot->bpbBackup);
166 for (i = 11; i < 11 + 90; i++) {
167 if (block[i] != backup[i])
168 pfatal("\ti=%d\tprimary 0x%02x\tbackup 0x%02x\n",
169 i, block[i], backup[i]);
170 }
171 }
172 /* Check backup bpbFSInfo? XXX */
173 }
174
175 boot->ClusterOffset = (boot->bpbRootDirEnts * 32 + boot->bpbBytesPerSec - 1)
176 / boot->bpbBytesPerSec
177 + boot->bpbResSectors
178 + boot->bpbFATs * boot->FATsecs
179 - CLUST_FIRST * boot->bpbSecPerClust;
180
181 if (boot->bpbBytesPerSec % DOSBOOTBLOCKSIZE != 0) {
182 pfatal("Invalid sector size: %u", boot->bpbBytesPerSec);
183 return FSFATAL;
184 }
185 if (boot->bpbSecPerClust == 0) {
186 pfatal("Invalid cluster size: %u", boot->bpbSecPerClust);
187 return FSFATAL;
188 }
189 if (boot->bpbSectors) {
190 boot->bpbHugeSectors = 0;
191 boot->NumSectors = boot->bpbSectors;
192 } else
193 boot->NumSectors = boot->bpbHugeSectors;
194 boot->NumClusters = (boot->NumSectors - boot->ClusterOffset) / boot->bpbSecPerClust;
195
196 if (boot->flags&FAT32)
197 boot->ClustMask = CLUST32_MASK;
198 else if (boot->NumClusters < (CLUST_RSRVD&CLUST12_MASK))
199 boot->ClustMask = CLUST12_MASK;
200 else if (boot->NumClusters < (CLUST_RSRVD&CLUST16_MASK))
201 boot->ClustMask = CLUST16_MASK;
202 else {
203 pfatal("Filesystem too big (%u clusters) for non-FAT32 partition",
204 boot->NumClusters);
205 return FSFATAL;
206 }
207
208 switch (boot->ClustMask) {
209 case CLUST32_MASK:
210 boot->NumFatEntries = (boot->FATsecs * boot->bpbBytesPerSec) / 4;
211 break;
212 case CLUST16_MASK:
213 boot->NumFatEntries = (boot->FATsecs * boot->bpbBytesPerSec) / 2;
214 break;
215 default:
216 boot->NumFatEntries = (boot->FATsecs * boot->bpbBytesPerSec * 2) / 3;
217 break;
218 }
219
220 if (boot->NumFatEntries < boot->NumClusters) {
221 pfatal("FAT size too small, %u entries won't fit into %u sectors\n",
222 boot->NumClusters, boot->FATsecs);
223 return FSFATAL;
224 }
225 boot->ClusterSize = boot->bpbBytesPerSec * boot->bpbSecPerClust;
226
227 boot->NumFiles = 1;
228 boot->NumFree = 0;
229
230 return ret;
231}
232
233int
234writefsinfo(int dosfs, struct bootblock *boot)
235{
236 u_char fsinfo[2 * DOSBOOTBLOCKSIZE];
237
238 if (lseek(dosfs, boot->bpbFSInfo * boot->bpbBytesPerSec, SEEK_SET)
239 != boot->bpbFSInfo * boot->bpbBytesPerSec
240 || read(dosfs, fsinfo, sizeof fsinfo) != sizeof fsinfo) {
241 perror("could not read fsinfo block");
242 return FSFATAL;
243 }
244 fsinfo[0x1e8] = (u_char)boot->FSFree;
245 fsinfo[0x1e9] = (u_char)(boot->FSFree >> 8);
246 fsinfo[0x1ea] = (u_char)(boot->FSFree >> 16);
247 fsinfo[0x1eb] = (u_char)(boot->FSFree >> 24);
248 fsinfo[0x1ec] = (u_char)boot->FSNext;
249 fsinfo[0x1ed] = (u_char)(boot->FSNext >> 8);
250 fsinfo[0x1ee] = (u_char)(boot->FSNext >> 16);
251 fsinfo[0x1ef] = (u_char)(boot->FSNext >> 24);
252 if (lseek(dosfs, boot->bpbFSInfo * boot->bpbBytesPerSec, SEEK_SET)
253 != boot->bpbFSInfo * boot->bpbBytesPerSec
254 || write(dosfs, fsinfo, sizeof fsinfo)
255 != sizeof fsinfo) {
256 perror("Unable to write bpbFSInfo");
257 return FSFATAL;
258 }
259 /*
260 * Technically, we should return FSBOOTMOD here.
261 *
262 * However, since Win95 OSR2 (the first M$ OS that has
263 * support for FAT32) doesn't maintain the FSINFO block
264 * correctly, it has to be fixed pretty often.
265 *
266 * Therefor, we handle the FSINFO block only informally,
267 * fixing it if necessary, but otherwise ignoring the
268 * fact that it was incorrect.
269 */
270 return 0;
271}
2 * Copyright (C) 1995, 1997 Wolfgang Solfrank
3 * Copyright (c) 1995 Martin Husemann
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26
27#include <sys/cdefs.h>
28#ifndef lint
29__RCSID("$NetBSD: boot.c,v 1.9 2003/07/24 19:25:46 ws Exp $");
30static const char rcsid[] =
31 "$FreeBSD: head/sbin/fsck_msdosfs/boot.c 203874 2010-02-14 12:31:28Z kib $";
32#endif /* not lint */
33
34#include <stdlib.h>
35#include <string.h>
36#include <stdio.h>
37#include <unistd.h>
38
39#include "ext.h"
40#include "fsutil.h"
41
42int
43readboot(int dosfs, struct bootblock *boot)
44{
45 u_char block[DOSBOOTBLOCKSIZE];
46 u_char fsinfo[2 * DOSBOOTBLOCKSIZE];
47 u_char backup[DOSBOOTBLOCKSIZE];
48 int ret = FSOK;
49 int i;
50
51 if ((size_t)read(dosfs, block, sizeof block) != sizeof block) {
52 perror("could not read boot block");
53 return FSFATAL;
54 }
55
56 if (block[510] != 0x55 || block[511] != 0xaa) {
57 pfatal("Invalid signature in boot block: %02x%02x", block[511], block[510]);
58 return FSFATAL;
59 }
60
61 memset(boot, 0, sizeof *boot);
62 boot->ValidFat = -1;
63
64 /* decode bios parameter block */
65 boot->bpbBytesPerSec = block[11] + (block[12] << 8);
66 boot->bpbSecPerClust = block[13];
67 boot->bpbResSectors = block[14] + (block[15] << 8);
68 boot->bpbFATs = block[16];
69 boot->bpbRootDirEnts = block[17] + (block[18] << 8);
70 boot->bpbSectors = block[19] + (block[20] << 8);
71 boot->bpbMedia = block[21];
72 boot->bpbFATsmall = block[22] + (block[23] << 8);
73 boot->SecPerTrack = block[24] + (block[25] << 8);
74 boot->bpbHeads = block[26] + (block[27] << 8);
75 boot->bpbHiddenSecs = block[28] + (block[29] << 8) + (block[30] << 16) + (block[31] << 24);
76 boot->bpbHugeSectors = block[32] + (block[33] << 8) + (block[34] << 16) + (block[35] << 24);
77
78 boot->FATsecs = boot->bpbFATsmall;
79
80 if (!boot->bpbRootDirEnts)
81 boot->flags |= FAT32;
82 if (boot->flags & FAT32) {
83 boot->FATsecs = block[36] + (block[37] << 8)
84 + (block[38] << 16) + (block[39] << 24);
85 if (block[40] & 0x80)
86 boot->ValidFat = block[40] & 0x0f;
87
88 /* check version number: */
89 if (block[42] || block[43]) {
90 /* Correct? XXX */
91 pfatal("Unknown file system version: %x.%x",
92 block[43], block[42]);
93 return FSFATAL;
94 }
95 boot->bpbRootClust = block[44] + (block[45] << 8)
96 + (block[46] << 16) + (block[47] << 24);
97 boot->bpbFSInfo = block[48] + (block[49] << 8);
98 boot->bpbBackup = block[50] + (block[51] << 8);
99
100 if (lseek(dosfs, boot->bpbFSInfo * boot->bpbBytesPerSec, SEEK_SET)
101 != boot->bpbFSInfo * boot->bpbBytesPerSec
102 || read(dosfs, fsinfo, sizeof fsinfo)
103 != sizeof fsinfo) {
104 perror("could not read fsinfo block");
105 return FSFATAL;
106 }
107 if (memcmp(fsinfo, "RRaA", 4)
108 || memcmp(fsinfo + 0x1e4, "rrAa", 4)
109 || fsinfo[0x1fc]
110 || fsinfo[0x1fd]
111 || fsinfo[0x1fe] != 0x55
112 || fsinfo[0x1ff] != 0xaa
113 || fsinfo[0x3fc]
114 || fsinfo[0x3fd]
115 || fsinfo[0x3fe] != 0x55
116 || fsinfo[0x3ff] != 0xaa) {
117 pwarn("Invalid signature in fsinfo block\n");
118 if (ask(0, "Fix")) {
119 memcpy(fsinfo, "RRaA", 4);
120 memcpy(fsinfo + 0x1e4, "rrAa", 4);
121 fsinfo[0x1fc] = fsinfo[0x1fd] = 0;
122 fsinfo[0x1fe] = 0x55;
123 fsinfo[0x1ff] = 0xaa;
124 fsinfo[0x3fc] = fsinfo[0x3fd] = 0;
125 fsinfo[0x3fe] = 0x55;
126 fsinfo[0x3ff] = 0xaa;
127 if (lseek(dosfs, boot->bpbFSInfo * boot->bpbBytesPerSec, SEEK_SET)
128 != boot->bpbFSInfo * boot->bpbBytesPerSec
129 || write(dosfs, fsinfo, sizeof fsinfo)
130 != sizeof fsinfo) {
131 perror("Unable to write bpbFSInfo");
132 return FSFATAL;
133 }
134 ret = FSBOOTMOD;
135 } else
136 boot->bpbFSInfo = 0;
137 }
138 if (boot->bpbFSInfo) {
139 boot->FSFree = fsinfo[0x1e8] + (fsinfo[0x1e9] << 8)
140 + (fsinfo[0x1ea] << 16)
141 + (fsinfo[0x1eb] << 24);
142 boot->FSNext = fsinfo[0x1ec] + (fsinfo[0x1ed] << 8)
143 + (fsinfo[0x1ee] << 16)
144 + (fsinfo[0x1ef] << 24);
145 }
146
147 if (lseek(dosfs, boot->bpbBackup * boot->bpbBytesPerSec, SEEK_SET)
148 != boot->bpbBackup * boot->bpbBytesPerSec
149 || read(dosfs, backup, sizeof backup) != sizeof backup) {
150 perror("could not read backup bootblock");
151 return FSFATAL;
152 }
153 backup[65] = block[65]; /* XXX */
154 if (memcmp(block + 11, backup + 11, 79)) {
155 /*
156 * XXX We require a reference that explains
157 * that these bytes need to match, or should
158 * drop the check. gdt@NetBSD has observed
159 * filesystems that work fine under Windows XP
160 * and NetBSD that do not match, so the
161 * requirement is suspect. For now, just
162 * print out useful information and continue.
163 */
164 pfatal("backup (block %d) mismatch with primary bootblock:\n",
165 boot->bpbBackup);
166 for (i = 11; i < 11 + 90; i++) {
167 if (block[i] != backup[i])
168 pfatal("\ti=%d\tprimary 0x%02x\tbackup 0x%02x\n",
169 i, block[i], backup[i]);
170 }
171 }
172 /* Check backup bpbFSInfo? XXX */
173 }
174
175 boot->ClusterOffset = (boot->bpbRootDirEnts * 32 + boot->bpbBytesPerSec - 1)
176 / boot->bpbBytesPerSec
177 + boot->bpbResSectors
178 + boot->bpbFATs * boot->FATsecs
179 - CLUST_FIRST * boot->bpbSecPerClust;
180
181 if (boot->bpbBytesPerSec % DOSBOOTBLOCKSIZE != 0) {
182 pfatal("Invalid sector size: %u", boot->bpbBytesPerSec);
183 return FSFATAL;
184 }
185 if (boot->bpbSecPerClust == 0) {
186 pfatal("Invalid cluster size: %u", boot->bpbSecPerClust);
187 return FSFATAL;
188 }
189 if (boot->bpbSectors) {
190 boot->bpbHugeSectors = 0;
191 boot->NumSectors = boot->bpbSectors;
192 } else
193 boot->NumSectors = boot->bpbHugeSectors;
194 boot->NumClusters = (boot->NumSectors - boot->ClusterOffset) / boot->bpbSecPerClust;
195
196 if (boot->flags&FAT32)
197 boot->ClustMask = CLUST32_MASK;
198 else if (boot->NumClusters < (CLUST_RSRVD&CLUST12_MASK))
199 boot->ClustMask = CLUST12_MASK;
200 else if (boot->NumClusters < (CLUST_RSRVD&CLUST16_MASK))
201 boot->ClustMask = CLUST16_MASK;
202 else {
203 pfatal("Filesystem too big (%u clusters) for non-FAT32 partition",
204 boot->NumClusters);
205 return FSFATAL;
206 }
207
208 switch (boot->ClustMask) {
209 case CLUST32_MASK:
210 boot->NumFatEntries = (boot->FATsecs * boot->bpbBytesPerSec) / 4;
211 break;
212 case CLUST16_MASK:
213 boot->NumFatEntries = (boot->FATsecs * boot->bpbBytesPerSec) / 2;
214 break;
215 default:
216 boot->NumFatEntries = (boot->FATsecs * boot->bpbBytesPerSec * 2) / 3;
217 break;
218 }
219
220 if (boot->NumFatEntries < boot->NumClusters) {
221 pfatal("FAT size too small, %u entries won't fit into %u sectors\n",
222 boot->NumClusters, boot->FATsecs);
223 return FSFATAL;
224 }
225 boot->ClusterSize = boot->bpbBytesPerSec * boot->bpbSecPerClust;
226
227 boot->NumFiles = 1;
228 boot->NumFree = 0;
229
230 return ret;
231}
232
233int
234writefsinfo(int dosfs, struct bootblock *boot)
235{
236 u_char fsinfo[2 * DOSBOOTBLOCKSIZE];
237
238 if (lseek(dosfs, boot->bpbFSInfo * boot->bpbBytesPerSec, SEEK_SET)
239 != boot->bpbFSInfo * boot->bpbBytesPerSec
240 || read(dosfs, fsinfo, sizeof fsinfo) != sizeof fsinfo) {
241 perror("could not read fsinfo block");
242 return FSFATAL;
243 }
244 fsinfo[0x1e8] = (u_char)boot->FSFree;
245 fsinfo[0x1e9] = (u_char)(boot->FSFree >> 8);
246 fsinfo[0x1ea] = (u_char)(boot->FSFree >> 16);
247 fsinfo[0x1eb] = (u_char)(boot->FSFree >> 24);
248 fsinfo[0x1ec] = (u_char)boot->FSNext;
249 fsinfo[0x1ed] = (u_char)(boot->FSNext >> 8);
250 fsinfo[0x1ee] = (u_char)(boot->FSNext >> 16);
251 fsinfo[0x1ef] = (u_char)(boot->FSNext >> 24);
252 if (lseek(dosfs, boot->bpbFSInfo * boot->bpbBytesPerSec, SEEK_SET)
253 != boot->bpbFSInfo * boot->bpbBytesPerSec
254 || write(dosfs, fsinfo, sizeof fsinfo)
255 != sizeof fsinfo) {
256 perror("Unable to write bpbFSInfo");
257 return FSFATAL;
258 }
259 /*
260 * Technically, we should return FSBOOTMOD here.
261 *
262 * However, since Win95 OSR2 (the first M$ OS that has
263 * support for FAT32) doesn't maintain the FSINFO block
264 * correctly, it has to be fixed pretty often.
265 *
266 * Therefor, we handle the FSINFO block only informally,
267 * fixing it if necessary, but otherwise ignoring the
268 * fact that it was incorrect.
269 */
270 return 0;
271}