aboutsummaryrefslogtreecommitdiff
path: root/util-linux/mkfs_vfat.c
diff options
context:
space:
mode:
Diffstat (limited to 'util-linux/mkfs_vfat.c')
-rw-r--r--util-linux/mkfs_vfat.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/util-linux/mkfs_vfat.c b/util-linux/mkfs_vfat.c
index 10de2af5b..de88a7443 100644
--- a/util-linux/mkfs_vfat.c
+++ b/util-linux/mkfs_vfat.c
@@ -391,16 +391,22 @@ int mkfs_vfat_main(int argc UNUSED_PARAM, char **argv)
391 while (1) { 391 while (1) {
392 while (1) { 392 while (1) {
393 int spf_adj; 393 int spf_adj;
394 off_t tcl = (volume_size_sect - reserved_sect - NUM_FATS * sect_per_fat) / sect_per_clust; 394 uoff_t tcl = (volume_size_sect - reserved_sect - NUM_FATS * sect_per_fat) / sect_per_clust;
395 // tcl may be > MAX_CLUST_32 here, but it may be 395 // tcl may be > MAX_CLUST_32 here, but it may be
396 // because sect_per_fat is underestimated, 396 // because sect_per_fat is underestimated,
397 // and with increased sect_per_fat it still may become 397 // and with increased sect_per_fat it still may become
398 // <= MAX_CLUST_32. Therefore, we do not check 398 // <= MAX_CLUST_32. Therefore, we do not check
399 // against MAX_CLUST_32, but against a bigger const: 399 // against MAX_CLUST_32, but against a bigger const:
400 if (tcl > 0x7fffffff) 400 if (tcl > 0x80ffffff)
401 goto next; 401 goto next;
402 total_clust = tcl; // fits in uint32_t 402 total_clust = tcl; // fits in uint32_t
403 spf_adj = ((total_clust + 2) * 4 + bytes_per_sect - 1) / bytes_per_sect - sect_per_fat; 403 // Every cluster needs 4 bytes in FAT. +2 entries since
404 // FAT has space for non-existent clusters 0 and 1.
405 // Let's see how many sectors that needs.
406 //May overflow at "*4":
407 //spf_adj = ((total_clust+2) * 4 + bytes_per_sect-1) / bytes_per_sect - sect_per_fat;
408 //Same in the more obscure, non-overflowing form:
409 spf_adj = ((total_clust+2) + (bytes_per_sect/4)-1) / (bytes_per_sect/4) - sect_per_fat;
404#if 0 410#if 0
405 bb_error_msg("sect_per_clust:%u sect_per_fat:%u total_clust:%u", 411 bb_error_msg("sect_per_clust:%u sect_per_fat:%u total_clust:%u",
406 sect_per_clust, sect_per_fat, (int)tcl); 412 sect_per_clust, sect_per_fat, (int)tcl);