Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Gabriel Krisman Bertazi <krisman@suse.de>
To: linux-fsdevel@vger.kernel.org
Cc: Gabriel Krisman Bertazi <krisman@suse.de>,
	Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
	"Theodore Ts'o" <tytso@mit.edu>, Hugh Dickins <hughd@google.com>,
	Daniel Tang <danielzgtg.opensource@gmail.com>,
	linux-ext4@vger.kernel.org, Miklos Szeredi <miklos@szeredi.hu>,
	Amir Goldstein <amir73il@gmail.com>,
	linux-unionfs@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH 2/4] ext4: Expose the filesystem encoding through sysfs
Date: Mon, 28 Sep 2026 17:31:53 -0400	[thread overview]
Message-ID: <20260928213155.2612039-3-krisman@suse.de> (raw)
In-Reply-To: <20260928213155.2612039-1-krisman@suse.de>

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 <krisman@suse.de>
---
 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" <tytso@mit.edu>
 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/<disk>/encoding
+Date:		September 2026
+Contact:	"Gabriel Krisman Bertazi" <krisman@suse.de>
+Description:
+		Displays name and version of the encoding set for the
+		filesystem.  If no encoding is set, displays (none)
+
+What:		/sys/fs/ext4/<disk>/encoding_flags
+Date:		September 2026
+Contact:	"Gabriel Krisman Bertazi" <krisman@suse.de>
+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



  parent reply	other threads:[~2026-09-28 21:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-28 21:31 [PATCH 0/4] Expose encoding information of volumes Gabriel Krisman Bertazi
2026-09-28 21:31 ` [PATCH 1/4] shmem: Report casefold setting in mount options Gabriel Krisman Bertazi
2026-09-29 14:00   ` Mohammed EL Kadiri
2026-09-29 15:17     ` Gabriel Krisman Bertazi
2026-09-28 21:31 ` Gabriel Krisman Bertazi [this message]
2026-09-28 21:31 ` [PATCH 3/4] ovl: Add /sys/fs/overlay plumbing Gabriel Krisman Bertazi
2026-09-28 21:31 ` [PATCH 4/4] ovl: Expose the filesystem encoding through sysfs Gabriel Krisman Bertazi
2026-09-29 14:15   ` Amir Goldstein
2026-09-29 14:40     ` Pali Rohár
2026-09-29 15:35       ` Gabriel Krisman Bertazi
2026-09-29 15:35     ` Gabriel Krisman Bertazi

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=20260928213155.2612039-3-krisman@suse.de \
    --to=krisman@suse.de \
    --cc=amir73il@gmail.com \
    --cc=brauner@kernel.org \
    --cc=danielzgtg.opensource@gmail.com \
    --cc=hughd@google.com \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=tytso@mit.edu \
    /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