From: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Christian Brauner <brauner@kernel.org>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
Alexander Mikhalitsyn <alex@amutable.com>
Subject: Re: [PATCH v2 3/6] fat: add fat_tmpfile()
Date: Sat, 05 Dec 2026 16:43:47 +0900 [thread overview]
Message-ID: <875wx82mvg.fsf@mail.parknet.co.jp> (raw)
In-Reply-To: <20261130-work-fat-tmpfile-v2-3-99af97d95683@kernel.org>
Christian Brauner <brauner@kernel.org> writes:
> 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.
>
> Reviewed-by: Alexander Mikhalitsyn <alex@amutable.com>
> Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Thanks.
> ---
> fs/fat/fat.h | 2 ++
> fs/fat/inode.c | 23 +++++++++++++++++++++++
> 2 files changed, 25 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 25b9d8e3bb7de..b5ad61b004613 100644
> --- a/fs/fat/inode.c
> +++ b/fs/fat/inode.c
> @@ -635,6 +635,29 @@ 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;
> +
> + 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 = fat_new_inode(sb, &de);
> + if (IS_ERR(inode))
> + return PTR_ERR(inode);
> + 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,
--
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
next prev parent reply other threads:[~2026-12-05 7:43 UTC|newest]
Thread overview: 13+ 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-12-05 7:43 ` OGAWA Hirofumi
2026-11-30 8:57 ` [PATCH v2 2/6] fat: add msdos_format_new_name() Christian Brauner
2026-12-05 7:43 ` OGAWA Hirofumi
2026-11-30 8:57 ` [PATCH v2 3/6] fat: add fat_tmpfile() Christian Brauner
2026-12-05 7:43 ` OGAWA Hirofumi [this message]
2026-11-30 8:57 ` [PATCH v2 4/6] fat: support O_TMPFILE on vfat Christian Brauner
2026-12-05 7:44 ` OGAWA Hirofumi
2026-11-30 8:57 ` [PATCH v2 5/6] fat: support O_TMPFILE on msdos Christian Brauner
2026-12-05 7:44 ` OGAWA Hirofumi
2026-11-30 8:57 ` [PATCH v2 6/6] selftests/filesystems: add FAT O_TMPFILE tests Christian Brauner
2026-12-05 7:44 ` OGAWA Hirofumi
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=875wx82mvg.fsf@mail.parknet.co.jp \
--to=hirofumi@mail.parknet.co.jp \
--cc=akpm@linux-foundation.org \
--cc=alex@amutable.com \
--cc=brauner@kernel.org \
--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