|
|
@ -49,45 +49,45 @@ |
|
|
|
|
|
|
|
/****************************Unstandard access to superblock*****************/ |
|
|
|
|
|
|
|
/**@brief Blocks count get stored in superblock.
|
|
|
|
* @param s superblock descriptor |
|
|
|
* @return count of blocks*/ |
|
|
|
static inline uint64_t ext4_sb_get_blocks_cnt(struct ext4_sblock *s) |
|
|
|
/**@brief Blocks count get stored in superblock.
|
|
|
|
* @param s superblock descriptor |
|
|
|
* @return count of blocks*/ |
|
|
|
static inline uint64_t ext4_sb_get_blocks_cnt(struct ext4_sblock *s) |
|
|
|
{ |
|
|
|
return ((uint64_t) to_le32(s->blocks_count_hi) << 32) | |
|
|
|
to_le32(s->blocks_count_lo); |
|
|
|
} |
|
|
|
|
|
|
|
/**@brief Free blocks count get stored in superblock.
|
|
|
|
* @param s superblock descriptor |
|
|
|
* @return free blocks*/ |
|
|
|
static inline uint64_t ext4_sb_get_free_blocks_cnt(struct ext4_sblock *s) |
|
|
|
/**@brief Free blocks count get stored in superblock.
|
|
|
|
* @param s superblock descriptor |
|
|
|
* @return free blocks*/ |
|
|
|
static inline uint64_t ext4_sb_get_free_blocks_cnt(struct ext4_sblock *s) |
|
|
|
{ |
|
|
|
return ((uint64_t) to_le32(s->free_blocks_count_hi) << 32) | |
|
|
|
to_le32(s->free_blocks_count_lo); |
|
|
|
} |
|
|
|
|
|
|
|
/**@brief Free blocks count set.
|
|
|
|
* @param s superblock descriptor |
|
|
|
* @param cnt new value of free blocks*/ |
|
|
|
static inline void ext4_sb_set_free_blocks_cnt(struct ext4_sblock *s, |
|
|
|
/**@brief Free blocks count set.
|
|
|
|
* @param s superblock descriptor |
|
|
|
* @param cnt new value of free blocks*/ |
|
|
|
static inline void ext4_sb_set_free_blocks_cnt(struct ext4_sblock *s, |
|
|
|
uint64_t cnt) |
|
|
|
{ |
|
|
|
s->free_blocks_count_lo = to_le32((cnt << 32) >> 32); |
|
|
|
s->free_blocks_count_hi = to_le32(cnt >> 32); |
|
|
|
} |
|
|
|
|
|
|
|
/**@brief Block size get from superblock.
|
|
|
|
* @param s superblock descriptor |
|
|
|
* @return block size in bytes*/ |
|
|
|
static inline uint32_t ext4_sb_get_block_size(struct ext4_sblock *s) |
|
|
|
/**@brief Block size get from superblock.
|
|
|
|
* @param s superblock descriptor |
|
|
|
* @return block size in bytes*/ |
|
|
|
static inline uint32_t ext4_sb_get_block_size(struct ext4_sblock *s) |
|
|
|
{ |
|
|
|
return 1024 << to_le32(s->log_block_size); |
|
|
|
} |
|
|
|
|
|
|
|
/**@brief Block group descriptor size.
|
|
|
|
* @param s superblock descriptor |
|
|
|
* @return block group descriptor size in bytes*/ |
|
|
|
/**@brief Block group descriptor size.
|
|
|
|
* @param s superblock descriptor |
|
|
|
* @return block group descriptor size in bytes*/ |
|
|
|
static inline uint16_t ext4_sb_get_desc_size(struct ext4_sblock *s) |
|
|
|
{ |
|
|
|
uint16_t size = to_le16(s->desc_size); |
|
|
@ -98,19 +98,19 @@ static inline uint16_t ext4_sb_get_desc_size(struct ext4_sblock *s) |
|
|
|
|
|
|
|
/*************************Flags and features*********************************/ |
|
|
|
|
|
|
|
/**@brief Support check of flag.
|
|
|
|
* @param s superblock descriptor |
|
|
|
* @param v flag to check |
|
|
|
* @return true if flag is supported*/ |
|
|
|
/**@brief Support check of flag.
|
|
|
|
* @param s superblock descriptor |
|
|
|
* @param v flag to check |
|
|
|
* @return true if flag is supported*/ |
|
|
|
static inline bool ext4_sb_check_flag(struct ext4_sblock *s, uint32_t v) |
|
|
|
{ |
|
|
|
return to_le32(s->flags) & v; |
|
|
|
} |
|
|
|
|
|
|
|
/**@brief Support check of feature compatible.
|
|
|
|
* @param s superblock descriptor |
|
|
|
* @param v feature to check |
|
|
|
* @return true if feature is supported*/ |
|
|
|
/**@brief Support check of feature compatible.
|
|
|
|
* @param s superblock descriptor |
|
|
|
* @param v feature to check |
|
|
|
* @return true if feature is supported*/ |
|
|
|
static inline bool ext4_sb_check_feature_compatible(struct ext4_sblock *s, |
|
|
|
uint32_t v) |
|
|
|
{ |
|
|
@ -118,10 +118,10 @@ static inline bool ext4_sb_check_feature_compatible(struct ext4_sblock *s, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**@brief Support check of feature incompatible.
|
|
|
|
* @param s superblock descriptor |
|
|
|
* @param v feature to check |
|
|
|
* @return true if feature is supported*/ |
|
|
|
/**@brief Support check of feature incompatible.
|
|
|
|
* @param s superblock descriptor |
|
|
|
* @param v feature to check |
|
|
|
* @return true if feature is supported*/ |
|
|
|
static inline bool ext4_sb_check_feature_incompatible(struct ext4_sblock *s, |
|
|
|
uint32_t v) |
|
|
|
{ |
|
|
@ -129,10 +129,10 @@ static inline bool ext4_sb_check_feature_incompatible(struct ext4_sblock *s, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**@brief Support check of read only flag.
|
|
|
|
* @param s superblock descriptor |
|
|
|
* @param v flag to check |
|
|
|
* @return true if flag is supported*/ |
|
|
|
/**@brief Support check of read only flag.
|
|
|
|
* @param s superblock descriptor |
|
|
|
* @param v flag to check |
|
|
|
* @return true if flag is supported*/ |
|
|
|
static inline bool ext4_sb_check_read_only(struct ext4_sblock *s, uint32_t v) |
|
|
|
{ |
|
|
|
return to_le32(s->features_read_only) & v; |
|
|
@ -140,42 +140,42 @@ static inline bool ext4_sb_check_read_only(struct ext4_sblock *s, uint32_t v) |
|
|
|
|
|
|
|
/**************************More complex functions****************************/ |
|
|
|
|
|
|
|
/**@brief Returns a block group count.
|
|
|
|
* @param s superblock descriptor |
|
|
|
* @return count of block groups*/ |
|
|
|
/**@brief Returns a block group count.
|
|
|
|
* @param s superblock descriptor |
|
|
|
* @return count of block groups*/ |
|
|
|
uint32_t ext4_block_group_cnt(struct ext4_sblock *s); |
|
|
|
|
|
|
|
/**@brief Returns block count in block group
|
|
|
|
/**@brief Returns block count in block group
|
|
|
|
* (last block group may have less blocks) |
|
|
|
* @param s superblock descriptor |
|
|
|
* @param bgid block group id |
|
|
|
* @return blocks count*/ |
|
|
|
* @param s superblock descriptor |
|
|
|
* @param bgid block group id |
|
|
|
* @return blocks count*/ |
|
|
|
uint32_t ext4_blocks_in_group_cnt(struct ext4_sblock *s, uint32_t bgid); |
|
|
|
|
|
|
|
/**@brief Returns inodes count in block group
|
|
|
|
/**@brief Returns inodes count in block group
|
|
|
|
* (last block group may have less inodes) |
|
|
|
* @param s superblock descriptor |
|
|
|
* @param bgid block group id |
|
|
|
* @return inodes count*/ |
|
|
|
* @param s superblock descriptor |
|
|
|
* @param bgid block group id |
|
|
|
* @return inodes count*/ |
|
|
|
uint32_t ext4_inodes_in_group_cnt(struct ext4_sblock *s, uint32_t bgid); |
|
|
|
|
|
|
|
/***************************Read/write/check superblock**********************/ |
|
|
|
|
|
|
|
/**@brief Superblock write.
|
|
|
|
* @param bdev block device descriptor. |
|
|
|
* @param s superblock descruptor |
|
|
|
* @return Standard error code */ |
|
|
|
/**@brief Superblock write.
|
|
|
|
* @param bdev block device descriptor. |
|
|
|
* @param s superblock descruptor |
|
|
|
* @return Standard error code */ |
|
|
|
int ext4_sb_write(struct ext4_blockdev *bdev, struct ext4_sblock *s); |
|
|
|
|
|
|
|
/**@brief Superblock read.
|
|
|
|
* @param bdev block device descriptor. |
|
|
|
* @param s superblock descruptor |
|
|
|
* @return Standard error code */ |
|
|
|
/**@brief Superblock read.
|
|
|
|
* @param bdev block device descriptor. |
|
|
|
* @param s superblock descruptor |
|
|
|
* @return Standard error code */ |
|
|
|
int ext4_sb_read(struct ext4_blockdev *bdev, struct ext4_sblock *s); |
|
|
|
|
|
|
|
/**@brief Superblock simple validation.
|
|
|
|
* @param s superblock dsecriptor |
|
|
|
* @return true if OK*/ |
|
|
|
/**@brief Superblock simple validation.
|
|
|
|
* @param s superblock dsecriptor |
|
|
|
* @return true if OK*/ |
|
|
|
bool ext4_sb_check(struct ext4_sblock *s); |
|
|
|
|
|
|
|
|
|
|
|