0002-ext4-64bit-feature.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. From af7e95c32cea40c1e443ae301e64b27f068b4915 Mon Sep 17 00:00:00 2001
  2. From: Paulo Alcantara <pcacjr@zytor.com>
  3. Date: Wed, 11 Oct 2017 07:00:31 -0400
  4. Subject: [PATCH] ext4: Fix 64bit feature
  5. As per ext4 specification:
  6. > In ext2, ext3, and ext4 (when the 64bit feature is not enabled), the
  7. > block group descriptor was only 32 bytes long and therefore ends at
  8. > bg_checksum. On an ext4 filesystem with the 64bit feature enabled, the
  9. > block group descriptor expands to at least the 64 bytes described below;
  10. > the size is stored in the superblock.
  11. Since block group descriptor has been expanded to 64 bytes long (when 64
  12. bit feature is enabled), we cannot index ext2_group_desc and return it
  13. *directly* -- as we did it in ext2_get_group_desc -- it's still 32 bytes
  14. long.
  15. Instead, use s_desc_size field from superblock to correctly index and
  16. return block group descriptors.
  17. Cc: H. Peter Anvin <hpa@zytor.com>
  18. Cc: Gene Cumm <gene.cumm@gmail.com>
  19. Signed-off-by: Paulo Alcantara <pcacjr@zytor.com>
  20. ---
  21. core/fs/ext2/ext2.c | 23 ++++++++++++++---------
  22. core/fs/ext2/ext2_fs.h | 1 +
  23. 2 files changed, 15 insertions(+), 9 deletions(-)
  24. diff --git a/core/fs/ext2/ext2.c b/core/fs/ext2/ext2.c
  25. index 76bd1d5..4bc0a53 100644
  26. --- a/core/fs/ext2/ext2.c
  27. +++ b/core/fs/ext2/ext2.c
  28. @@ -25,22 +25,17 @@ static enum dirent_type ext2_cvt_type(unsigned int d_file_type)
  29. return inode_type[d_file_type];
  30. }
  31. -/*
  32. - * get the group's descriptor of group_num
  33. - */
  34. -static const struct ext2_group_desc *
  35. -ext2_get_group_desc(struct fs_info *fs, uint32_t group_num)
  36. +static const void *__ext2_get_group_desc(struct fs_info *fs, uint32_t group_num)
  37. {
  38. struct ext2_sb_info *sbi = EXT2_SB(fs);
  39. uint32_t desc_block, desc_index;
  40. - const struct ext2_group_desc *desc_data_block;
  41. + uint8_t *p;
  42. if (group_num >= sbi->s_groups_count) {
  43. printf ("ext2_get_group_desc"
  44. "block_group >= groups_count - "
  45. "block_group = %d, groups_count = %d",
  46. group_num, sbi->s_groups_count);
  47. -
  48. return NULL;
  49. }
  50. @@ -49,8 +44,17 @@ ext2_get_group_desc(struct fs_info *fs, uint32_t group_num)
  51. desc_block += sbi->s_first_data_block + 1;
  52. - desc_data_block = get_cache(fs->fs_dev, desc_block);
  53. - return &desc_data_block[desc_index];
  54. + p = get_cache(fs->fs_dev, desc_block);
  55. + return p + sbi->s_desc_size * desc_index;
  56. +}
  57. +
  58. +/*
  59. + * get the group's descriptor of group_num
  60. + */
  61. +static inline const struct ext2_group_desc *
  62. +ext2_get_group_desc(struct fs_info *fs, uint32_t group_num)
  63. +{
  64. + return __ext2_get_group_desc(fs, group_num);
  65. }
  66. /*
  67. @@ -306,6 +310,7 @@ static int ext2_fs_init(struct fs_info *fs)
  68. if (sb.s_desc_size < sizeof(struct ext2_group_desc))
  69. sb.s_desc_size = sizeof(struct ext2_group_desc);
  70. sbi->s_desc_per_block = BLOCK_SIZE(fs) / sb.s_desc_size;
  71. + sbi->s_desc_size = sb.s_desc_size;
  72. sbi->s_groups_count = (sb.s_blocks_count - sb.s_first_data_block
  73. + EXT2_BLOCKS_PER_GROUP(fs) - 1)
  74. / EXT2_BLOCKS_PER_GROUP(fs);
  75. diff --git a/core/fs/ext2/ext2_fs.h b/core/fs/ext2/ext2_fs.h
  76. index 803a995..d8d07eb 100644
  77. --- a/core/fs/ext2/ext2_fs.h
  78. +++ b/core/fs/ext2/ext2_fs.h
  79. @@ -278,6 +278,7 @@ struct ext2_sb_info {
  80. uint32_t s_first_data_block; /* First Data Block */
  81. int s_inode_size;
  82. uint8_t s_uuid[16]; /* 128-bit uuid for volume */
  83. + int s_desc_size; /* size of group descriptor */
  84. };
  85. static inline struct ext2_sb_info *EXT2_SB(struct fs_info *fs)
  86. --
  87. 2.7.4.GIT