Page MenuHomeFreeBSD

D23082.id66610.diff
No OneTemporary

D23082.id66610.diff

Index: sbin/fsck_msdosfs/boot.c
===================================================================
--- sbin/fsck_msdosfs/boot.c
+++ sbin/fsck_msdosfs/boot.c
@@ -266,8 +266,11 @@
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->NumClusters > (CLUST_RSRVD & CLUST32_MASK)) {
@@ -310,11 +313,19 @@
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",
boot->NumClusters, boot->FATsecs);
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->NumFiles = 1;

File Metadata

Mime Type
text/plain
Expires
Fri, Mar 7, 8:19 AM (19 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
17028305
Default Alt Text
D23082.id66610.diff (1 KB)

Event Timeline