[PATCH v1 04/54] fs: fat: don't duplicate dentries when resolving differently cased paths
Ahmad Fatoum
a.fatoum at pengutronix.de
Thu Dec 18 02:37:24 PST 2025
With case insensitive file systems, like FAT, we should avoid having
multiple dentry cache entries for the same file differing only in
capitalization. Allow case-insensitive file system to set a casefold
flag that barebox will honour when comparing dentries.
That this patch works can be verified using the debug_fs_dump command,
which will show a dentry for each differently cased path in a VFAT,
but only a single dentry once this patch is applied.
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
fs/fat/fat.c | 1 +
fs/fs.c | 3 +++
include/linux/fs.h | 1 +
3 files changed, 5 insertions(+)
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index cdca666566d2..93d1e08b8456 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -352,6 +352,7 @@ static int fat_probe(struct device *dev)
goto err_open;
priv->cdev = fsdev->cdev;
+ fsdev->sb.s_casefold = true;
priv->fat.userdata = priv;
ret = f_mount(&priv->fat);
diff --git a/fs/fs.c b/fs/fs.c
index cc6f0f7057c3..e997bd5f6a99 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1562,6 +1562,9 @@ static bool d_same_name(const struct dentry *dentry,
if (dentry->d_name.len != name->len)
return false;
+ if (dentry->d_sb->s_casefold)
+ return strncasecmp(dentry->d_name.name, name->name, name->len) == 0;
+
return strncmp(dentry->d_name.name, name->name, name->len) == 0;
}
diff --git a/include/linux/fs.h b/include/linux/fs.h
index e624b2ce7161..d3813ad9c543 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -160,6 +160,7 @@ struct super_block {
unsigned long s_blocksize;
unsigned char s_blocksize_bits;
unsigned char s_dirt;
+ bool s_casefold;
unsigned long long s_maxbytes; /* Max file size */
struct file_system_type *s_type;
const struct super_operations *s_op;
--
2.47.3
More information about the barebox
mailing list