[PATCH v3 05/13] f2fs: move fscrypt to filesystem inode

Christian Brauner
2025-07-22T19:28:07Z

Move fscrypt data pointer into the filesystem's private inode and record
the offset from the embedded struct inode.

This will allow us to drop the fscrypt data pointer from struct inode
itself and move it into the filesystem's inode.

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
fs/f2fs/f2fs.h | 3 +++
fs/f2fs/super.c | 7 +++++++
2 files changed, 10 insertions(+)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 9333a22b9a01..14e69c00e679 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -905,6 +905,9 @@ struct f2fs_inode_info {

unsigned int atomic_write_cnt;
loff_t original_i_size; /* original i_size before atomic write */
+#ifdef CONFIG_FS_ENCRYPTION
+ struct fscrypt_inode_info *i_fscrypt_info; /* filesystem encryption info */
+#endif
};

static inline void get_read_extent_info(struct extent_info *ext,
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index bbf1dad6843f..969ba46990ea 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -1453,6 +1453,9 @@ static struct inode *f2fs_alloc_inode(struct super_block *sb)

/* Will be used by directory only */
fi->i_dir_level = F2FS_SB(sb)->dir_level;
+#ifdef CONFIG_FS_ENCRYPTION
+ fi->i_fscrypt_info = NULL;
+#endif

return &fi->vfs_inode;
}
@@ -3246,6 +3249,10 @@ void f2fs_quota_off_umount(struct super_block *sb)
#endif

static const struct super_operations f2fs_sops = {
+#ifdef CONFIG_FS_ENCRYPTION
+ .i_fscrypt = offsetof(struct f2fs_inode_info, i_fscrypt_info) -
+ offsetof(struct f2fs_inode_info, vfs_inode),
+#endif
.alloc_inode = f2fs_alloc_inode,
.free_inode = f2fs_free_inode,
.drop_inode = f2fs_drop_inode,

--
2.47.2