OSDN Git Service

Fail to create FS if specified cluster size is too small.
authorresver <resver@60bc1c72-a15a-11de-b98f-4500b42dc123>
Sun, 18 Mar 2012 13:24:37 +0000 (13:24 +0000)
committerresver <resver@60bc1c72-a15a-11de-b98f-4500b42dc123>
Sun, 18 Mar 2012 13:24:37 +0000 (13:24 +0000)
git-svn-id: http://exfat.googlecode.com/svn/trunk@277 60bc1c72-a15a-11de-b98f-4500b42dc123

mkfs/main.c

index 885dd71..675140a 100644 (file)
@@ -52,10 +52,27 @@ struct exfat_structure
 static int init_sb(off_t volume_size, int sector_bits, int spc_bits,
                uint32_t volume_serial, int first_sector)
 {
-       uint32_t clusters_max = (volume_size >> sector_bits >> spc_bits);
-       uint32_t fat_sectors = DIV_ROUND_UP(clusters_max * 4, 1 << sector_bits);
+       uint32_t clusters_max;
+       uint32_t fat_sectors;
        uint32_t allocated_clusters;
 
+       if ((volume_size >> sector_bits >> spc_bits) > EXFAT_LAST_DATA_CLUSTER)
+       {
+               struct exfat_human_bytes chb, vhb;
+
+               exfat_humanize_bytes(1 << sector_bits << spc_bits, &chb);
+               exfat_humanize_bytes(volume_size, &vhb);
+               exfat_error("cluster size %"PRIu64" %s is too small for "
+                               "%"PRIu64" %s volume",
+                               chb.value, chb.unit,
+                               vhb.value, vhb.unit);
+               return 1;
+       }
+
+       clusters_max = (volume_size >> sector_bits >> spc_bits);
+       fat_sectors = DIV_ROUND_UP((off_t) clusters_max * sizeof(cluster_t),
+                       1 << sector_bits);
+
        memset(&sb, 0, sizeof(struct exfat_super_block));
        sb.jump[0] = 0xeb;
        sb.jump[1] = 0x76;