Fix issues with big-endian system
authorbranzhu <branzhu@outlook.com>
Fri, 24 Mar 2017 04:51:51 +0000 (00:51 -0400)
committerbranzhu <branzhu@outlook.com>
Fri, 24 Mar 2017 04:51:51 +0000 (00:51 -0400)
include/ext4_types.h
src/ext4_fs.c
src/ext4_mkfs.c

index 2d9e49cb2fd65c9cfe749557dcc4f5b401188d5e..80e9a0f0f275b556bb419d5d0a804e0e90c9d298 100644 (file)
@@ -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:
index 5cc317abf48cb89875a63e47a3299c59c71f3560..0e0ae1545c7f3590799c99213993ebdd40f249f6 100644 (file)
@@ -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);
index 81867d6af237b41416cd85e0296d16aa473265d1..cd27c681d739f7389091ffeb6f2ed62a16632f64 100644 (file)
@@ -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);