1/*
2 * Copyright (C) 1995, 1996, 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 <stdlib.h>
28#include <string.h>
29#include <ctype.h>
30#include <stdio.h>
31#include <unistd.h>
32
33#include "ext.h"
34
35static int checkclnum(struct bootblock *, u_int, cl_t, cl_t *);
36static int clustdiffer(cl_t, cl_t *, cl_t *, u_int);
37static int tryclear(struct bootblock *, struct fatEntry *, cl_t, cl_t *);
38static int _readfat(int, struct bootblock *, u_int, u_char **);
39
40/*-
41 * The first 2 FAT entries contain pseudo-cluster numbers with the following
42 * layout:
43 *
44 * 31...... ........ ........ .......0
45 * rrrr1111 11111111 11111111 mmmmmmmm         FAT32 entry 0
46 * rrrrsh11 11111111 11111111 11111xxx         FAT32 entry 1
47 *
48 *                   11111111 mmmmmmmm         FAT16 entry 0
49 *                   sh111111 11111xxx         FAT16 entry 1
50 *
51 * r = reserved
52 * m = BPB media ID byte
53 * s = clean flag (1 = dismounted; 0 = still mounted)
54 * h = hard error flag (1 = ok; 0 = I/O error)
55 * x = any value ok
56 */
57
58int
59checkdirty(int fs, struct bootblock *boot)
60{
61	off_t off;
62	u_char *buffer;
63	int ret = 0;
64	size_t len;
65
66	if (boot->ClustMask != CLUST16_MASK && boot->ClustMask != CLUST32_MASK)
67		return 0;
68
69	off = boot->bpbResSectors;
70	off *= boot->bpbBytesPerSec;
71
72	buffer = malloc(len = boot->bpbBytesPerSec);
73	if (buffer == NULL) {
74		perr("No space for FAT sectors (%zu)", len);
75		return 1;
76	}
77
78	if (lseek(fs, off, SEEK_SET) != off) {
79		perr("Unable to read FAT");
80		goto err;
81	}
82
83	if ((size_t)read(fs, buffer, boot->bpbBytesPerSec) !=
84	    boot->bpbBytesPerSec) {
85		perr("Unable to read FAT");
86		goto err;
87	}
88
89	/*
90	 * If we don't understand the FAT, then the file system must be
91	 * assumed to be unclean.
92	 */
93	if (buffer[0] != boot->bpbMedia || buffer[1] != 0xff)
94		goto err;
95	if (boot->ClustMask == CLUST16_MASK) {
96		if ((buffer[2] & 0xf8) != 0xf8 || (buffer[3] & 0x3f) != 0x3f)
97			goto err;
98	} else {
99		if (buffer[2] != 0xff || (buffer[3] & 0x0f) != 0x0f
100		    || (buffer[4] & 0xf8) != 0xf8 || buffer[5] != 0xff
101		    || buffer[6] != 0xff || (buffer[7] & 0x03) != 0x03)
102			goto err;
103	}
104
105	/*
106	 * Now check the actual clean flag (and the no-error flag).
107	 */
108	if (boot->ClustMask == CLUST16_MASK) {
109		if ((buffer[3] & 0xc0) == 0xc0)
110			ret = 1;
111	} else {
112		if ((buffer[7] & 0x0c) == 0x0c)
113			ret = 1;
114	}
115
116err:
117	free(buffer);
118	return ret;
119}
120
121/*
122 * Check a cluster number for valid value
123 */
124static int
125checkclnum(struct bootblock *boot, u_int fat, cl_t cl, cl_t *next)
126{
127	if (*next >= (CLUST_RSRVD&boot->ClustMask))
128		*next |= ~boot->ClustMask;
129	if (*next == CLUST_FREE) {
130		boot->NumFree++;
131		return FSOK;
132	}
133	if (*next == CLUST_BAD) {
134		boot->NumBad++;
135		return FSOK;
136	}
137	if (*next < CLUST_FIRST
138	    || (*next >= boot->NumClusters && *next < CLUST_EOFS)) {
139		pwarn("Cluster %u in FAT %d continues with %s cluster number %u\n",
140		      cl, fat,
141		      *next < CLUST_RSRVD ? "out of range" : "reserved",
142		      *next&boot->ClustMask);
143		if (ask(0, "Truncate")) {
144			*next = CLUST_EOF;
145			return FSFATMOD;
146		}
147		return FSERROR;
148	}
149	return FSOK;
150}
151
152/*
153 * Read a FAT from disk. Returns 1 if successful, 0 otherwise.
154 */
155static int
156_readfat(int fs, struct bootblock *boot, u_int no, u_char **buffer)
157{
158	off_t off;
159	size_t len;
160
161	*buffer = malloc(len = boot->FATsecs * boot->bpbBytesPerSec);
162	if (*buffer == NULL) {
163		perr("No space for FAT sectors (%zu)", len);
164		return 0;
165	}
166
167	off = boot->bpbResSectors + no * boot->FATsecs;
168	off *= boot->bpbBytesPerSec;
169
170	if (lseek(fs, off, SEEK_SET) != off) {
171		perr("Unable to read FAT");
172		goto err;
173	}
174
175	if ((size_t)read(fs, *buffer, boot->FATsecs * boot->bpbBytesPerSec)
176	    != boot->FATsecs * boot->bpbBytesPerSec) {
177		perr("Unable to read FAT");
178		goto err;
179	}
180
181	return 1;
182
183    err:
184	free(*buffer);
185	return 0;
186}
187
188/*
189 * Read a FAT and decode it into internal format
190 */
191int
192readfat(int fs, struct bootblock *boot, u_int no, struct fatEntry **fp)
193{
194	struct fatEntry *fat;
195	u_char *buffer, *p;
196	cl_t cl;
197	int ret = FSOK;
198	size_t len;
199
200	boot->NumFree = boot->NumBad = 0;
201
202	if (!_readfat(fs, boot, no, &buffer))
203		return FSFATAL;
204
205	fat = malloc(len = boot->NumClusters * sizeof(struct fatEntry));
206	if (fat == NULL) {
207		perr("No space for FAT clusters (%zu)", len);
208		free(buffer);
209		return FSFATAL;
210	}
211	(void)memset(fat, 0, len);
212
213	if (buffer[0] != boot->bpbMedia
214	    || buffer[1] != 0xff || buffer[2] != 0xff
215	    || (boot->ClustMask == CLUST16_MASK && buffer[3] != 0xff)
216	    || (boot->ClustMask == CLUST32_MASK
217		&& ((buffer[3]&0x0f) != 0x0f
218		    || buffer[4] != 0xff || buffer[5] != 0xff
219		    || buffer[6] != 0xff || (buffer[7]&0x0f) != 0x0f))) {
220
221		/* Windows 95 OSR2 (and possibly any later) changes
222		 * the FAT signature to 0xXXffff7f for FAT16 and to
223		 * 0xXXffff0fffffff07 for FAT32 upon boot, to know that the
224		 * file system is dirty if it doesn't reboot cleanly.
225		 * Check this special condition before errorring out.
226		 */
227		if (buffer[0] == boot->bpbMedia && buffer[1] == 0xff
228		    && buffer[2] == 0xff
229		    && ((boot->ClustMask == CLUST16_MASK && buffer[3] == 0x7f)
230			|| (boot->ClustMask == CLUST32_MASK
231			    && buffer[3] == 0x0f && buffer[4] == 0xff
232			    && buffer[5] == 0xff && buffer[6] == 0xff
233			    && buffer[7] == 0x07)))
234			ret |= FSDIRTY;
235		else {
236			/* just some odd byte sequence in FAT */
237
238			switch (boot->ClustMask) {
239			case CLUST32_MASK:
240				pwarn("%s (%02x%02x%02x%02x%02x%02x%02x%02x)\n",
241				      "FAT starts with odd byte sequence",
242				      buffer[0], buffer[1], buffer[2], buffer[3],
243				      buffer[4], buffer[5], buffer[6], buffer[7]);
244				break;
245			case CLUST16_MASK:
246				pwarn("%s (%02x%02x%02x%02x)\n",
247				    "FAT starts with odd byte sequence",
248				    buffer[0], buffer[1], buffer[2], buffer[3]);
249				break;
250			default:
251				pwarn("%s (%02x%02x%02x)\n",
252				    "FAT starts with odd byte sequence",
253				    buffer[0], buffer[1], buffer[2]);
254				break;
255			}
256
257
258			if (ask(1, "Correct"))
259				ret |= FSFIXFAT;
260		}
261	}
262	switch (boot->ClustMask) {
263	case CLUST32_MASK:
264		p = buffer + 8;
265		break;
266	case CLUST16_MASK:
267		p = buffer + 4;
268		break;
269	default:
270		p = buffer + 3;
271		break;
272	}
273	for (cl = CLUST_FIRST; cl < boot->NumClusters;) {
274		switch (boot->ClustMask) {
275		case CLUST32_MASK:
276			fat[cl].next = p[0] + (p[1] << 8)
277				       + (p[2] << 16) + (p[3] << 24);
278			fat[cl].next &= boot->ClustMask;
279			ret |= checkclnum(boot, no, cl, &fat[cl].next);
280			cl++;
281			p += 4;
282			break;
283		case CLUST16_MASK:
284			fat[cl].next = p[0] + (p[1] << 8);
285			ret |= checkclnum(boot, no, cl, &fat[cl].next);
286			cl++;
287			p += 2;
288			break;
289		default:
290			fat[cl].next = (p[0] + (p[1] << 8)) & 0x0fff;
291			ret |= checkclnum(boot, no, cl, &fat[cl].next);
292			cl++;
293			if (cl >= boot->NumClusters)
294				break;
295			fat[cl].next = ((p[1] >> 4) + (p[2] << 4)) & 0x0fff;
296			ret |= checkclnum(boot, no, cl, &fat[cl].next);
297			cl++;
298			p += 3;
299			break;
300		}
301	}
302
303	free(buffer);
304	if (ret & FSFATAL) {
305		free(fat);
306		*fp = NULL;
307	} else
308		*fp = fat;
309	return ret;
310}
311
312/*
313 * Get type of reserved cluster
314 */
315const char *
316rsrvdcltype(cl_t cl)
317{
318	if (cl == CLUST_FREE)
319		return "free";
320	if (cl < CLUST_BAD)
321		return "reserved";
322	if (cl > CLUST_BAD)
323		return "as EOF";
324	return "bad";
325}
326
327static int
328clustdiffer(cl_t cl, cl_t *cp1, cl_t *cp2, u_int fatnum)
329{
330	if (*cp1 == CLUST_FREE || *cp1 >= CLUST_RSRVD) {
331		if (*cp2 == CLUST_FREE || *cp2 >= CLUST_RSRVD) {
332			if ((*cp1 != CLUST_FREE && *cp1 < CLUST_BAD
333			     && *cp2 != CLUST_FREE && *cp2 < CLUST_BAD)
334			    || (*cp1 > CLUST_BAD && *cp2 > CLUST_BAD)) {
335				pwarn("Cluster %u is marked %s with different indicators\n",
336				      cl, rsrvdcltype(*cp1));
337				if (ask(1, "Fix")) {
338					*cp2 = *cp1;
339					return FSFATMOD;
340				}
341				return FSFATAL;
342			}
343			pwarn("Cluster %u is marked %s in FAT 0, %s in FAT %u\n",
344			      cl, rsrvdcltype(*cp1), rsrvdcltype(*cp2), fatnum);
345			if (ask(0, "Use FAT 0's entry")) {
346				*cp2 = *cp1;
347				return FSFATMOD;
348			}
349			if (ask(0, "Use FAT %u's entry", fatnum)) {
350				*cp1 = *cp2;
351				return FSFATMOD;
352			}
353			return FSFATAL;
354		}
355		pwarn("Cluster %u is marked %s in FAT 0, but continues with cluster %u in FAT %d\n",
356		      cl, rsrvdcltype(*cp1), *cp2, fatnum);
357		if (ask(0, "Use continuation from FAT %u", fatnum)) {
358			*cp1 = *cp2;
359			return FSFATMOD;
360		}
361		if (ask(0, "Use mark from FAT 0")) {
362			*cp2 = *cp1;
363			return FSFATMOD;
364		}
365		return FSFATAL;
366	}
367	if (*cp2 == CLUST_FREE || *cp2 >= CLUST_RSRVD) {
368		pwarn("Cluster %u continues with cluster %u in FAT 0, but is marked %s in FAT %u\n",
369		      cl, *cp1, rsrvdcltype(*cp2), fatnum);
370		if (ask(0, "Use continuation from FAT 0")) {
371			*cp2 = *cp1;
372			return FSFATMOD;
373		}
374		if (ask(0, "Use mark from FAT %d", fatnum)) {
375			*cp1 = *cp2;
376			return FSFATMOD;
377		}
378		return FSERROR;
379	}
380	pwarn("Cluster %u continues with cluster %u in FAT 0, but with cluster %u in FAT %u\n",
381	      cl, *cp1, *cp2, fatnum);
382	if (ask(0, "Use continuation from FAT 0")) {
383		*cp2 = *cp1;
384		return FSFATMOD;
385	}
386	if (ask(0, "Use continuation from FAT %u", fatnum)) {
387		*cp1 = *cp2;
388		return FSFATMOD;
389	}
390	return FSERROR;
391}
392
393/*
394 * Compare two FAT copies in memory. Resolve any conflicts and merge them
395 * into the first one.
396 */
397int
398comparefat(struct bootblock *boot, struct fatEntry *first,
399    struct fatEntry *second, u_int fatnum)
400{
401	cl_t cl;
402	int ret = FSOK;
403
404	for (cl = CLUST_FIRST; cl < boot->NumClusters; cl++)
405		if (first[cl].next != second[cl].next)
406			ret |= clustdiffer(cl, &first[cl].next, &second[cl].next, fatnum);
407	return ret;
408}
409
410void
411clearchain(struct bootblock *boot, struct fatEntry *fat, cl_t head)
412{
413	cl_t p, q;
414
415	for (p = head; p >= CLUST_FIRST && p < boot->NumClusters; p = q) {
416		if (fat[p].head != head)
417			break;
418		q = fat[p].next;
419		fat[p].next = fat[p].head = CLUST_FREE;
420		fat[p].length = 0;
421	}
422}
423
424int
425tryclear(struct bootblock *boot, struct fatEntry *fat, cl_t head, cl_t *truncp)
426{
427	if (ask(0, "Clear chain starting at %u", head)) {
428		clearchain(boot, fat, head);
429		return FSFATMOD;
430	} else if (ask(0, "Truncate")) {
431		uint32_t len;
432		cl_t p;
433
434		for (p = head, len = 0;
435		    p >= CLUST_FIRST && p < boot->NumClusters;
436		    p = fat[p].next, len++)
437			continue;
438		*truncp = CLUST_EOF;
439		fat[head].length = len;
440		return FSFATMOD;
441	} else
442		return FSERROR;
443}
444
445/*
446 * Check a complete FAT in-memory for crosslinks
447 */
448int
449checkfat(struct bootblock *boot, struct fatEntry *fat)
450{
451	cl_t head, p, h, n;
452	u_int len;
453	int ret = 0;
454	int conf;
455
456	/*
457	 * pass 1: figure out the cluster chains.
458	 */
459	for (head = CLUST_FIRST; head < boot->NumClusters; head++) {
460		/* find next untravelled chain */
461		if (fat[head].head != 0		/* cluster already belongs to some chain */
462		    || fat[head].next == CLUST_FREE
463		    || fat[head].next == CLUST_BAD)
464			continue;		/* skip it. */
465
466		/* follow the chain and mark all clusters on the way */
467		for (len = 0, p = head;
468		     p >= CLUST_FIRST && p < boot->NumClusters &&
469		     fat[p].head != head;
470		     p = fat[p].next) {
471			fat[p].head = head;
472			len++;
473		}
474
475		/* the head record gets the length */
476		fat[head].length = fat[head].next == CLUST_FREE ? 0 : len;
477	}
478
479	/*
480	 * pass 2: check for crosslinked chains (we couldn't do this in pass 1 because
481	 * we didn't know the real start of the chain then - would have treated partial
482	 * chains as interlinked with their main chain)
483	 */
484	for (head = CLUST_FIRST; head < boot->NumClusters; head++) {
485		/* find next untravelled chain */
486		if (fat[head].head != head)
487			continue;
488
489		/* follow the chain to its end (hopefully) */
490		for (len = fat[head].length, p = head;
491		     (n = fat[p].next) >= CLUST_FIRST && n < boot->NumClusters;
492		     p = n)
493			if (fat[n].head != head || len-- < 2)
494				break;
495		if (n >= CLUST_EOFS)
496			continue;
497
498		if (n == CLUST_FREE || n >= CLUST_RSRVD) {
499			pwarn("Cluster chain starting at %u ends with cluster marked %s\n",
500			      head, rsrvdcltype(n));
501clear:
502			ret |= tryclear(boot, fat, head, &fat[p].next);
503			continue;
504		}
505		if (n < CLUST_FIRST || n >= boot->NumClusters) {
506			pwarn("Cluster chain starting at %u ends with cluster out of range (%u)\n",
507			    head, n);
508			goto clear;
509		}
510		if (head == fat[n].head) {
511			pwarn("Cluster chain starting at %u loops at cluster %u\n",
512
513			    head, p);
514			goto clear;
515		}
516		pwarn("Cluster chains starting at %u and %u are linked at cluster %u\n",
517		      head, fat[n].head, n);
518		conf = tryclear(boot, fat, head, &fat[p].next);
519		if (ask(0, "Clear chain starting at %u", h = fat[n].head)) {
520			if (conf == FSERROR) {
521				/*
522				 * Transfer the common chain to the one not cleared above.
523				 */
524				for (p = n;
525				     p >= CLUST_FIRST && p < boot->NumClusters;
526				     p = fat[p].next) {
527					if (h != fat[p].head) {
528						/*
529						 * Have to reexamine this chain.
530						 */
531						head--;
532						break;
533					}
534					fat[p].head = head;
535				}
536			}
537			clearchain(boot, fat, h);
538			conf |= FSFATMOD;
539		}
540		ret |= conf;
541	}
542
543	return ret;
544}
545
546/*
547 * Write out FATs encoding them from the internal format
548 */
549int
550writefat(int fs, struct bootblock *boot, struct fatEntry *fat, int correct_fat)
551{
552	u_char *buffer, *p;
553	cl_t cl;
554	u_int i;
555	size_t fatsz;
556	off_t off;
557	int ret = FSOK;
558
559	buffer = malloc(fatsz = boot->FATsecs * boot->bpbBytesPerSec);
560	if (buffer == NULL) {
561		perr("No space for FAT sectors (%zu)", fatsz);
562		return FSFATAL;
563	}
564	memset(buffer, 0, fatsz);
565	boot->NumFree = 0;
566	p = buffer;
567	if (correct_fat) {
568		*p++ = (u_char)boot->bpbMedia;
569		*p++ = 0xff;
570		*p++ = 0xff;
571		switch (boot->ClustMask) {
572		case CLUST16_MASK:
573			*p++ = 0xff;
574			break;
575		case CLUST32_MASK:
576			*p++ = 0x0f;
577			*p++ = 0xff;
578			*p++ = 0xff;
579			*p++ = 0xff;
580			*p++ = 0x0f;
581			break;
582		}
583	} else {
584		/* use same FAT signature as the old FAT has */
585		int count;
586		u_char *old_fat;
587
588		switch (boot->ClustMask) {
589		case CLUST32_MASK:
590			count = 8;
591			break;
592		case CLUST16_MASK:
593			count = 4;
594			break;
595		default:
596			count = 3;
597			break;
598		}
599
600		if (!_readfat(fs, boot, boot->ValidFat >= 0 ? boot->ValidFat :0,
601					 &old_fat)) {
602			free(buffer);
603			return FSFATAL;
604		}
605
606		memcpy(p, old_fat, count);
607		free(old_fat);
608		p += count;
609	}
610
611	for (cl = CLUST_FIRST; cl < boot->NumClusters; cl++) {
612		switch (boot->ClustMask) {
613		case CLUST32_MASK:
614			if (fat[cl].next == CLUST_FREE)
615				boot->NumFree++;
616			*p++ = (u_char)fat[cl].next;
617			*p++ = (u_char)(fat[cl].next >> 8);
618			*p++ = (u_char)(fat[cl].next >> 16);
619			*p &= 0xf0;
620			*p++ |= (fat[cl].next >> 24)&0x0f;
621			break;
622		case CLUST16_MASK:
623			if (fat[cl].next == CLUST_FREE)
624				boot->NumFree++;
625			*p++ = (u_char)fat[cl].next;
626			*p++ = (u_char)(fat[cl].next >> 8);
627			break;
628		default:
629			if (fat[cl].next == CLUST_FREE)
630				boot->NumFree++;
631			*p++ = (u_char)fat[cl].next;
632			*p = (u_char)((fat[cl].next >> 8) & 0xf);
633			cl++;
634			if (cl >= boot->NumClusters)
635				break;
636			if (fat[cl].next == CLUST_FREE)
637				boot->NumFree++;
638			*p++ |= (u_char)(fat[cl + 1].next << 4);
639			*p++ = (u_char)(fat[cl + 1].next >> 4);
640			break;
641		}
642	}
643	for (i = 0; i < boot->bpbFATs; i++) {
644		off = boot->bpbResSectors + i * boot->FATsecs;
645		off *= boot->bpbBytesPerSec;
646		if (lseek(fs, off, SEEK_SET) != off
647		    || (size_t)write(fs, buffer, fatsz) != fatsz) {
648			perr("Unable to write FAT");
649			ret = FSFATAL; /* Return immediately?		XXX */
650		}
651	}
652	free(buffer);
653	return ret;
654}
655
656/*
657 * Check a complete in-memory FAT for lost cluster chains
658 */
659int
660checklost(int dosfs, struct bootblock *boot, struct fatEntry *fat)
661{
662	cl_t head;
663	int mod = FSOK;
664	int ret;
665
666	for (head = CLUST_FIRST; head < boot->NumClusters; head++) {
667		/* find next untravelled chain */
668		if (fat[head].head != head
669		    || fat[head].next == CLUST_FREE
670		    || (fat[head].next >= CLUST_RSRVD
671			&& fat[head].next < CLUST_EOFS)
672		    || (fat[head].flags & FAT_USED))
673			continue;
674
675		pwarn("Lost cluster chain at cluster %u\n%d Cluster(s) lost\n",
676		      head, fat[head].length);
677		mod |= ret = reconnect(dosfs, boot, fat, head);
678		if (mod & FSFATAL)
679			break;
680		if (ret == FSERROR && ask(0, "Clear")) {
681			clearchain(boot, fat, head);
682			mod |= FSFATMOD;
683		}
684	}
685	finishlf();
686
687	if (boot->bpbFSInfo) {
688		ret = 0;
689		if (boot->FSFree != 0xffffffffU &&
690		    boot->FSFree != boot->NumFree) {
691			pwarn("Free space in FSInfo block (%u) not correct (%u)\n",
692			      boot->FSFree, boot->NumFree);
693			if (ask(1, "Fix")) {
694				boot->FSFree = boot->NumFree;
695				ret = 1;
696			}
697		}
698		if (ret)
699			mod |= writefsinfo(dosfs, boot);
700	}
701
702	return mod;
703}
704