From: David Timber <dxdt@dev.snart.me>
To: Namjae Jeon <linkinjeon@kernel.org>,
Sungjong Seo <sj1557.seo@samsung.com>,
Yuezhang Mo <yuezhang.mo@sony.com>
Cc: exfat@lists.linux.dev, Hyunchul Lee <hyc.lee@gmail.com>,
linux-kernel@vger.kernel.org, David Timber <dxdt@dev.snart.me>
Subject: [PATCH v1 1/2] exfat: update percent_in_use field when updating volume flags
Date: Sat, 5 Sep 2026 17:10:42 +0000 [thread overview]
Message-ID: <20260905171043.922793-2-dxdt@dev.snart.me> (raw)
In-Reply-To: <20260905171043.922793-1-dxdt@dev.snart.me>
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.
Signed-off-by: David Timber <dxdt@dev.snart.me>
---
fs/exfat/super.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/fs/exfat/super.c b/fs/exfat/super.c
index a9ea36ba2693..2409e57e7370 100644
--- a/fs/exfat/super.c
+++ b/fs/exfat/super.c
@@ -18,6 +18,7 @@
#include <linux/nls.h>
#include <linux/buffer_head.h>
#include <linux/magic.h>
+#include <linux/math.h>
#include "exfat_raw.h"
#include "exfat_fs.h"
@@ -69,16 +70,28 @@ 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)
+{
+ return (__u8)mul_u64_u32_div(sbi->used_clusters, 100,
+ EXFAT_DATA_CLUSTER_COUNT(sbi));
+}
+
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 +103,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);
--
2.55.0
next prev parent reply other threads:[~2026-09-05 17:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-05 17:10 [PATCH v1 0/2] exfat: update percent_in_use, remove runtime integer division David Timber
2026-09-05 17:10 ` David Timber [this message]
2026-09-05 17:10 ` [PATCH v1 2/2] exfat: " David Timber
2026-09-07 14:42 ` [PATCH v1 0/2] exfat: update percent_in_use, " Namjae Jeon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260905171043.922793-2-dxdt@dev.snart.me \
--to=dxdt@dev.snart.me \
--cc=exfat@lists.linux.dev \
--cc=hyc.lee@gmail.com \
--cc=linkinjeon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sj1557.seo@samsung.com \
--cc=yuezhang.mo@sony.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®