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

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