From 1032747d0a4f372eaeeacc4e48e65ff2f13c5e26 Mon Sep 17 00:00:00 2001 From: Matthieu CASTET Date: Thu, 5 Dec 2019 11:43:16 +0100 Subject: [PATCH 1/2] mkfs : Fix cluster_count Cluster count is the number of cluster after cluster_sector_start. --- mkfs/vbr.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mkfs/vbr.c b/mkfs/vbr.c index e40081fa..c896fbc4 100644 --- a/mkfs/vbr.c +++ b/mkfs/vbr.c @@ -62,8 +62,7 @@ static void init_sb(struct exfat_super_block* sb) sb->cluster_sector_start = cpu_to_le32( get_position(&cbm) / get_sector_size()); sb->cluster_count = cpu_to_le32(clusters_max - - ((le32_to_cpu(sb->fat_sector_start) + - le32_to_cpu(sb->fat_sector_count)) >> get_spc_bits())); + (le32_to_cpu(sb->cluster_sector_start) >> get_spc_bits())); sb->rootdir_cluster = cpu_to_le32( (get_position(&rootdir) - get_position(&cbm)) / get_cluster_size() + EXFAT_FIRST_DATA_CLUSTER); From 5e599f2ff6a611d8bac9491dd21601331345a2a8 Mon Sep 17 00:00:00 2001 From: Matthieu CASTET Date: Thu, 5 Dec 2019 11:56:38 +0100 Subject: [PATCH 2/2] mount: check cluster_count against sector_count and cluster_sector_start This is follow exfat specification and take in accound cluster_sector_start --- libexfat/mount.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libexfat/mount.c b/libexfat/mount.c index a22e0f8b..988ebdaa 100644 --- a/libexfat/mount.c +++ b/libexfat/mount.c @@ -293,12 +293,15 @@ int exfat_mount(struct exfat* ef, const char* spec, const char* options) exfat_get_size(ef->dev)); } if ((off_t) le32_to_cpu(ef->sb->cluster_count) * CLUSTER_SIZE(*ef->sb) > - exfat_get_size(ef->dev)) + (le64_to_cpu(ef->sb->sector_count) - le32_to_cpu(ef->sb->cluster_sector_start)) + * SECTOR_SIZE(*ef->sb)) { - exfat_error("file system in clusters is larger than device: " - "%u * %d > %"PRIu64, + exfat_error("file system in clusters is larger than file system in sectors: " + "%u * %d > (%"PRIu64" - %d) * %d", le32_to_cpu(ef->sb->cluster_count), CLUSTER_SIZE(*ef->sb), - exfat_get_size(ef->dev)); + le64_to_cpu(ef->sb->sector_count), + le32_to_cpu(ef->sb->cluster_sector_start), + SECTOR_SIZE(*ef->sb)); exfat_free(ef); return -EIO; }