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 1/4] fat: add fat_tmpfile()
Date: Thu, 26 Nov 2026 23:15:31 +0100 [thread overview]
Message-ID: <20261126-work-fat-tmpfile-v1-1-3bca7b2dbc20@kernel.org> (raw)
In-Reply-To: <20261126-work-fat-tmpfile-v1-0-3bca7b2dbc20@kernel.org>
FAT already knows how to deal with a file that is open but has no
directory entry. When an open file is unlinked fat_detach() resets
i_pos to 0. From then on __fat_write_inode() has nothing to write, the
data still goes to the file's cluster chain, and fat_evict_inode()
frees the chain when the last reference is put.
An O_TMPFILE is a file that starts out in that state. So build the
inode like fat_build_inode() does, from a directory entry that only
exists in memory, but don't attach it. fat_build_inode() itself can't
be used for this. It would attach the inode at i_pos 0 and the next
O_TMPFILE would find it through fat_iget().
The mode is ignored, just like in vfat_create() and msdos_create(). On
FAT it's derived from the mount options.
Nothing uses fat_tmpfile() yet. vfat and msdos need a ->link() method
first and wire it up in the following patches.
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
fs/fat/fat.h | 2 ++
fs/fat/inode.c | 31 +++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/fs/fat/fat.h b/fs/fat/fat.h
index a8a3ca4f465bf..cc706d89d1b96 100644
--- a/fs/fat/fat.h
+++ b/fs/fat/fat.h
@@ -423,6 +423,8 @@ extern void fat_detach(struct inode *inode);
extern struct inode *fat_iget(struct super_block *sb, loff_t i_pos);
extern struct inode *fat_build_inode(struct super_block *sb,
struct msdos_dir_entry *de, loff_t i_pos);
+int fat_tmpfile(const struct mnt_idmap *idmap, struct inode *dir,
+ struct file *file, umode_t mode);
extern int fat_fill_super(struct super_block *sb, struct fs_context *fc,
void (*setup)(struct super_block *));
extern int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de);
diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index 642e690632d83..1481ef1a3efac 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -626,6 +626,37 @@ struct inode *fat_build_inode(struct super_block *sb,
EXPORT_SYMBOL_GPL(fat_build_inode);
+/* Like an open file that got unlinked: no directory entry, i_pos is 0. */
+int fat_tmpfile(const struct mnt_idmap *idmap, struct inode *dir,
+ struct file *file, umode_t mode)
+{
+ struct super_block *sb = dir->i_sb;
+ struct msdos_dir_entry de = { .attr = ATTR_ARCH };
+ struct timespec64 ts = current_time(dir);
+ struct inode *inode;
+ int err;
+
+ fat_time_unix2fat(MSDOS_SB(sb), &ts, &de.time, &de.date, &de.ctime_cs);
+ de.ctime = de.time;
+ de.cdate = de.date;
+ de.adate = de.date;
+
+ inode = new_inode(sb);
+ if (!inode)
+ return -ENOMEM;
+ inode->i_ino = iunique(sb, MSDOS_ROOT_INO);
+ inode_set_iversion(inode, 1);
+ err = fat_fill_inode(inode, &de);
+ if (err) {
+ iput(inode);
+ return err;
+ }
+ insert_inode_hash(inode);
+ d_tmpfile(file, inode);
+ return finish_open_simple(file, 0);
+}
+EXPORT_SYMBOL_GPL(fat_tmpfile);
+
static int __fat_write_inode(struct inode *inode);
static int fat_sync_inode_metadata(struct inode *inode,
--
2.53.0
next prev parent reply other threads:[~2026-11-26 22:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 22:15 [PATCH 0/4] fat: support O_TMPFILE Christian Brauner
2026-11-26 22:15 ` Christian Brauner [this message]
2026-11-26 22:15 ` [PATCH 2/4] fat: support O_TMPFILE on vfat Christian Brauner
2026-11-26 22:15 ` [PATCH 3/4] fat: support O_TMPFILE on msdos Christian Brauner
2026-11-26 22:15 ` [PATCH 4/4] selftests/filesystems: add FAT O_TMPFILE tests Christian Brauner
2026-11-27 8:43 ` [PATCH 0/4] fat: support O_TMPFILE Alexander Mikhalitsyn
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=20261126-work-fat-tmpfile-v1-1-3bca7b2dbc20@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