[PATCH v2 1/6] fat: add fat_new_inode()
From: Christian Brauner
Date: Mon Nov 30 2026 - 03:57:56 EST
Move allocating and filling in the inode out of fat_build_inode() into
fat_new_inode(). The O_TMPFILE support in the following patches needs
an inode built the same way but without attaching it.
No functional changes.
Suggested-by: OGAWA Hirofumi <hirofumi@xxxxxxxxxxxxxxxxxx>
Signed-off-by: Christian Brauner (Amutable) <brauner@xxxxxxxxxx>
---
fs/fat/inode.c | 35 ++++++++++++++++++++++-------------
1 file changed, 22 insertions(+), 13 deletions(-)
diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index 642e690632d83..25b9d8e3bb7de 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -582,6 +582,26 @@ int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de)
return 0;
}
+/* Build an inode from @de without attaching or hashing it. */
+static struct inode *fat_new_inode(struct super_block *sb,
+ struct msdos_dir_entry *de)
+{
+ struct inode *inode;
+ int err;
+
+ inode = new_inode(sb);
+ if (!inode)
+ return ERR_PTR(-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_PTR(err);
+ }
+ return inode;
+}
+
static inline void fat_lock_build_inode(struct msdos_sb_info *sbi)
{
if (sbi->options.nfs == FAT_NFS_NOSTALE_RO)
@@ -598,25 +618,14 @@ struct inode *fat_build_inode(struct super_block *sb,
struct msdos_dir_entry *de, loff_t i_pos)
{
struct inode *inode;
- int err;
fat_lock_build_inode(MSDOS_SB(sb));
inode = fat_iget(sb, i_pos);
if (inode)
goto out;
- inode = new_inode(sb);
- if (!inode) {
- inode = ERR_PTR(-ENOMEM);
- goto out;
- }
- inode->i_ino = iunique(sb, MSDOS_ROOT_INO);
- inode_set_iversion(inode, 1);
- err = fat_fill_inode(inode, de);
- if (err) {
- iput(inode);
- inode = ERR_PTR(err);
+ inode = fat_new_inode(sb, de);
+ if (IS_ERR(inode))
goto out;
- }
fat_attach(inode, i_pos);
insert_inode_hash(inode);
out:
--
2.53.0