Changeset View
Changeset View
Standalone View
Standalone View
head/sbin/fsck_msdosfs/boot.c
Show First 20 Lines • Show All 260 Lines • ▼ Show 20 Lines | boot->FirstCluster = (boot->bpbRootDirEnts * 32 + | ||||
boot->bpbResSectors + boot->bpbFATs * boot->FATsecs; | boot->bpbResSectors + boot->bpbFATs * boot->FATsecs; | ||||
if (boot->FirstCluster + boot->bpbSecPerClust > boot->NumSectors) { | if (boot->FirstCluster + boot->bpbSecPerClust > boot->NumSectors) { | ||||
pfatal("Cluster offset too large (%u clusters)\n", | pfatal("Cluster offset too large (%u clusters)\n", | ||||
boot->FirstCluster); | boot->FirstCluster); | ||||
return FSFATAL; | return FSFATAL; | ||||
} | } | ||||
boot->NumClusters = (boot->NumSectors - boot->FirstCluster) / boot->bpbSecPerClust + | /* | ||||
CLUST_FIRST; | * The number of clusters is derived from available data sectors, divided | ||||
* by sectors per cluster. | |||||
*/ | |||||
boot->NumClusters = (boot->NumSectors - boot->FirstCluster) / boot->bpbSecPerClust; | |||||
if (boot->flags & FAT32) { | if (boot->flags & FAT32) { | ||||
if (boot->NumClusters > (CLUST_RSRVD & CLUST32_MASK)) { | if (boot->NumClusters > (CLUST_RSRVD & CLUST32_MASK)) { | ||||
pfatal("Filesystem too big (%u clusters) for FAT32 partition", | pfatal("Filesystem too big (%u clusters) for FAT32 partition", | ||||
boot->NumClusters); | boot->NumClusters); | ||||
return FSFATAL; | return FSFATAL; | ||||
} | } | ||||
if (boot->NumClusters < (CLUST_RSRVD & CLUST16_MASK)) { | if (boot->NumClusters < (CLUST_RSRVD & CLUST16_MASK)) { | ||||
Show All 26 Lines | readboot(int dosfs, struct bootblock *boot) | ||||
case CLUST16_MASK: | case CLUST16_MASK: | ||||
boot->NumFatEntries = (boot->FATsecs * boot->bpbBytesPerSec) / 2; | boot->NumFatEntries = (boot->FATsecs * boot->bpbBytesPerSec) / 2; | ||||
break; | break; | ||||
default: | default: | ||||
boot->NumFatEntries = (boot->FATsecs * boot->bpbBytesPerSec * 2) / 3; | boot->NumFatEntries = (boot->FATsecs * boot->bpbBytesPerSec * 2) / 3; | ||||
break; | break; | ||||
} | } | ||||
if (boot->NumFatEntries < boot->NumClusters - CLUST_FIRST) { | if (boot->NumFatEntries < boot->NumClusters) { | ||||
pfatal("FAT size too small, %u entries won't fit into %u sectors\n", | pfatal("FAT size too small, %u entries won't fit into %u sectors\n", | ||||
boot->NumClusters, boot->FATsecs); | boot->NumClusters, boot->FATsecs); | ||||
return FSFATAL; | return FSFATAL; | ||||
} | } | ||||
/* | |||||
* There are two reserved clusters. To avoid adding CLUST_FIRST every time | |||||
* when we perform boundary checks, we increment the NumClusters by 2, | |||||
* which is CLUST_FIRST to denote the first out-of-range cluster number. | |||||
*/ | |||||
boot->NumClusters += CLUST_FIRST; | |||||
boot->ClusterSize = boot->bpbBytesPerSec * boot->bpbSecPerClust; | boot->ClusterSize = boot->bpbBytesPerSec * boot->bpbSecPerClust; | ||||
boot->NumFiles = 1; | boot->NumFiles = 1; | ||||
boot->NumFree = 0; | boot->NumFree = 0; | ||||
return ret; | return ret; | ||||
} | } | ||||
Show All 39 Lines |