| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: fat.c,v 1.23 2012/08/07 19:30:41 jakllsch Exp $ */ | | 1 | /* $NetBSD: fat.c,v 1.24 2013/01/17 16:45:48 jakllsch Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank | | 4 | * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank |
5 | * Copyright (c) 1995 Martin Husemann | | 5 | * Copyright (c) 1995 Martin Husemann |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -18,27 +18,27 @@ | | | @@ -18,27 +18,27 @@ |
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, | | 19 | * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | | 26 | */ |
27 | | | 27 | |
28 | | | 28 | |
29 | #include <sys/cdefs.h> | | 29 | #include <sys/cdefs.h> |
30 | #ifndef lint | | 30 | #ifndef lint |
31 | __RCSID("$NetBSD: fat.c,v 1.23 2012/08/07 19:30:41 jakllsch Exp $"); | | 31 | __RCSID("$NetBSD: fat.c,v 1.24 2013/01/17 16:45:48 jakllsch Exp $"); |
32 | #endif /* not lint */ | | 32 | #endif /* not lint */ |
33 | | | 33 | |
34 | #include <stdlib.h> | | 34 | #include <stdlib.h> |
35 | #include <string.h> | | 35 | #include <string.h> |
36 | #include <ctype.h> | | 36 | #include <ctype.h> |
37 | #include <stdio.h> | | 37 | #include <stdio.h> |
38 | #include <unistd.h> | | 38 | #include <unistd.h> |
39 | | | 39 | |
40 | #include "ext.h" | | 40 | #include "ext.h" |
41 | #include "fsutil.h" | | 41 | #include "fsutil.h" |
42 | | | 42 | |
43 | static int checkclnum(struct bootblock *, u_int, cl_t, cl_t *); | | 43 | static int checkclnum(struct bootblock *, u_int, cl_t, cl_t *); |
44 | static int clustdiffer(cl_t, cl_t *, cl_t *, u_int); | | 44 | static int clustdiffer(cl_t, cl_t *, cl_t *, u_int); |
| @@ -595,27 +595,29 @@ checklost(int dosfs, struct bootblock *b | | | @@ -595,27 +595,29 @@ checklost(int dosfs, struct bootblock *b |
595 | finishlf(); | | 595 | finishlf(); |
596 | | | 596 | |
597 | if (boot->FSInfo) { | | 597 | if (boot->FSInfo) { |
598 | ret = 0; | | 598 | ret = 0; |
599 | if (boot->FSFree != 0xffffffffU && | | 599 | if (boot->FSFree != 0xffffffffU && |
600 | boot->FSFree != boot->NumFree) { | | 600 | boot->FSFree != boot->NumFree) { |
601 | pwarn("Free space in FSInfo block (%u) not correct (%u)\n", | | 601 | pwarn("Free space in FSInfo block (%u) not correct (%u)\n", |
602 | boot->FSFree, boot->NumFree); | | 602 | boot->FSFree, boot->NumFree); |
603 | if (ask(1, "fix")) { | | 603 | if (ask(1, "fix")) { |
604 | boot->FSFree = boot->NumFree; | | 604 | boot->FSFree = boot->NumFree; |
605 | ret = 1; | | 605 | ret = 1; |
606 | } | | 606 | } |
607 | } | | 607 | } |
608 | if (boot->FSNext >= boot->NumClusters || (boot->NumFree && fat[boot->FSNext].next != CLUST_FREE)) { | | 608 | if (boot->FSNext != 0xffffffffU && |
| | | 609 | (boot->FSNext >= boot->NumClusters || |
| | | 610 | (boot->NumFree && fat[boot->FSNext].next != CLUST_FREE))) { |
609 | pwarn("Next free cluster in FSInfo block (%u) %s\n", | | 611 | pwarn("Next free cluster in FSInfo block (%u) %s\n", |
610 | boot->FSNext, | | 612 | boot->FSNext, |
611 | (boot->FSNext >= boot->NumClusters) ? "invalid" : "not free"); | | 613 | (boot->FSNext >= boot->NumClusters) ? "invalid" : "not free"); |
612 | if (ask(1, "fix")) | | 614 | if (ask(1, "fix")) |
613 | for (head = CLUST_FIRST; head < boot->NumClusters; head++) | | 615 | for (head = CLUST_FIRST; head < boot->NumClusters; head++) |
614 | if (fat[head].next == CLUST_FREE) { | | 616 | if (fat[head].next == CLUST_FREE) { |
615 | boot->FSNext = head; | | 617 | boot->FSNext = head; |
616 | ret = 1; | | 618 | ret = 1; |
617 | break; | | 619 | break; |
618 | } | | 620 | } |
619 | } | | 621 | } |
620 | if (ret) | | 622 | if (ret) |
621 | mod |= writefsinfo(dosfs, boot); | | 623 | mod |= writefsinfo(dosfs, boot); |