From: branzhu Date: Fri, 24 Mar 2017 04:51:51 +0000 (-0400) Subject: Fix issues with big-endian system X-Git-Url: https://git.carlh.net/gitweb/?p=lwext4.git;a=commitdiff_plain;h=02eb05014ff09bbadca174a2924ff2bdbc69b97e Fix issues with big-endian system --- diff --git a/include/ext4_types.h b/include/ext4_types.h index 2d9e49c..80e9a0f 100644 --- a/include/ext4_types.h +++ b/include/ext4_types.h @@ -698,19 +698,20 @@ struct ext4_extent_header { ((struct ext4_extent_index *)(((char *)(__hdr__)) + \ sizeof(struct ext4_extent_header))) #define EXT_HAS_FREE_INDEX(__path__) \ - ((__path__)->header->entries_count < (__path__)->header->max_entries_count) + (to_le16((__path__)->header->entries_count) < \ + to_le16((__path__)->header->max_entries_count)) #define EXT_LAST_EXTENT(__hdr__) \ - (EXT_FIRST_EXTENT((__hdr__)) + (__hdr__)->entries_count - 1) + (EXT_FIRST_EXTENT((__hdr__)) + to_le16((__hdr__)->entries_count) - 1) #define EXT_LAST_INDEX(__hdr__) \ - (EXT_FIRST_INDEX((__hdr__)) + (__hdr__)->entries_count - 1) + (EXT_FIRST_INDEX((__hdr__)) + to_le16((__hdr__)->entries_count) - 1) #define EXT_MAX_EXTENT(__hdr__) \ - (EXT_FIRST_EXTENT((__hdr__)) + (__hdr__)->max_entries_count - 1) + (EXT_FIRST_EXTENT((__hdr__)) + to_le16((__hdr__)->max_entries_count) - 1) #define EXT_MAX_INDEX(__hdr__) \ - (EXT_FIRST_INDEX((__hdr__)) + (__hdr__)->max_entries_count - 1) + (EXT_FIRST_INDEX((__hdr__)) + to_le16((__hdr__)->max_entries_count) - 1) #define EXT4_EXTENT_TAIL_OFFSET(hdr) \ (sizeof(struct ext4_extent_header) + \ - (sizeof(struct ext4_extent) * (hdr)->max_entries_count)) + (sizeof(struct ext4_extent) * to_le16((hdr)->max_entries_count))) /* * ext4_ext_next_allocated_block: diff --git a/src/ext4_fs.c b/src/ext4_fs.c index 5cc317a..0e0ae15 100644 --- a/src/ext4_fs.c +++ b/src/ext4_fs.c @@ -431,7 +431,7 @@ static int ext4_fs_init_inode_table(struct ext4_block_group_ref *bg_ref) struct ext4_sblock *sb = &bg_ref->fs->sb; struct ext4_bgroup *bg = bg_ref->block_group; - uint32_t inode_size = ext4_get32(sb, inode_size); + uint32_t inode_size = ext4_get16(sb, inode_size); uint32_t block_size = ext4_sb_get_block_size(sb); uint32_t inodes_per_block = block_size / inode_size; uint32_t inodes_in_group = ext4_inodes_in_group_cnt(sb, bg_ref->index); diff --git a/src/ext4_mkfs.c b/src/ext4_mkfs.c index 81867d6..cd27c68 100644 --- a/src/ext4_mkfs.c +++ b/src/ext4_mkfs.c @@ -388,7 +388,7 @@ static int write_bgroups(struct ext4_blockdev *bd, struct fs_aux_info *aux_info, bg_free_blk); ext4_bg_set_free_inodes_count(bg_desc, - aux_info->sb, aux_info->sb->inodes_per_group); + aux_info->sb, to_le32(aux_info->sb->inodes_per_group)); ext4_bg_set_used_dirs_count(bg_desc, aux_info->sb, 0);