mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	 "Christian Brauner (Amutable)" <brauner@kernel.org>
Subject: [PATCH v2 2/6] fat: add msdos_format_new_name()
Date: Mon, 30 Nov 2026 09:57:07 +0100	[thread overview]
Message-ID: <20261130-work-fat-tmpfile-v2-2-99af97d95683@kernel.org> (raw)
In-Reply-To: <20261130-work-fat-tmpfile-v2-0-99af97d95683@kernel.org>

msdos_create() and msdos_mkdir() both format the new name, figure out
whether it's hidden and refuse it if it clashes with an existing entry
because of foo vs. .foo. Move that into msdos_format_new_name(). The
msdos O_TMPFILE support in the following patches uses it as well.

No functional changes.

Suggested-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
 fs/fat/namei_msdos.c | 40 ++++++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 18 deletions(-)

diff --git a/fs/fat/namei_msdos.c b/fs/fat/namei_msdos.c
index 5a43d042eb01f..36e6a14f1b134 100644
--- a/fs/fat/namei_msdos.c
+++ b/fs/fat/namei_msdos.c
@@ -262,6 +262,26 @@ static int msdos_add_entry(struct inode *dir, const unsigned char *name,
 	return 0;
 }
 
+/***** Formats the name of a new entry. Rejects foo vs. .foo clashes. */
+static int msdos_format_new_name(struct inode *dir, struct dentry *dentry,
+				 unsigned char *msdos_name, int *is_hid)
+{
+	struct fat_slot_info sinfo;
+	int err;
+
+	err = msdos_format_name(dentry->d_name.name, dentry->d_name.len,
+				msdos_name, &MSDOS_SB(dir->i_sb)->options);
+	if (err)
+		return err;
+	*is_hid = (dentry->d_name.name[0] == '.') && (msdos_name[0] != '.');
+	/* Have to do it due to foo vs. .foo conflicts */
+	if (!fat_scan(dir, msdos_name, &sinfo)) {
+		brelse(sinfo.bh);
+		return -EINVAL;
+	}
+	return 0;
+}
+
 /***** Create a file */
 static int msdos_create(const struct mnt_idmap *idmap, struct inode *dir,
 			struct dentry *dentry, umode_t mode)
@@ -275,17 +295,9 @@ static int msdos_create(const struct mnt_idmap *idmap, struct inode *dir,
 
 	mutex_lock(&MSDOS_SB(sb)->s_lock);
 
-	err = msdos_format_name(dentry->d_name.name, dentry->d_name.len,
-				msdos_name, &MSDOS_SB(sb)->options);
+	err = msdos_format_new_name(dir, dentry, msdos_name, &is_hid);
 	if (err)
 		goto out;
-	is_hid = (dentry->d_name.name[0] == '.') && (msdos_name[0] != '.');
-	/* Have to do it due to foo vs. .foo conflicts */
-	if (!fat_scan(dir, msdos_name, &sinfo)) {
-		brelse(sinfo.bh);
-		err = -EINVAL;
-		goto out;
-	}
 
 	ts = current_time(dir);
 	err = msdos_add_entry(dir, msdos_name, 0, is_hid, 0, &ts, &sinfo);
@@ -358,17 +370,9 @@ static struct dentry *msdos_mkdir(const struct mnt_idmap *idmap, struct inode *d
 
 	mutex_lock(&MSDOS_SB(sb)->s_lock);
 
-	err = msdos_format_name(dentry->d_name.name, dentry->d_name.len,
-				msdos_name, &MSDOS_SB(sb)->options);
+	err = msdos_format_new_name(dir, dentry, msdos_name, &is_hid);
 	if (err)
 		goto out;
-	is_hid = (dentry->d_name.name[0] == '.') && (msdos_name[0] != '.');
-	/* foo vs .foo situation */
-	if (!fat_scan(dir, msdos_name, &sinfo)) {
-		brelse(sinfo.bh);
-		err = -EINVAL;
-		goto out;
-	}
 
 	ts = current_time(dir);
 	cluster = fat_alloc_new_dir(dir, &ts);

-- 
2.53.0


  parent reply	other threads:[~2026-11-30  8:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  8:57 [PATCH v2 0/6] fat: support O_TMPFILE Christian Brauner
2026-11-30  8:57 ` [PATCH v2 1/6] fat: add fat_new_inode() Christian Brauner
2026-11-30  8:57 ` Christian Brauner [this message]
2026-11-30  8:57 ` [PATCH v2 3/6] fat: add fat_tmpfile() Christian Brauner
2026-11-30  8:57 ` [PATCH v2 4/6] fat: support O_TMPFILE on vfat Christian Brauner
2026-11-30  8:57 ` [PATCH v2 5/6] fat: support O_TMPFILE on msdos Christian Brauner
2026-11-30  8:57 ` [PATCH v2 6/6] selftests/filesystems: add FAT O_TMPFILE tests Christian Brauner

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=20261130-work-fat-tmpfile-v2-2-99af97d95683@kernel.org \
    --to=brauner@kernel.org \
    --cc=hirofumi@mail.parknet.co.jp \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@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®