Linux filesystem development
 help / color / mirror / Atom feed
From: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
To: Christian Brauner <brauner@kernel.org>
Cc: linux-kernel@vger.kernel.org,  linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 1/4] fat: add fat_tmpfile()
Date: Sat, 28 Nov 2026 16:49:38 +0900	[thread overview]
Message-ID: <87ecc5qtt9.fsf@mail.parknet.co.jp> (raw)
In-Reply-To: <20261126-work-fat-tmpfile-v1-1-3bca7b2dbc20@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.
>
> 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)
> +{

[...]

> +	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);

This part is almost copy of fat_build_inode(). Maybe it is better to add
as a new helper function to share with fat_build_inode().

Thanks.

> +	d_tmpfile(file, inode);
> +	return finish_open_simple(file, 0);
> +}
> +EXPORT_SYMBOL_GPL(fat_tmpfile);
-- 
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>

  reply	other threads:[~2026-11-28  7:59 UTC|newest]

Thread overview: 9+ 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 ` [PATCH 1/4] fat: add fat_tmpfile() Christian Brauner
2026-11-28  7:49   ` OGAWA Hirofumi [this message]
2026-11-26 22:15 ` [PATCH 2/4] fat: support O_TMPFILE on vfat Christian Brauner
2026-11-28  7:50   ` OGAWA Hirofumi
2026-11-26 22:15 ` [PATCH 3/4] fat: support O_TMPFILE on msdos Christian Brauner
2026-11-28  7:53   ` OGAWA Hirofumi
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=87ecc5qtt9.fsf@mail.parknet.co.jp \
    --to=hirofumi@mail.parknet.co.jp \
    --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