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

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