dosfstools/0010-mkfs.fat-Fix-calculation-of-FAT32-cluster-size-on-no.patch

41 lines
1.4 KiB
Diff

From b71c7c400276cc48acc257c294e01825773100dc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pali=20Roh=C3=A1r?= <pali.rohar@gmail.com>
Date: Sat, 11 Aug 2018 20:34:08 +0200
Subject: [PATCH] mkfs.fat: Fix calculation of FAT32 cluster size on non 512
bytes sector disks
Previous FAT32 calculation worked correctly only for disks with 512 byte
sectors. New calculation formula is generalized variant of previous one,
but to be sector size independent.
---
src/mkfs.fat.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/mkfs.fat.c b/src/mkfs.fat.c
index ff89013..f7d8607 100644
--- a/src/mkfs.fat.c
+++ b/src/mkfs.fat.c
@@ -588,13 +588,13 @@ static void establish_params(struct device_info *info)
* fs size <= 16G: 8k clusters
* fs size <= 32G: 16k clusters
* fs size > 32G: 32k clusters
- *
- * This only works correctly for 512 byte sectors!
*/
- uint32_t sz_mb = info->size / (1024 * 1024);
- cluster_size =
- sz_mb > 32 * 1024 ? 64 : sz_mb > 16 * 1024 ? 32 : sz_mb >
- 8 * 1024 ? 16 : sz_mb > 260 ? 8 : 1;
+ unsigned long long int sectors = info->size / sector_size;
+ cluster_size = sectors > 32*1024*1024*2 ? 64 :
+ sectors > 16*1024*1024*2 ? 32 :
+ sectors > 8*1024*1024*2 ? 16 :
+ sectors > 260*1024*2 ? 8 : 1;
+
}
if (info->geom_heads > 0) {
--
1.8.3.1