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>,
	 Alexander Mikhalitsyn <alex@amutable.com>
Subject: [PATCH v2 5/6] fat: support O_TMPFILE on msdos
Date: Mon, 30 Nov 2026 09:57:10 +0100	[thread overview]
Message-ID: <20261130-work-fat-tmpfile-v2-5-99af97d95683@kernel.org> (raw)
In-Reply-To: <20261130-work-fat-tmpfile-v2-0-99af97d95683@kernel.org>

Do what vfat does. msdos_link() creates the directory entry the same
way msdos_create() does and handles ATTR_HIDDEN like do_msdos_rename().
With the dots mount option a leading dot means the file is hidden and
__fat_write_inode() writes the attributes from i_attrs. So i_attrs has
to agree with the new name.

Reviewed-by: Alexander Mikhalitsyn <alex@amutable.com>
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
 fs/fat/namei_msdos.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/fs/fat/namei_msdos.c b/fs/fat/namei_msdos.c
index 36e6a14f1b134..14ef5d48d65e0 100644
--- a/fs/fat/namei_msdos.c
+++ b/fs/fat/namei_msdos.c
@@ -443,6 +443,67 @@ static int msdos_unlink(struct inode *dir, struct dentry *dentry)
 	return err;
 }
 
+/***** Give an O_TMPFILE its first name */
+static int msdos_link(struct dentry *old_dentry, struct inode *dir,
+		      struct dentry *dentry)
+{
+	struct inode *inode = d_inode(old_dentry);
+	struct super_block *sb = dir->i_sb;
+	struct fat_slot_info sinfo;
+	unsigned char msdos_name[MSDOS_NAME];
+	struct timespec64 ts;
+	int err, err2, is_hid, old_attrs;
+
+	/* FAT has no hard links. */
+	if (inode->i_nlink)
+		return -EPERM;
+
+	mutex_lock(&MSDOS_SB(sb)->s_lock);
+
+	err = msdos_format_new_name(dir, dentry, msdos_name, &is_hid);
+	if (err)
+		goto out;
+
+	ts = current_time(dir);
+	err = msdos_add_entry(dir, msdos_name, 0, is_hid, 0, &ts, &sinfo);
+	if (err)
+		goto out;
+	inode_inc_iversion(dir);
+
+	old_attrs = MSDOS_I(inode)->i_attrs;
+	fat_attach(inode, sinfo.i_pos);
+	if (is_hid)
+		MSDOS_I(inode)->i_attrs |= ATTR_HIDDEN;
+	else
+		MSDOS_I(inode)->i_attrs &= ~ATTR_HIDDEN;
+	mark_inode_dirty(inode);
+	if (IS_DIRSYNC(dir)) {
+		/* FIXME: this sync should be done within msdos_add_entry() */
+		err = sync_inode_metadata(inode, 1);
+		if (err)
+			goto out_detach;
+	}
+	brelse(sinfo.bh);
+
+	inc_nlink(inode);
+	ihold(inode);
+	d_instantiate(dentry, inode);
+	mutex_unlock(&MSDOS_SB(sb)->s_lock);
+	fat_flush_inodes(sb, dir, inode);
+	return 0;
+
+out_detach:
+	fat_detach(inode);
+	MSDOS_I(inode)->i_attrs = old_attrs;
+	err2 = fat_remove_entries(dir, &sinfo);	/* and releases bh */
+	if (err2)
+		fat_msg(sb, KERN_WARNING,
+			"failed to roll back new entry (%d)", err2);
+out:
+	mutex_unlock(&MSDOS_SB(sb)->s_lock);
+	return err;
+}
+
 static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name,
 			   struct dentry *old_dentry,
 			   struct inode *new_dir, unsigned char *new_name,
@@ -655,10 +716,12 @@ static int msdos_rename(const struct mnt_idmap *idmap,
 static const struct inode_operations msdos_dir_inode_operations = {
 	.create		= msdos_create,
 	.lookup		= msdos_lookup,
+	.link		= msdos_link,
 	.unlink		= msdos_unlink,
 	.mkdir		= msdos_mkdir,
 	.rmdir		= msdos_rmdir,
 	.rename		= msdos_rename,
+	.tmpfile	= fat_tmpfile,
 	.setattr	= fat_setattr,
 	.getattr	= fat_getattr,
 	.fileattr_get	= fat_fileattr_get,

-- 
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 ` [PATCH v2 2/6] fat: add msdos_format_new_name() Christian Brauner
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 ` Christian Brauner [this message]
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-5-99af97d95683@kernel.org \
    --to=brauner@kernel.org \
    --cc=alex@amutable.com \
    --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®