mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daeho Jeong <daeho43@gmail.com>
To: linux-kernel@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com
Cc: Daeho Jeong <daehojeong@google.com>,
	Wenjie Qi <qiwenjie@xiaomi.com>,
	stable@vger.kernel.org
Subject: [PATCH] mkfs.f2fs: enforce alias_filename to match device name
Date: Wed, 26 Aug 2026 11:11:21 -0700	[thread overview]
Message-ID: <20260826181121.3825702-1-daeho43@gmail.com> (raw)

From: Daeho Jeong <daehojeong@google.com>

The kernel expects the device alias file in the root directory to match
the device basename (strrchr(path, '/') + 1) to identify the target device
both during mount in f2fs_restore_device_alias() and during reserve in
f2fs_ioc_reserve_dev_alias().

If a custom alias filename that differs from the device name is used,
the kernel fails to match the alias file at mount time (leaving
FDEV(i).has_alias unset and allowing pinned files to allocate in that
range) and subsequently fails to reserve the device range when requested.

Enforce that if an alias filename is specified, it must match the device
name. Also allow specifying just '-c <device>@' as a shorthand so users
do not have to redundantly type the device basename twice.

Reported-by: Wenjie Qi <qiwenjie@xiaomi.com>
Fixes: 8cc4e257ec20 ("mkfs.f2fs: add device aliasing feature")
Cc: stable@vger.kernel.org
Signed-off-by: Daeho Jeong <daehojeong@google.com>
---
 man/mkfs.f2fs.8         |  4 +++-
 mkfs/f2fs_format_main.c | 27 +++++++++++++++------------
 2 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/man/mkfs.f2fs.8 b/man/mkfs.f2fs.8
index 9096646..430d180 100644
--- a/man/mkfs.f2fs.8
+++ b/man/mkfs.f2fs.8
@@ -121,10 +121,12 @@ Currently, the kernel is only able to mount f2fs filesystems where the
 block size matches the page size.
 The default value is 4096.
 .TP
-.BI \-c " device-list"
+.BI \-c " device_name[@alias_filename]"
 Build f2fs with these additional devices, so that the user can
 see all the devices as one big volume.
 Supports up to 7 devices except meta device.
+If '@' or '@alias_filename' is given, the device is configured as a device alias.
+Note that alias_filename must match the device name.
 .TP
 .BI \-d " debug-level"
 Specify the level of debugging options.
diff --git a/mkfs/f2fs_format_main.c b/mkfs/f2fs_format_main.c
index 8d44a9b..99d92c5 100644
--- a/mkfs/f2fs_format_main.c
+++ b/mkfs/f2fs_format_main.c
@@ -191,6 +191,7 @@ static void f2fs_parse_options(int argc, char *argv[])
 	int32_t option=0;
 	int val;
 	char *token;
+	bool is_alias;
 	int dev_num;
 
 	while ((option = getopt_long(argc,argv,option_string,long_opts,NULL)) != EOF) {
@@ -218,6 +219,8 @@ static void f2fs_parse_options(int argc, char *argv[])
 				mkfs_usage();
 			}
 
+			is_alias = (strchr(optarg, '@') != NULL);
+
 			token = strtok(optarg, "@");
 			if (strlen(token) > MAX_PATH_LEN) {
 				MSG(0, "Error: device path should be equal or "
@@ -226,21 +229,21 @@ static void f2fs_parse_options(int argc, char *argv[])
 				mkfs_usage();
 			}
 			c.devices[dev_num].path = strdup(token);
-			token = strtok(NULL, "");
-			if (token) {
-				if (strlen(token) > MAX_PATH_LEN) {
-					MSG(0, "Error: alias_filename should "
-						"be equal or less than %d "
-						"characters\n", MAX_PATH_LEN);
-					mkfs_usage();
-				}
-				if (strchr(token, '/')) {
-					MSG(0, "Error: alias_filename has "
-						"invalid '/' character\n");
+
+			if (is_alias) {
+				char *dev_name = strrchr(token, '/');
+
+				dev_name = dev_name ? dev_name + 1 : token;
+
+				token = strtok(NULL, "");
+				if (token && strcmp(token, dev_name)) {
+					MSG(0,
+						"Error: alias_filename (\"%s\") must match device name (\"%s\")\n",
+						token, dev_name);
 					mkfs_usage();
 				}
 				c.devices[dev_num].alias_filename =
-					strdup(token);
+					strdup(dev_name);
 				if (!c.aliased_devices)
 					c.feature |= F2FS_FEATURE_DEVICE_ALIAS;
 				c.aliased_devices++;
-- 
2.55.0.887.g758fc8c411-goog


                 reply	other threads:[~2026-08-26 18:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260826181121.3825702-1-daeho43@gmail.com \
    --to=daeho43@gmail.com \
    --cc=daehojeong@google.com \
    --cc=kernel-team@android.com \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=qiwenjie@xiaomi.com \
    --cc=stable@vger.kernel.org \
    /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®