From: Chi Zhiling <chizhiling@163.com>
To: Namjae Jeon <linkinjeon@kernel.org>,
Sungjong Seo <sj1557.seo@samsung.com>,
Yuezhang Mo <yuezhang.mo@sony.com>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Chi Zhiling <chizhiling@kylinos.cn>
Subject: [PATCH v3 3/6] exfat: use exfat_cluster_walk helper
Date: Fri, 3 Apr 2026 16:05:35 +0800 [thread overview]
Message-ID: <20260403080538.361663-4-chizhiling@163.com> (raw)
In-Reply-To: <20260403080538.361663-1-chizhiling@163.com>
From: Chi Zhiling <chizhiling@kylinos.cn>
Replace the custom exfat_walk_fat_chain() function and open-coded
FAT chain walking logic with the exfat_cluster_walk() helper across
exfat_find_location, __exfat_get_dentry_set, and exfat_map_cluster.
Suggested-by: Sungjong Seo <sj1557.seo@samsung.com>
Signed-off-by: Chi Zhiling <chizhiling@kylinos.cn>
---
fs/exfat/dir.c | 47 +++++++++++------------------------------------
fs/exfat/inode.c | 11 ++---------
2 files changed, 13 insertions(+), 45 deletions(-)
diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c
index 7619410d668e..ca5827046a1f 100644
--- a/fs/exfat/dir.c
+++ b/fs/exfat/dir.c
@@ -562,38 +562,6 @@ int exfat_put_dentry_set(struct exfat_entry_set_cache *es, int sync)
return err;
}
-static int exfat_walk_fat_chain(struct super_block *sb,
- struct exfat_chain *p_dir, unsigned int byte_offset,
- unsigned int *clu)
-{
- struct exfat_sb_info *sbi = EXFAT_SB(sb);
- unsigned int clu_offset;
- unsigned int cur_clu;
-
- clu_offset = EXFAT_B_TO_CLU(byte_offset, sbi);
- cur_clu = p_dir->dir;
-
- if (p_dir->flags == ALLOC_NO_FAT_CHAIN) {
- cur_clu += clu_offset;
- } else {
- while (clu_offset > 0) {
- if (exfat_get_next_cluster(sb, &cur_clu))
- return -EIO;
- if (cur_clu == EXFAT_EOF_CLUSTER) {
- exfat_fs_error(sb,
- "invalid dentry access beyond EOF (clu : %u, eidx : %d)",
- p_dir->dir,
- EXFAT_B_TO_DEN(byte_offset));
- return -EIO;
- }
- clu_offset--;
- }
- }
-
- *clu = cur_clu;
- return 0;
-}
-
static int exfat_find_location(struct super_block *sb, struct exfat_chain *p_dir,
int entry, sector_t *sector, int *offset)
{
@@ -603,10 +571,19 @@ static int exfat_find_location(struct super_block *sb, struct exfat_chain *p_dir
off = EXFAT_DEN_TO_B(entry);
- ret = exfat_walk_fat_chain(sb, p_dir, off, &clu);
+ clu = p_dir->dir;
+ ret = exfat_cluster_walk(sb, &clu, EXFAT_B_TO_CLU(off, sbi), p_dir->flags);
if (ret)
return ret;
+ if (clu == EXFAT_EOF_CLUSTER) {
+ exfat_fs_error(sb,
+ "unexpected early break in cluster chain (clu : %u, len : %d)",
+ p_dir->dir,
+ EXFAT_B_TO_CLU(off, sbi));
+ return -EIO;
+ }
+
if (!exfat_test_bitmap(sb, clu)) {
exfat_err(sb, "failed to test cluster bit(%u)", clu);
return -EIO;
@@ -792,9 +769,7 @@ static int __exfat_get_dentry_set(struct exfat_entry_set_cache *es,
if (exfat_is_last_sector_in_cluster(sbi, sec)) {
unsigned int clu = exfat_sector_to_cluster(sbi, sec);
- if (p_dir->flags == ALLOC_NO_FAT_CHAIN)
- clu++;
- else if (exfat_get_next_cluster(sb, &clu))
+ if (exfat_cluster_walk(sb, &clu, 1, p_dir->flags))
goto put_es;
sec = exfat_cluster_to_sector(sbi, clu);
} else {
diff --git a/fs/exfat/inode.c b/fs/exfat/inode.c
index beb9ea7cca9f..cde2eb0f31ad 100644
--- a/fs/exfat/inode.c
+++ b/fs/exfat/inode.c
@@ -225,15 +225,8 @@ static int exfat_map_cluster(struct inode *inode, unsigned int clu_offset,
* *clu = (the first cluster of the allocated chain) =>
* (the last cluster of ...)
*/
- if (ei->flags == ALLOC_NO_FAT_CHAIN) {
- *clu += num_to_be_allocated - 1;
- } else {
- while (num_to_be_allocated > 1) {
- if (exfat_get_next_cluster(sb, clu))
- return -EIO;
- num_to_be_allocated--;
- }
- }
+ if (exfat_cluster_walk(sb, clu, num_to_be_allocated - 1, ei->flags))
+ return -EIO;
*count = 1;
}
--
2.43.0
next prev parent reply other threads:[~2026-04-03 8:06 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20260403080638epcas1p34e96a9d3f74f963d1085f67399f51da2@epcas1p3.samsung.com>
2026-04-03 8:05 ` [PATCH v3 0/6] exfat: unify FAT chain walking helpers Chi Zhiling
2026-04-03 8:05 ` [PATCH v3 1/6] exfat: fix incorrect directory checksum after rename to shorter name Chi Zhiling
2026-04-03 8:05 ` [PATCH v3 2/6] exfat: introduce exfat_cluster_walk helper Chi Zhiling
2026-04-03 8:05 ` Chi Zhiling [this message]
2026-04-03 8:05 ` [PATCH v3 4/6] exfat: remove NULL cache pointer case in exfat_ent_get Chi Zhiling
2026-04-03 8:05 ` [PATCH v3 5/6] exfat: introduce exfat_chain_advance helper Chi Zhiling
2026-04-03 8:05 ` [PATCH v3 6/6] exfat: use " Chi Zhiling
2026-04-03 8:38 ` [PATCH v3 0/6] exfat: unify FAT chain walking helpers Sungjong Seo
2026-04-03 10:07 ` Yuezhang.Mo
2026-04-03 13:44 ` 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=20260403080538.361663-4-chizhiling@163.com \
--to=chizhiling@163.com \
--cc=chizhiling@kylinos.cn \
--cc=linkinjeon@kernel.org \
--cc=linux-fsdevel@vger.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