X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=lwext4%2Fext4_block_group.h;h=92d57dfb97314c6128412d616d1632594f55051e;hb=b96145cb6c6083cbd57c9575a6ea52969babcb73;hp=e76d1cabc7591e5d1a2662eb265170d4cb96e64f;hpb=c6a76b0c566f6cc4fd0d7a956cdf9739912944d7;p=lwext4.git diff --git a/lwext4/ext4_block_group.h b/lwext4/ext4_block_group.h index e76d1ca..92d57df 100644 --- a/lwext4/ext4_block_group.h +++ b/lwext4/ext4_block_group.h @@ -42,9 +42,13 @@ #ifndef EXT4_BLOCK_GROUP_H_ #define EXT4_BLOCK_GROUP_H_ -#include -#include -#include +#ifdef __cplusplus +extern "C" { +#endif + +#include "ext4_config.h" +#include "ext4_types.h" +#include "ext4_super.h" #include #include @@ -55,14 +59,30 @@ * @return Address of block with block bitmap */ static inline uint64_t ext4_bg_get_block_bitmap(struct ext4_bgroup *bg, - struct ext4_sblock *s) + struct ext4_sblock *s) { - uint64_t v = to_le32(bg->block_bitmap_lo); + uint64_t v = to_le32(bg->block_bitmap_lo); - if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) - v |= (uint64_t)to_le32(bg->block_bitmap_hi) << 32; + if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) + v |= (uint64_t)to_le32(bg->block_bitmap_hi) << 32; + + return v; +} + +/**@brief Set address of block with data block bitmap. + * @param bg pointer to block group + * @param s pointer to superblock + * @param blk block to set + * @return Address of block with block bitmap + */ +static inline void ext4_bg_set_block_bitmap(struct ext4_bgroup *bg, + struct ext4_sblock *s, uint64_t blk) +{ + + bg->block_bitmap_lo = to_le32(blk); + if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) + bg->block_bitmap_hi = to_le32(blk >> 32); - return v; } /**@brief Get address of block with i-node bitmap. @@ -71,17 +91,33 @@ static inline uint64_t ext4_bg_get_block_bitmap(struct ext4_bgroup *bg, * @return Address of block with i-node bitmap */ static inline uint64_t ext4_bg_get_inode_bitmap(struct ext4_bgroup *bg, - struct ext4_sblock *s) + struct ext4_sblock *s) { - uint64_t v = to_le32(bg->inode_bitmap_lo); + uint64_t v = to_le32(bg->inode_bitmap_lo); + + if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) + v |= (uint64_t)to_le32(bg->inode_bitmap_hi) << 32; + + return v; +} - if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) - v |= (uint64_t)to_le32(bg->inode_bitmap_hi) << 32; +/**@brief Set address of block with i-node bitmap. + * @param bg Pointer to block group + * @param s Pointer to superblock + * @param blk block to set + * @return Address of block with i-node bitmap + */ +static inline void ext4_bg_set_inode_bitmap(struct ext4_bgroup *bg, + struct ext4_sblock *s, uint64_t blk) +{ + bg->inode_bitmap_lo = to_le32(blk); + if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) + bg->inode_bitmap_hi = to_le32(blk >> 32); - return v; } + /**@brief Get address of the first block of the i-node table. * @param bg Pointer to block group * @param s Pointer to superblock @@ -89,14 +125,29 @@ static inline uint64_t ext4_bg_get_inode_bitmap(struct ext4_bgroup *bg, */ static inline uint64_t ext4_bg_get_inode_table_first_block(struct ext4_bgroup *bg, - struct ext4_sblock *s) + struct ext4_sblock *s) { - uint64_t v = to_le32(bg->inode_table_first_block_lo); + uint64_t v = to_le32(bg->inode_table_first_block_lo); - if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) - v |= (uint64_t)to_le32(bg->inode_table_first_block_hi) << 32; + if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) + v |= (uint64_t)to_le32(bg->inode_table_first_block_hi) << 32; - return v; + return v; +} + +/**@brief Set address of the first block of the i-node table. + * @param bg Pointer to block group + * @param s Pointer to superblock + * @param blk block to set + * @return Address of first block of i-node table + */ +static inline void +ext4_bg_set_inode_table_first_block(struct ext4_bgroup *bg, + struct ext4_sblock *s, uint64_t blk) +{ + bg->inode_table_first_block_lo = to_le32(blk); + if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) + bg->inode_table_first_block_hi = to_le32(blk >> 32); } /**@brief Get number of free blocks in block group. @@ -105,14 +156,14 @@ ext4_bg_get_inode_table_first_block(struct ext4_bgroup *bg, * @return Number of free blocks in block group */ static inline uint32_t ext4_bg_get_free_blocks_count(struct ext4_bgroup *bg, - struct ext4_sblock *s) + struct ext4_sblock *s) { - uint32_t v = to_le16(bg->free_blocks_count_lo); + uint32_t v = to_le16(bg->free_blocks_count_lo); - if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) - v |= (uint32_t)to_le16(bg->free_blocks_count_hi) << 16; + if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) + v |= (uint32_t)to_le16(bg->free_blocks_count_hi) << 16; - return v; + return v; } /**@brief Set number of free blocks in block group. @@ -121,12 +172,12 @@ static inline uint32_t ext4_bg_get_free_blocks_count(struct ext4_bgroup *bg, * @param cnt Number of free blocks in block group */ static inline void ext4_bg_set_free_blocks_count(struct ext4_bgroup *bg, - struct ext4_sblock *s, - uint32_t cnt) + struct ext4_sblock *s, + uint32_t cnt) { - bg->free_blocks_count_lo = to_le16((cnt << 16) >> 16); - if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) - bg->free_blocks_count_hi = to_le16(cnt >> 16); + bg->free_blocks_count_lo = to_le16((cnt << 16) >> 16); + if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) + bg->free_blocks_count_hi = to_le16(cnt >> 16); } /**@brief Get number of free i-nodes in block group. @@ -135,14 +186,14 @@ static inline void ext4_bg_set_free_blocks_count(struct ext4_bgroup *bg, * @return Number of free i-nodes in block group */ static inline uint32_t ext4_bg_get_free_inodes_count(struct ext4_bgroup *bg, - struct ext4_sblock *s) + struct ext4_sblock *s) { - uint32_t v = to_le16(bg->free_inodes_count_lo); + uint32_t v = to_le16(bg->free_inodes_count_lo); - if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) - v |= (uint32_t)to_le16(bg->free_inodes_count_hi) << 16; + if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) + v |= (uint32_t)to_le16(bg->free_inodes_count_hi) << 16; - return v; + return v; } /**@brief Set number of free i-nodes in block group. @@ -151,12 +202,12 @@ static inline uint32_t ext4_bg_get_free_inodes_count(struct ext4_bgroup *bg, * @param cnt Number of free i-nodes in block group */ static inline void ext4_bg_set_free_inodes_count(struct ext4_bgroup *bg, - struct ext4_sblock *s, - uint32_t cnt) + struct ext4_sblock *s, + uint32_t cnt) { - bg->free_inodes_count_lo = to_le16((cnt << 16) >> 16); - if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) - bg->free_inodes_count_hi = to_le16(cnt >> 16); + bg->free_inodes_count_lo = to_le16((cnt << 16) >> 16); + if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) + bg->free_inodes_count_hi = to_le16(cnt >> 16); } /**@brief Get number of used directories in block group. @@ -165,14 +216,14 @@ static inline void ext4_bg_set_free_inodes_count(struct ext4_bgroup *bg, * @return Number of used directories in block group */ static inline uint32_t ext4_bg_get_used_dirs_count(struct ext4_bgroup *bg, - struct ext4_sblock *s) + struct ext4_sblock *s) { - uint32_t v = to_le16(bg->used_dirs_count_lo); + uint32_t v = to_le16(bg->used_dirs_count_lo); - if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) - v |= (uint32_t)to_le16(bg->used_dirs_count_hi) << 16; + if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) + v |= (uint32_t)to_le16(bg->used_dirs_count_hi) << 16; - return v; + return v; } /**@brief Set number of used directories in block group. @@ -181,12 +232,12 @@ static inline uint32_t ext4_bg_get_used_dirs_count(struct ext4_bgroup *bg, * @param cnt Number of used directories in block group */ static inline void ext4_bg_set_used_dirs_count(struct ext4_bgroup *bg, - struct ext4_sblock *s, - uint32_t cnt) + struct ext4_sblock *s, + uint32_t cnt) { - bg->used_dirs_count_lo = to_le16((cnt << 16) >> 16); - if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) - bg->used_dirs_count_hi = to_le16(cnt >> 16); + bg->used_dirs_count_lo = to_le16((cnt << 16) >> 16); + if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) + bg->used_dirs_count_hi = to_le16(cnt >> 16); } /**@brief Get number of unused i-nodes. @@ -195,15 +246,15 @@ static inline void ext4_bg_set_used_dirs_count(struct ext4_bgroup *bg, * @return Number of unused i-nodes */ static inline uint32_t ext4_bg_get_itable_unused(struct ext4_bgroup *bg, - struct ext4_sblock *s) + struct ext4_sblock *s) { - uint32_t v = to_le16(bg->itable_unused_lo); + uint32_t v = to_le16(bg->itable_unused_lo); - if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) - v |= (uint32_t)to_le16(bg->itable_unused_hi) << 16; + if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) + v |= (uint32_t)to_le16(bg->itable_unused_hi) << 16; - return v; + return v; } /**@brief Set number of unused i-nodes. @@ -212,12 +263,12 @@ static inline uint32_t ext4_bg_get_itable_unused(struct ext4_bgroup *bg, * @param cnt Number of unused i-nodes */ static inline void ext4_bg_set_itable_unused(struct ext4_bgroup *bg, - struct ext4_sblock *s, - uint32_t cnt) + struct ext4_sblock *s, + uint32_t cnt) { - bg->itable_unused_lo = to_le16((cnt << 16) >> 16); - if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) - bg->itable_unused_hi = to_le16(cnt >> 16); + bg->itable_unused_lo = to_le16((cnt << 16) >> 16); + if (ext4_sb_get_desc_size(s) > EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) + bg->itable_unused_hi = to_le16(cnt >> 16); } /**@brief Set checksum of block group. @@ -226,7 +277,7 @@ static inline void ext4_bg_set_itable_unused(struct ext4_bgroup *bg, */ static inline void ext4_bg_set_checksum(struct ext4_bgroup *bg, uint16_t crc) { - bg->checksum = to_le16(crc); + bg->checksum = to_le16(crc); } /**@brief Check if block group has a flag. @@ -236,7 +287,7 @@ static inline void ext4_bg_set_checksum(struct ext4_bgroup *bg, uint16_t crc) */ static inline bool ext4_bg_has_flag(struct ext4_bgroup *bg, uint32_t f) { - return to_le16(bg->flags) & f; + return to_le16(bg->flags) & f; } /**@brief Set flag of block group. @@ -245,9 +296,9 @@ static inline bool ext4_bg_has_flag(struct ext4_bgroup *bg, uint32_t f) */ static inline void ext4_bg_set_flag(struct ext4_bgroup *bg, uint32_t f) { - uint16_t flags = to_le16(bg->flags); - flags |= f; - bg->flags = to_le16(flags); + uint16_t flags = to_le16(bg->flags); + flags |= f; + bg->flags = to_le16(flags); } /**@brief Clear flag of block group. @@ -256,9 +307,9 @@ static inline void ext4_bg_set_flag(struct ext4_bgroup *bg, uint32_t f) */ static inline void ext4_bg_clear_flag(struct ext4_bgroup *bg, uint32_t f) { - uint16_t flags = to_le16(bg->flags); - flags &= ~f; - bg->flags = to_le16(flags); + uint16_t flags = to_le16(bg->flags); + flags &= ~f; + bg->flags = to_le16(flags); } /**@brief Calculate CRC16 of the block group.