diff options
| author | Xin LI <delphij@FreeBSD.org> | 2020-01-11 17:41:20 +0000 |
|---|---|---|
| committer | Xin LI <delphij@FreeBSD.org> | 2020-01-11 17:41:20 +0000 |
| commit | d3dd66792bfbd6264c65aad5da1d9e47505a52b0 (patch) | |
| tree | c458e1b460b9e30bed0f1f4d7188d5ae45ab4a27 /sbin | |
| parent | ae5b45c86ef51c66a1736346d6ac2f29ccdeb5f1 (diff) | |
Notes
Diffstat (limited to 'sbin')
| -rw-r--r-- | sbin/fsck_msdosfs/boot.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/sbin/fsck_msdosfs/boot.c b/sbin/fsck_msdosfs/boot.c index ff76ac34919d..86528ce83df9 100644 --- a/sbin/fsck_msdosfs/boot.c +++ b/sbin/fsck_msdosfs/boot.c @@ -266,8 +266,11 @@ readboot(int dosfs, struct bootblock *boot) 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 @@ readboot(int dosfs, struct bootblock *boot) 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; |
