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

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