[PATCH 6/8] fs: ext4: support files exceeding 4G

Ahmad Fatoum a.fatoum at pengutronix.de
Tue Feb 16 15:02:06 EST 2021


ext4 redefines directory ACL to hold the most-significant 32-bit of the
inode size for regular files. For directories, it can either be ACL or,
when using largedir, the most-significant 32-bit of the directory size.

Adapt the code take these upper 32-bit into consideration for
determining regular file size. For directories, behavior remains
unchanged as we neither support ACLs nor >= 4G directories

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 fs/ext4/ext4fs.c      | 2 +-
 fs/ext4/ext_barebox.c | 2 +-
 fs/ext4/ext_common.h  | 9 +++++++++
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c
index be643a448761..54349aad3f3f 100644
--- a/fs/ext4/ext4fs.c
+++ b/fs/ext4/ext4fs.c
@@ -55,7 +55,7 @@ loff_t ext4fs_read_file(struct ext2fs_node *node, loff_t pos,
 	int log2blocksize = LOG2_EXT2_BLOCK_SIZE(node->data);
 	const int blockshift = log2blocksize + DISK_SECTOR_BITS;
 	const int blocksize = 1 << blockshift;
-	unsigned int filesize = le32_to_cpu(node->inode.size);
+	loff_t filesize = ext4_isize(node);
 	ssize_t ret;
 	struct ext_filesystem *fs = node->data->fs;
 
diff --git a/fs/ext4/ext_barebox.c b/fs/ext4/ext_barebox.c
index a68a783e1c8a..8f318a49c008 100644
--- a/fs/ext4/ext_barebox.c
+++ b/fs/ext4/ext_barebox.c
@@ -221,7 +221,7 @@ struct inode *ext_get_inode(struct super_block *sb, int ino)
 
 	inode->i_ino = ino;
 	inode->i_mode = le16_to_cpu(node->inode.mode);
-	inode->i_size = le32_to_cpu(node->inode.size);
+	inode->i_size = ext4_isize(node);
 
 	switch (inode->i_mode & S_IFMT) {
 	default:
diff --git a/fs/ext4/ext_common.h b/fs/ext4/ext_common.h
index 350cc6efe535..37575d2a1aea 100644
--- a/fs/ext4/ext_common.h
+++ b/fs/ext4/ext_common.h
@@ -232,4 +232,13 @@ struct ext2_data {
 	struct ext4fs_indir_block indir1, indir2, indir3;
 };
 
+static inline loff_t ext4_isize(struct ext2fs_node *node)
+{
+        if (S_ISREG(le16_to_cpu(node->inode.mode)))
+                return ((loff_t)le32_to_cpu(node->inode.size_high) << 32) |
+                        le32_to_cpu(node->inode.size);
+
+        return (loff_t) le32_to_cpu(node->inode.size);
+}
+
 #endif
-- 
2.29.2




More information about the barebox mailing list