summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Brüns <stefan.bruens@rwth-aachen.de>2016-09-20 02:12:42 +0300
committerDongjin Kim <tobetter@gmail.com>2020-02-10 16:44:41 +0300
commit708f8ebd23228843b7092189346589b7d01269c9 (patch)
treea338462d161f7fca79e5bb8df1db9b335384b454
parent5533f101a2072efbba22839a1b2bcba59d8395eb (diff)
downloadu-boot-708f8ebd23228843b7092189346589b7d01269c9.tar.xz
ext4: Add helper functions for block group descriptor field access
The helper functions encapsulate access of the block group descriptors, independent of group descriptor size. The helpers also deal with the endianess of the fields, and with split fields like free_blocks/ free_blocks_high. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
-rw-r--r--fs/ext4/ext4_common.c82
-rw-r--r--fs/ext4/ext4_common.h12
2 files changed, 94 insertions, 0 deletions
diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
index d72ea18efe..4ddd4d1cf4 100644
--- a/fs/ext4/ext4_common.c
+++ b/fs/ext4/ext4_common.c
@@ -46,6 +46,12 @@ struct ext2_inode *g_parent_inode;
static int symlinknest;
#if defined(CONFIG_EXT4_WRITE)
+struct ext2_block_group *ext4fs_get_group_descriptor
+ (const struct ext_filesystem *fs, uint32_t bg_idx)
+{
+ return (struct ext2_block_group *)(fs->gdtable + (bg_idx * fs->gdsize));
+}
+
static inline void ext4fs_sb_free_inodes_dec(struct ext2_sblock *sb)
{
sb->free_inodes = cpu_to_le32(le32_to_cpu(sb->free_inodes) - 1);
@@ -71,6 +77,82 @@ static inline void ext4fs_bg_itable_unused_dec(struct ext2_block_group *bg)
bg->bg_itable_unused = cpu_to_le16(le16_to_cpu(bg->bg_itable_unused) - 1);
}
+uint64_t ext4fs_sb_get_free_blocks(const struct ext2_sblock *sb)
+{
+ uint64_t free_blocks = le32_to_cpu(sb->free_blocks);
+ free_blocks += (uint64_t)le32_to_cpu(sb->free_blocks_high) << 32;
+ return free_blocks;
+}
+
+void ext4fs_sb_set_free_blocks(struct ext2_sblock *sb, uint64_t free_blocks)
+{
+ sb->free_blocks = cpu_to_le32(free_blocks & 0xffffffff);
+ sb->free_blocks_high = cpu_to_le16(free_blocks >> 32);
+}
+
+uint32_t ext4fs_bg_get_free_blocks(const struct ext2_block_group *bg,
+ const struct ext_filesystem *fs)
+{
+ uint32_t free_blocks = le16_to_cpu(bg->free_blocks);
+ if (fs->gdsize == 64)
+ free_blocks += le16_to_cpu(bg->free_blocks_high) << 16;
+ return free_blocks;
+}
+
+static inline
+uint32_t ext4fs_bg_get_free_inodes(const struct ext2_block_group *bg,
+ const struct ext_filesystem *fs)
+{
+ uint32_t free_inodes = le16_to_cpu(bg->free_inodes);
+ if (fs->gdsize == 64)
+ free_inodes += le16_to_cpu(bg->free_inodes_high) << 16;
+ return free_inodes;
+}
+
+static inline uint16_t ext4fs_bg_get_flags(const struct ext2_block_group *bg)
+{
+ return le16_to_cpu(bg->bg_flags);
+}
+
+static inline void ext4fs_bg_set_flags(struct ext2_block_group *bg,
+ uint16_t flags)
+{
+ bg->bg_flags = cpu_to_le16(flags);
+}
+
+/* Block number of the block bitmap */
+uint64_t ext4fs_bg_get_block_id(const struct ext2_block_group *bg,
+ const struct ext_filesystem *fs)
+{
+ uint64_t block_nr = le32_to_cpu(bg->block_id);
+ if (fs->gdsize == 64)
+ block_nr += (uint64_t)le32_to_cpu(bg->block_id_high) << 32;
+ return block_nr;
+}
+
+/* Block number of the inode bitmap */
+uint64_t ext4fs_bg_get_inode_id(const struct ext2_block_group *bg,
+ const struct ext_filesystem *fs)
+{
+ uint64_t block_nr = le32_to_cpu(bg->inode_id);
+ if (fs->gdsize == 64)
+ block_nr += (uint64_t)le32_to_cpu(bg->inode_id_high) << 32;
+ return block_nr;
+}
+#endif
+
+/* Block number of the inode table */
+uint64_t ext4fs_bg_get_inode_table_id(const struct ext2_block_group *bg,
+ const struct ext_filesystem *fs)
+{
+ uint64_t block_nr = le32_to_cpu(bg->inode_table_id);
+ if (fs->gdsize == 64)
+ block_nr +=
+ (uint64_t)le32_to_cpu(bg->inode_table_id_high) << 32;
+ return block_nr;
+}
+
+#if defined(CONFIG_EXT4_WRITE)
uint32_t ext4fs_div_roundup(uint32_t size, uint32_t n)
{
uint32_t res = size / n;
diff --git a/fs/ext4/ext4_common.h b/fs/ext4/ext4_common.h
index cc9d0c5a5f..99d49e6e55 100644
--- a/fs/ext4/ext4_common.h
+++ b/fs/ext4/ext4_common.h
@@ -74,5 +74,17 @@ void ext4fs_allocate_blocks(struct ext2_inode *file_inode,
unsigned int total_remaining_blocks,
unsigned int *total_no_of_block);
void put_ext4(uint64_t off, void *buf, uint32_t size);
+struct ext2_block_group *ext4fs_get_group_descriptor
+ (const struct ext_filesystem *fs, uint32_t bg_idx);
+uint64_t ext4fs_bg_get_block_id(const struct ext2_block_group *bg,
+ const struct ext_filesystem *fs);
+uint64_t ext4fs_bg_get_inode_id(const struct ext2_block_group *bg,
+ const struct ext_filesystem *fs);
+uint64_t ext4fs_bg_get_inode_table_id(const struct ext2_block_group *bg,
+ const struct ext_filesystem *fs);
+uint64_t ext4fs_sb_get_free_blocks(const struct ext2_sblock *sb);
+void ext4fs_sb_set_free_blocks(struct ext2_sblock *sb, uint64_t free_blocks);
+uint32_t ext4fs_bg_get_free_blocks(const struct ext2_block_group *bg,
+ const struct ext_filesystem *fs);
#endif
#endif