fat.c (241807) | fat.c (268631) |
---|---|
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 --- 14 unchanged lines hidden (view full) --- 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: fat.c,v 1.18 2006/06/05 16:51:18 christos Exp $"); 30static const char rcsid[] = | 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 --- 14 unchanged lines hidden (view full) --- 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: fat.c,v 1.18 2006/06/05 16:51:18 christos Exp $"); 30static const char rcsid[] = |
31 "$FreeBSD: head/sbin/fsck_msdosfs/fat.c 241807 2012-10-21 12:01:19Z uqs $"; | 31 "$FreeBSD: head/sbin/fsck_msdosfs/fat.c 268631 2014-07-14 20:17:09Z pfg $"; |
32#endif /* not lint */ 33 34#include <stdlib.h> 35#include <string.h> 36#include <ctype.h> 37#include <stdio.h> 38#include <unistd.h> 39 --- 197 unchanged lines hidden (view full) --- 237 && ((boot->ClustMask == CLUST16_MASK && buffer[3] == 0x7f) 238 || (boot->ClustMask == CLUST32_MASK 239 && buffer[3] == 0x0f && buffer[4] == 0xff 240 && buffer[5] == 0xff && buffer[6] == 0xff 241 && buffer[7] == 0x07))) 242 ret |= FSDIRTY; 243 else { 244 /* just some odd byte sequence in FAT */ | 32#endif /* not lint */ 33 34#include <stdlib.h> 35#include <string.h> 36#include <ctype.h> 37#include <stdio.h> 38#include <unistd.h> 39 --- 197 unchanged lines hidden (view full) --- 237 && ((boot->ClustMask == CLUST16_MASK && buffer[3] == 0x7f) 238 || (boot->ClustMask == CLUST32_MASK 239 && buffer[3] == 0x0f && buffer[4] == 0xff 240 && buffer[5] == 0xff && buffer[6] == 0xff 241 && buffer[7] == 0x07))) 242 ret |= FSDIRTY; 243 else { 244 /* just some odd byte sequence in FAT */ |
245 | 245 |
246 switch (boot->ClustMask) { 247 case CLUST32_MASK: 248 pwarn("%s (%02x%02x%02x%02x%02x%02x%02x%02x)\n", 249 "FAT starts with odd byte sequence", 250 buffer[0], buffer[1], buffer[2], buffer[3], 251 buffer[4], buffer[5], buffer[6], buffer[7]); 252 break; 253 case CLUST16_MASK: 254 pwarn("%s (%02x%02x%02x%02x)\n", 255 "FAT starts with odd byte sequence", 256 buffer[0], buffer[1], buffer[2], buffer[3]); 257 break; 258 default: 259 pwarn("%s (%02x%02x%02x)\n", 260 "FAT starts with odd byte sequence", 261 buffer[0], buffer[1], buffer[2]); 262 break; 263 } 264 | 246 switch (boot->ClustMask) { 247 case CLUST32_MASK: 248 pwarn("%s (%02x%02x%02x%02x%02x%02x%02x%02x)\n", 249 "FAT starts with odd byte sequence", 250 buffer[0], buffer[1], buffer[2], buffer[3], 251 buffer[4], buffer[5], buffer[6], buffer[7]); 252 break; 253 case CLUST16_MASK: 254 pwarn("%s (%02x%02x%02x%02x)\n", 255 "FAT starts with odd byte sequence", 256 buffer[0], buffer[1], buffer[2], buffer[3]); 257 break; 258 default: 259 pwarn("%s (%02x%02x%02x)\n", 260 "FAT starts with odd byte sequence", 261 buffer[0], buffer[1], buffer[2]); 262 break; 263 } 264 |
265 | 265 |
266 if (ask(1, "Correct")) 267 ret |= FSFIXFAT; 268 } 269 } 270 switch (boot->ClustMask) { 271 case CLUST32_MASK: 272 p = buffer + 8; 273 break; --- 374 unchanged lines hidden (view full) --- 648 * Check a complete in-memory FAT for lost cluster chains 649 */ 650int 651checklost(int dosfs, struct bootblock *boot, struct fatEntry *fat) 652{ 653 cl_t head; 654 int mod = FSOK; 655 int ret; | 266 if (ask(1, "Correct")) 267 ret |= FSFIXFAT; 268 } 269 } 270 switch (boot->ClustMask) { 271 case CLUST32_MASK: 272 p = buffer + 8; 273 break; --- 374 unchanged lines hidden (view full) --- 648 * Check a complete in-memory FAT for lost cluster chains 649 */ 650int 651checklost(int dosfs, struct bootblock *boot, struct fatEntry *fat) 652{ 653 cl_t head; 654 int mod = FSOK; 655 int ret; |
656 | 656 |
657 for (head = CLUST_FIRST; head < boot->NumClusters; head++) { 658 /* find next untravelled chain */ 659 if (fat[head].head != head 660 || fat[head].next == CLUST_FREE 661 || (fat[head].next >= CLUST_RSRVD 662 && fat[head].next < CLUST_EOFS) 663 || (fat[head].flags & FAT_USED)) 664 continue; --- 7 unchanged lines hidden (view full) --- 672 clearchain(boot, fat, head); 673 mod |= FSFATMOD; 674 } 675 } 676 finishlf(); 677 678 if (boot->bpbFSInfo) { 679 ret = 0; | 657 for (head = CLUST_FIRST; head < boot->NumClusters; head++) { 658 /* find next untravelled chain */ 659 if (fat[head].head != head 660 || fat[head].next == CLUST_FREE 661 || (fat[head].next >= CLUST_RSRVD 662 && fat[head].next < CLUST_EOFS) 663 || (fat[head].flags & FAT_USED)) 664 continue; --- 7 unchanged lines hidden (view full) --- 672 clearchain(boot, fat, head); 673 mod |= FSFATMOD; 674 } 675 } 676 finishlf(); 677 678 if (boot->bpbFSInfo) { 679 ret = 0; |
680 if (boot->FSFree != boot->NumFree) { 681 pwarn("Free space in FSInfo block (%d) not correct (%d)\n", | 680 if (boot->FSFree != 0xffffffffU && 681 boot->FSFree != boot->NumFree) { 682 pwarn("Free space in FSInfo block (%u) not correct (%u)\n", |
682 boot->FSFree, boot->NumFree); 683 if (ask(1, "Fix")) { 684 boot->FSFree = boot->NumFree; 685 ret = 1; 686 } 687 } 688 if (ret) 689 mod |= writefsinfo(dosfs, boot); 690 } 691 692 return mod; 693} | 683 boot->FSFree, boot->NumFree); 684 if (ask(1, "Fix")) { 685 boot->FSFree = boot->NumFree; 686 ret = 1; 687 } 688 } 689 if (ret) 690 mod |= writefsinfo(dosfs, boot); 691 } 692 693 return mod; 694} |