exfat: update percent_in_use field when updating volume flags
RFC PATCH 1/1 exfat: update percent_in_use field when updating volume flags
Currently, the exfat fs implementation does not modify the percent_in_use in the boot sector header at all. Although the field is only an advisory field for situations where bit counting is not feasible, not updating the field at all can cause confusion if the the value is actually exposed to the user.
Calculate the value using integer arithmetic only when the dirty flag is cleared. If the dirty flag is set, set to 0xFF.
It is set to 0xFF when mounting under the assumption that the number of used clusters will change - this is basically what is recommended in the SD Association's specs.
When clearing the dirty flag, if overridden by sbi->vol_flags_persistent, set to 0xFF. This is intentional because if there are orphan clusters, the calculated value would be incorrect and correcting the fs error is fsck.exfat's job.
--- fs/exfat/super.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
fs/exfat/super.c +18 -1
@@ -69,16 +69,32 @@ static int exfat_statfs(struct dentry *dentry, struct kstatfs *buf)return 0 ; } +static inline __u8 exfat_calc_perc_in_use (const struct exfat_sb_info *sbi) +{ +const unsigned long long total_clus =EXFAT_DATA_CLUSTER_COUNT (sbi); +unsigned long long ret = sbi->used_clusters; + + ret *=100 ; + ret /= total_clus; +return (__u8 )ret; +} +static int exfat_set_vol_flags (struct super_block *sb,unsigned short new_flags) {struct exfat_sb_info *sbi =EXFAT_SB (sb);struct boot_sector *p_boot = (struct boot_sector *)sbi->boot_bh->b_data; +__u8 new_piu;/* retain persistent-flags */ new_flags |= sbi->vol_flags_persistent; +if (new_flags &VOLUME_DIRTY ) + new_piu =0xFF ; +else + new_piu =exfat_calc_perc_in_use (sbi); +/* flags are not changed */ -if (sbi->vol_flags == new_flags) +if (sbi->vol_flags == new_flags && new_piu == p_boot->percent_in_use)return 0 ; sbi->vol_flags = new_flags;
@@ -90,6 +106,7 @@ static int exfat_set_vol_flags(struct super_block *sb, unsigned short new_flags)return 0 ; p_boot->vol_flags =cpu_to_le16 (new_flags); + p_boot->percent_in_use = new_piu;set_buffer_uptodate (sbi->boot_bh);mark_buffer_dirty (sbi->boot_bh);
Signature · 1 line
2.55.0
Quoted 14 lines · David Timber
Currently, the exfat fs implementation does not modify the
percent_in_usein the boot sector header at all. Although the field is only an advisory field for situations where bit counting is not feasible, not updating the field at all can cause confusion if the the value is actually exposed to the user.Calculate the value using integer arithmetic only when the dirty flag is cleared. If the dirty flag is set, set to
0xFF.It is set to
0xFFwhen mounting under the assumption that the number of used clusters will change - this is basically what is recommended in the SD Association's specs.
Quoted 6 lines
When clearing the dirty flag, if overridden by
sbi->vol_flags_persistent, set to0xFF. This is intentional because if there are orphan clusters, the calculated value would be incorrect and correcting the fs error is fsck.exfat's job.Signed-off-by David Timber <[email protected]>
Applied it to dev.
Shouldn’t mkfs.exfat also initialize ->perc_in_use with the calculated value instead of leaving it at zero?
Thanks.
Quoted 19 lines · Namjae Jeon
Quoted 18 lines · David Timber
Currently, the exfat fs implementation does not modify the
percent_in_usein the boot sector header at all. Although the field is only an advisory field for situations where bit counting is not feasible, not updating the field at all can cause confusion if the the value is actually exposed to the user.Calculate the value using integer arithmetic only when the dirty flag is cleared. If the dirty flag is set, set to
0xFF.It is set to
0xFFwhen mounting under the assumption that the number of used clusters will change - this is basically what is recommended in the SD Association's specs.When clearing the dirty flag, if overridden by
sbi->vol_flags_persistent, set to0xFF. This is intentional because if there are orphan clusters, the calculated value would be incorrect and correcting the fs error is fsck.exfat's job.
Quoted 5 lines
Quoted 1 line
Signed-off-by David Timber <[email protected]>Applied it to dev.
Shouldn’t mkfs.exfat also initialize ->perc_in_use with the calculated value instead of leaving it at zero?
I've sent the patch. I've just changed it to 0xFF instead of zero.
Namjae Jeon
maintainerQuoted 21 lines · David Timber
Quoted 19 lines · Namjae Jeon
Quoted 18 lines · David Timber
Currently, the exfat fs implementation does not modify the
percent_in_usein the boot sector header at all. Although the field is only an advisory field for situations where bit counting is not feasible, not updating the field at all can cause confusion if the the value is actually exposed to the user.Calculate the value using integer arithmetic only when the dirty flag is cleared. If the dirty flag is set, set to
0xFF.It is set to
0xFFwhen mounting under the assumption that the number of used clusters will change - this is basically what is recommended in the SD Association's specs.When clearing the dirty flag, if overridden by
sbi->vol_flags_persistent, set to0xFF. This is intentional because if there are orphan clusters, the calculated value would be incorrect and correcting the fs error is fsck.exfat's job.
Quoted 6 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by David Timber <[email protected]>Applied it to dev.
Shouldn’t mkfs.exfat also initialize ->perc_in_use with the calculated value instead of leaving it at zero?
I've sent the patch. I've just changed it to
0xFFinstead of zero.
Please check a warning from kernel test robot.
For now, I will remove this patch from the exfat dev queue.
Quoted 21 lines · Namjae Jeon
Quoted 20 lines · David Timber
Quoted 19 lines · Namjae Jeon
Quoted 18 lines · David Timber
Currently, the exfat fs implementation does not modify the
percent_in_usein the boot sector header at all. Although the field is only an advisory field for situations where bit counting is not feasible, not updating the field at all can cause confusion if the the value is actually exposed to the user.Calculate the value using integer arithmetic only when the dirty flag is cleared. If the dirty flag is set, set to
0xFF.It is set to
0xFFwhen mounting under the assumption that the number of used clusters will change - this is basically what is recommended in the SD Association's specs.When clearing the dirty flag, if overridden by
sbi->vol_flags_persistent, set to0xFF. This is intentional because if there are orphan clusters, the calculated value would be incorrect and correcting the fs error is fsck.exfat's job.
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by David Timber <[email protected]>Applied it to dev.
Shouldn’t mkfs.exfat also initialize ->perc_in_use with the calculated value instead of leaving it at zero?
I've sent the patch. I've just changed it to
0xFFinstead of zero.Please check a warning from kernel test robot.
For now, I will remove this patch from the exfat dev queue.
There are several places where runtime division is used. I don't think fs/exfat would build on RISC-V w/o integer division either.
mul_u64_u32_div() seems to be a good candidate for the fix. do_div() for other places.
Will follow up.
Davo