Skip to contentSkip to conversation

mkfs: set perc_in_use to 0xFF

PATCH Applied David Timber 3 participants 3 messages Sep 2 – Sep 4 exFAT file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mkfs: set perc_in_use to 0xFF

Currently, mkfs.exfat always sets the perc_in_use field in the boot header to zero. This is not the correct behaviour since there is always going to be used clusters for the volume structures like the allocation bitmap and upcase table.

perc_in_use is only an advisory field. As the number of used clusters are determined later on during the formatting process, it's not worth risking a huge code change just for correctness. Therefore, to avoid confusion, set it to 0xFF which is the magic value that should be interpreted as "not known" according to the spec.

As the Linux kernel exfat driver currently does not modify perc_in_use at all, unless the volume is mounted by an implementation that modifies it, it will always be read as 0. Setting it to 0xFF should somewhat alleviate the issue because the user would at least know it's not valid.

---
 mkfs/mkfs.c | 1 +
 1 file changed, 1 insertion(+)
mkfs/mkfs.c +1 -0
index 0bc4876..609654b 100644
@@ -388,6 +388,7 @@ static void exfat_setup_boot_sector(struct pbr *ppbr,
 	pbsx->fs_version[0] = 0;
 	pbsx->fs_version[1] = 1;
 	pbsx->phy_drv_no = 0x80;
+	pbsx->perc_in_use = 0xFF;
 	memset(pbsx->reserved2, 0, 7);
 
 	memset(ppbr->boot_code, 0, 390);
Signature · 1 line
2.55.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · David Timber

Currently, mkfs.exfat always sets the perc_in_use field in the boot header to zero. This is not the correct behaviour since there is always going to be used clusters for the volume structures like the allocation bitmap and upcase table.

perc_in_use is only an advisory field. As the number of used clusters are determined later on during the formatting process, it's not worth risking a huge code change just for correctness. Therefore, to avoid confusion, set it to 0xFF which is the magic value that should be interpreted as "not known" according to the spec.

Quoted 6 lines

As the Linux kernel exfat driver currently does not modify perc_in_use at all, unless the volume is mounted by an implementation that modifies it, it will always be read as 0. Setting it to 0xFF should somewhat alleviate the issue because the user would at least know it's not valid.

Thank you for this patch.

Quoted 19 lines
---
 mkfs/mkfs.c | 1 +
 1 file changed, 1 insertion(+)
mkfs/mkfs.c +1 -0
index 0bc4876..609654b 100644
@@ -388,6 +388,7 @@ static void exfat_setup_boot_sector(struct pbr *ppbr,
 	pbsx->fs_version[0] = 0;
 	pbsx->fs_version[1] = 1;
 	pbsx->phy_drv_no = 0x80;
+	pbsx->perc_in_use = 0xFF;
 	memset(pbsx->reserved2, 0, 7);
 
 	memset(ppbr->boot_code, 0, 390);
Signature · 1 line
2.55.0
Signature · 2 lines
Thanks,
Hyunchul
maintainer Applied
#2 lore raw
In reply to David Timber
Quoted 12 lines · David Timber

Currently, mkfs.exfat always sets the perc_in_use field in the boot header to zero. This is not the correct behaviour since there is always going to be used clusters for the volume structures like the allocation bitmap and upcase table.

perc_in_use is only an advisory field. As the number of used clusters are determined later on during the formatting process, it's not worth risking a huge code change just for correctness. Therefore, to avoid confusion, set it to 0xFF which is the magic value that should be interpreted as "not known" according to the spec.

Quoted 6 lines

As the Linux kernel exfat driver currently does not modify perc_in_use at all, unless the volume is mounted by an implementation that modifies it, it will always be read as 0. Setting it to 0xFF should somewhat alleviate the issue because the user would at least know it's not valid.

Applied it to #exfat-next.
Thanks!