Blame dosfstools-4.1-fix-cluster-size-auto-detect-for-4k-disks.patch

Petr Šabata c3c316
diff --git a/src/mkfs.fat.c b/src/mkfs.fat.c
Petr Šabata c3c316
index 5843550..29fbf55 100644
Petr Šabata c3c316
--- a/src/mkfs.fat.c
Petr Šabata c3c316
+++ b/src/mkfs.fat.c
Petr Šabata c3c316
@@ -507,6 +507,7 @@ static void establish_params(struct device_info *info)
Petr Šabata c3c316
     unsigned int heads = 255;
Petr Šabata c3c316
     unsigned int media = 0xf8;
Petr Šabata c3c316
     unsigned int cluster_size = 4;  /* starting point for FAT12 and FAT16 */
Petr Šabata c3c316
+    unsigned int sector_size_mult = 1; /* x 512 == sector_size */
Petr Šabata c3c316
     int def_root_dir_entries = 512;
Petr Šabata c3c316
 
Petr Šabata c3c316
     if (info->size < 512 * 1024 * 1024) {
Petr Šabata c3c316
@@ -580,11 +581,15 @@ static void establish_params(struct device_info *info)
Petr Šabata c3c316
 	 * fs size >   32G:  32k clusters
Petr Šabata c3c316
 	 *
Petr Šabata c3c316
 	 * This only works correctly for 512 byte sectors!
Petr Šabata c3c316
+	 * For other sector sizes it tries to approximate.
Petr Šabata c3c316
 	 */
Petr Šabata c3c316
 	uint32_t sz_mb = info->size / (1024 * 1024);
Petr Šabata c3c316
+	if (info->sector_size > 0)
Petr Šabata c3c316
+	    sector_size_mult = info->sector_size / 512;
Petr Šabata c3c316
 	cluster_size =
Petr Šabata c3c316
-	    sz_mb > 32 * 1024 ? 64 : sz_mb > 16 * 1024 ? 32 : sz_mb >
Petr Šabata c3c316
-	    8 * 1024 ? 16 : sz_mb > 260 ? 8 : 1;
Petr Šabata c3c316
+	    sz_mb > 32 * 1024 * sector_size_mult ? 64 : sz_mb >
Petr Šabata c3c316
+	    16 * 1024 * sector_size_mult ? 32 : sz_mb >
Petr Šabata c3c316
+	    8 * 1024 * sector_size_mult ? 16 : sz_mb > 260 * sector_size_mult ? 8 : 1;
Petr Šabata c3c316
     }
Petr Šabata c3c316
 
Petr Šabata c3c316
     if (info->geom_heads > 0) {