Daniel Tang pointed out that shmem doesn't list casefold as a mount option, even when it is mounted casefolded. While fixing it, I noticed f2fs actually already provides that information via sysfs, but ext4 doesn't. This patch reproduces the same interface in ext4 to have feature parity, so users don't need to rely on parsing dmesg or trying +F on a temporary directory just to check for support. Assisted-by: LLM Signed-off-by: Gabriel Krisman Bertazi --- Documentation/ABI/testing/sysfs-fs-ext4 | 21 ++++++++++++++++++ fs/ext4/sysfs.c | 29 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-fs-ext4 b/Documentation/ABI/testing/sysfs-fs-ext4 index 2edd0a6672d3..8abc5706f459 100644 --- a/Documentation/ABI/testing/sysfs-fs-ext4 +++ b/Documentation/ABI/testing/sysfs-fs-ext4 @@ -116,3 +116,24 @@ Contact: "Theodore Ts'o" Description: This file is read-only and shows the pid of journal thread in current pid-namespace or 0 if task is unreachable. + +What: /sys/fs/ext4//encoding +Date: September 2026 +Contact: "Gabriel Krisman Bertazi" +Description: + Displays name and version of the encoding set for the + filesystem. If no encoding is set, displays (none) + +What: /sys/fs/ext4//encoding_flags +Date: September 2026 +Contact: "Gabriel Krisman Bertazi" +Description: + This is a read-only entry to show the value of + sb.s_encoding_flags, the value is hexadecimal. + + ============================ ========== + Flag_Name Flag_Value + ============================ ========== + SB_ENC_STRICT_MODE_FL 0x00000001 + SB_ENC_NO_COMPAT_FALLBACK_FL 0x00000002 + ============================ ========== diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c index 923b375e017f..bc1c59d67eed 100644 --- a/fs/ext4/sysfs.c +++ b/fs/ext4/sysfs.c @@ -32,6 +32,8 @@ typedef enum { attr_clusters_in_group, attr_mb_order, attr_feature, + attr_encoding, + attr_encoding_flags, attr_pointer_pi, attr_pointer_ui, attr_pointer_ul, @@ -161,6 +163,25 @@ static ssize_t err_report_sec_store(struct ext4_sb_info *sbi, return count; } +static ssize_t encoding_show(struct ext4_sb_info *sbi, char *buf) +{ +#if IS_ENABLED(CONFIG_UNICODE) + struct super_block *sb = sbi->s_sb; + + if (ext4_has_feature_casefold(sb)) + return sysfs_emit(buf, "UTF-8 (%d.%d.%d)\n", + unicode_major(sb->s_encoding->version), + unicode_minor(sb->s_encoding->version), + unicode_rev(sb->s_encoding->version)); +#endif + return sysfs_emit(buf, "(none)\n"); +} + +static ssize_t encoding_flags_show(struct ext4_sb_info *sbi, char *buf) +{ + return sysfs_emit(buf, "%x\n", le16_to_cpu(sbi->s_es->s_encoding_flags)); +} + static ssize_t journal_task_show(struct ext4_sb_info *sbi, char *buf) { if (!sbi->s_journal) @@ -283,6 +304,8 @@ EXT4_RO_ATTR_ES_STRING(last_error_func, s_last_error_func, 32); EXT4_ATTR(first_error_time, 0444, first_error_time); EXT4_ATTR(last_error_time, 0444, last_error_time); EXT4_ATTR(journal_task, 0444, journal_task); +EXT4_ATTR_FUNC(encoding, 0444); +EXT4_ATTR_FUNC(encoding_flags, 0444); EXT4_RW_ATTR_SBI_UI(mb_prefetch, s_mb_prefetch); EXT4_RW_ATTR_SBI_UI(mb_prefetch_limit, s_mb_prefetch_limit); EXT4_RW_ATTR_SBI_UL(last_trim_minblks, s_last_trim_minblks); @@ -333,6 +356,8 @@ static struct attribute *ext4_attrs[] = { ATTR_LIST(first_error_time), ATTR_LIST(last_error_time), ATTR_LIST(journal_task), + ATTR_LIST(encoding), + ATTR_LIST(encoding_flags), #ifdef CONFIG_EXT4_DEBUG ATTR_LIST(simulate_fail), #endif @@ -483,6 +508,10 @@ static ssize_t ext4_attr_show(struct kobject *kobj, return print_tstamp(buf, sbi->s_es, s_last_error_time); case attr_journal_task: return journal_task_show(sbi, buf); + case attr_encoding: + return encoding_show(sbi, buf); + case attr_encoding_flags: + return encoding_flags_show(sbi, buf); default: return ext4_generic_attr_show(a, sbi, buf); } -- 2.55.0