Blame SOURCES/0002-ext4-Fix-64bit-feature.patch

21bee5
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
536a55
From: Paulo Alcantara <pcacjr@zytor.com>
536a55
Date: Wed, 11 Oct 2017 07:00:31 -0400
536a55
Subject: [PATCH] ext4: Fix 64bit feature
536a55
536a55
As per ext4 specification:
536a55
536a55
> In ext2, ext3, and ext4 (when the 64bit feature is not enabled), the
536a55
> block group descriptor was only 32 bytes long and therefore ends at
536a55
> bg_checksum. On an ext4 filesystem with the 64bit feature enabled, the
536a55
> block group descriptor expands to at least the 64 bytes described below;
536a55
> the size is stored in the superblock.
536a55
536a55
Since block group descriptor has been expanded to 64 bytes long (when 64
536a55
bit feature is enabled), we cannot index ext2_group_desc and return it
536a55
*directly* -- as we did it in ext2_get_group_desc -- it's still 32 bytes
536a55
long.
536a55
536a55
Instead, use s_desc_size field from superblock to correctly index and
536a55
return block group descriptors.
536a55
536a55
Cc: H. Peter Anvin <hpa@zytor.com>
536a55
Cc: Gene Cumm <gene.cumm@gmail.com>
536a55
Signed-off-by: Paulo Alcantara <pcacjr@zytor.com>
536a55
---
536a55
 core/fs/ext2/ext2.c    | 23 ++++++++++++++---------
536a55
 core/fs/ext2/ext2_fs.h |  1 +
536a55
 2 files changed, 15 insertions(+), 9 deletions(-)
536a55
536a55
diff --git a/core/fs/ext2/ext2.c b/core/fs/ext2/ext2.c
21bee5
index 76bd1d5a..4bc0a535 100644
536a55
--- a/core/fs/ext2/ext2.c
536a55
+++ b/core/fs/ext2/ext2.c
536a55
@@ -25,22 +25,17 @@ static enum dirent_type ext2_cvt_type(unsigned int d_file_type)
536a55
 	return inode_type[d_file_type];
536a55
 }
536a55
 
536a55
-/*
536a55
- * get the group's descriptor of group_num
536a55
- */
536a55
-static const struct ext2_group_desc *
536a55
-ext2_get_group_desc(struct fs_info *fs, uint32_t group_num)
536a55
+static const void *__ext2_get_group_desc(struct fs_info *fs, uint32_t group_num)
536a55
 {
536a55
     struct ext2_sb_info *sbi = EXT2_SB(fs);
536a55
     uint32_t desc_block, desc_index;
536a55
-    const struct ext2_group_desc *desc_data_block;
536a55
+    uint8_t *p;
536a55
 
536a55
     if (group_num >= sbi->s_groups_count) {
536a55
 	printf ("ext2_get_group_desc"
536a55
 		"block_group >= groups_count - "
536a55
 		"block_group = %d, groups_count = %d",
536a55
 		group_num, sbi->s_groups_count);
536a55
-
536a55
 	return NULL;
536a55
     }
536a55
 
536a55
@@ -49,8 +44,17 @@ ext2_get_group_desc(struct fs_info *fs, uint32_t group_num)
536a55
 
536a55
     desc_block += sbi->s_first_data_block + 1;
536a55
 
536a55
-    desc_data_block = get_cache(fs->fs_dev, desc_block);
536a55
-    return &desc_data_block[desc_index];
536a55
+    p = get_cache(fs->fs_dev, desc_block);
536a55
+    return p + sbi->s_desc_size * desc_index;
536a55
+}
536a55
+
536a55
+/*
536a55
+ * get the group's descriptor of group_num
536a55
+ */
536a55
+static inline const struct ext2_group_desc *
536a55
+ext2_get_group_desc(struct fs_info *fs, uint32_t group_num)
536a55
+{
536a55
+    return __ext2_get_group_desc(fs, group_num);
536a55
 }
536a55
 
536a55
 /*
536a55
@@ -306,6 +310,7 @@ static int ext2_fs_init(struct fs_info *fs)
536a55
     if (sb.s_desc_size < sizeof(struct ext2_group_desc))
536a55
 	sb.s_desc_size = sizeof(struct ext2_group_desc);
536a55
     sbi->s_desc_per_block   = BLOCK_SIZE(fs) / sb.s_desc_size;
536a55
+    sbi->s_desc_size = sb.s_desc_size;
536a55
     sbi->s_groups_count     = (sb.s_blocks_count - sb.s_first_data_block
536a55
 			       + EXT2_BLOCKS_PER_GROUP(fs) - 1)
536a55
 	                      / EXT2_BLOCKS_PER_GROUP(fs);
536a55
diff --git a/core/fs/ext2/ext2_fs.h b/core/fs/ext2/ext2_fs.h
21bee5
index 803a9954..d8d07ebd 100644
536a55
--- a/core/fs/ext2/ext2_fs.h
536a55
+++ b/core/fs/ext2/ext2_fs.h
536a55
@@ -278,6 +278,7 @@ struct ext2_sb_info {
536a55
     uint32_t s_first_data_block;	/* First Data Block */
536a55
     int      s_inode_size;
536a55
     uint8_t  s_uuid[16];	/* 128-bit uuid for volume */
536a55
+    int      s_desc_size;	/* size of group descriptor */
536a55
 };
536a55
 
536a55
 static inline struct ext2_sb_info *EXT2_SB(struct fs_info *fs)