]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - fs/ext4/ext4_common.c
ext4: Fix handling of direntlen in unlink_filename
[people/ms/u-boot.git] / fs / ext4 / ext4_common.c
index 5f21dc794805ea7d3f32778fb0293db07c84530f..0c11ddb1b5891d5aa766d2d5f324d1593e490cbb 100644 (file)
@@ -47,6 +47,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);
@@ -54,24 +60,129 @@ static inline void ext4fs_sb_free_inodes_dec(struct ext2_sblock *sb)
 
 static inline void ext4fs_sb_free_blocks_dec(struct ext2_sblock *sb)
 {
-       sb->free_blocks = cpu_to_le32(le32_to_cpu(sb->free_blocks) - 1);
+       uint64_t free_blocks = le32_to_cpu(sb->free_blocks);
+       free_blocks += (uint64_t)le32_to_cpu(sb->free_blocks_high) << 32;
+       free_blocks--;
+
+       sb->free_blocks = cpu_to_le32(free_blocks & 0xffffffff);
+       sb->free_blocks_high = cpu_to_le16(free_blocks >> 32);
+}
+
+static inline void ext4fs_bg_free_inodes_dec
+       (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;
+       free_inodes--;
+
+       bg->free_inodes = cpu_to_le16(free_inodes & 0xffff);
+       if (fs->gdsize == 64)
+               bg->free_inodes_high = cpu_to_le16(free_inodes >> 16);
+}
+
+static inline void ext4fs_bg_free_blocks_dec
+       (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;
+       free_blocks--;
+
+       bg->free_blocks = cpu_to_le16(free_blocks & 0xffff);
+       if (fs->gdsize == 64)
+               bg->free_blocks_high = cpu_to_le16(free_blocks >> 16);
+}
+
+static inline void ext4fs_bg_itable_unused_dec
+       (struct ext2_block_group *bg, const struct ext_filesystem *fs)
+{
+       uint32_t free_inodes = le16_to_cpu(bg->bg_itable_unused);
+       if (fs->gdsize == 64)
+               free_inodes += le16_to_cpu(bg->bg_itable_unused_high) << 16;
+       free_inodes--;
+
+       bg->bg_itable_unused = cpu_to_le16(free_inodes & 0xffff);
+       if (fs->gdsize == 64)
+               bg->bg_itable_unused_high = cpu_to_le16(free_inodes >> 16);
+}
+
+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);
 }
 
-static inline void ext4fs_bg_free_inodes_dec(struct ext2_block_group *bg)
+uint32_t ext4fs_bg_get_free_blocks(const struct ext2_block_group *bg,
+                                  const struct ext_filesystem *fs)
 {
-       bg->free_inodes = cpu_to_le16(le16_to_cpu(bg->free_inodes) - 1);
+       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 void ext4fs_bg_free_blocks_dec(struct ext2_block_group *bg)
+static inline
+uint32_t ext4fs_bg_get_free_inodes(const struct ext2_block_group *bg,
+                                  const struct ext_filesystem *fs)
 {
-       bg->free_blocks = cpu_to_le16(le16_to_cpu(bg->free_blocks) - 1);
+       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 void ext4fs_bg_itable_unused_dec(struct ext2_block_group *bg)
+static inline uint16_t ext4fs_bg_get_flags(const struct ext2_block_group *bg)
 {
-       bg->bg_itable_unused = cpu_to_le16(le16_to_cpu(bg->bg_itable_unused) - 1);
+       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;
@@ -311,7 +422,7 @@ uint16_t ext4fs_checksum_update(uint32_t i)
        uint16_t crc = 0;
        __le32 le32_i = cpu_to_le32(i);
 
-       desc = (struct ext2_block_group *)&fs->bgd[i];
+       desc = ext4fs_get_group_descriptor(fs, i);
        if (le32_to_cpu(fs->sb->feature_ro_compat) & EXT4_FEATURE_RO_COMPAT_GDT_CSUM) {
                int offset = offsetof(struct ext2_block_group, bg_checksum);
 
@@ -743,42 +854,40 @@ fail:
 
 static int unlink_filename(char *filename, unsigned int blknr)
 {
-       int totalbytes = 0;
-       int templength = 0;
-       int status, inodeno;
-       int found = 0;
-       char *root_first_block_buffer = NULL;
+       int status;
+       int inodeno = 0;
+       int offset;
+       char *block_buffer = NULL;
        struct ext2_dirent *dir = NULL;
-       struct ext2_dirent *previous_dir = NULL;
-       char *ptr = NULL;
+       struct ext2_dirent *previous_dir;
        struct ext_filesystem *fs = get_fs();
        int ret = -1;
+       char *direntname;
 
-       /* get the first block of root */
-       root_first_block_buffer = zalloc(fs->blksz);
-       if (!root_first_block_buffer)
+       block_buffer = zalloc(fs->blksz);
+       if (!block_buffer)
                return -ENOMEM;
+
+       /* read the directory block */
        status = ext4fs_devread((lbaint_t)blknr * fs->sect_perblk, 0,
-                               fs->blksz, root_first_block_buffer);
+                               fs->blksz, block_buffer);
        if (status == 0)
                goto fail;
 
-       if (ext4fs_log_journal(root_first_block_buffer, blknr))
+       if (ext4fs_log_journal(block_buffer, blknr))
                goto fail;
-       dir = (struct ext2_dirent *)root_first_block_buffer;
-       ptr = (char *)dir;
-       totalbytes = 0;
-       while (le16_to_cpu(dir->direntlen) >= 0) {
-               /*
-                * blocksize-totalbytes because last
-                * directory length i.e., *dir->direntlen
-                * is free availble space in the block that
-                * means it is a last entry of directory entry
-                */
+       offset = 0;
+       do {
+               previous_dir = dir;
+               dir = (struct ext2_dirent *)(block_buffer + offset);
+               direntname = (char *)(dir) + sizeof(struct ext2_dirent);
+
+               int direntlen = le16_to_cpu(dir->direntlen);
+               if (direntlen < sizeof(struct ext2_dirent))
+                       break;
+
                if (dir->inode && (strlen(filename) == dir->namelen) &&
-                   (strncmp(ptr + sizeof(struct ext2_dirent),
-                            filename, dir->namelen) == 0)) {
-                       printf("file found, deleting\n");
+                   (strncmp(direntname, filename, dir->namelen) == 0)) {
                        inodeno = le32_to_cpu(dir->inode);
                        if (previous_dir) {
                                uint16_t new_len;
@@ -788,29 +897,21 @@ static int unlink_filename(char *filename, unsigned int blknr)
                        } else {
                                dir->inode = 0;
                        }
-                       found = 1;
                        break;
                }
 
-               if (fs->blksz - totalbytes == le16_to_cpu(dir->direntlen))
-                       break;
+               offset += direntlen;
 
-               /* traversing the each directory entry */
-               templength = le16_to_cpu(dir->direntlen);
-               totalbytes = totalbytes + templength;
-               previous_dir = dir;
-               dir = (struct ext2_dirent *)((char *)dir + templength);
-               ptr = (char *)dir;
-       }
+       } while (offset < fs->blksz);
 
+       if (inodeno > 0) {
 
-       if (found == 1) {
-               if (ext4fs_put_metadata(root_first_block_buffer, blknr))
+               if (ext4fs_put_metadata(block_buffer, blknr))
                        goto fail;
                ret = inodeno;
        }
 fail:
-       free(root_first_block_buffer);
+       free(block_buffer);
 
        return ret;
 }
@@ -851,39 +952,41 @@ uint32_t ext4fs_get_new_blk_no(void)
        char *zero_buffer = zalloc(fs->blksz);
        if (!journal_buffer || !zero_buffer)
                goto fail;
-       struct ext2_block_group *bgd = (struct ext2_block_group *)fs->gdtable;
 
        if (fs->first_pass_bbmap == 0) {
                for (i = 0; i < fs->no_blkgrp; i++) {
-                       if (le16_to_cpu(bgd[i].free_blocks)) {
-                               if (le16_to_cpu(bgd[i].bg_flags) & EXT4_BG_BLOCK_UNINIT) {
-                                       uint16_t new_flags;
-                                       put_ext4((uint64_t)le32_to_cpu(bgd[i].block_id) * fs->blksz,
-                                                zero_buffer, fs->blksz);
-                                       new_flags = le16_to_cpu(bgd[i].bg_flags) & ~EXT4_BG_BLOCK_UNINIT;
-                                       bgd[i].bg_flags = cpu_to_le16(new_flags);
+                       struct ext2_block_group *bgd = NULL;
+                       bgd = ext4fs_get_group_descriptor(fs, i);
+                       if (ext4fs_bg_get_free_blocks(bgd, fs)) {
+                               uint16_t bg_flags = ext4fs_bg_get_flags(bgd);
+                               uint64_t b_bitmap_blk =
+                                       ext4fs_bg_get_block_id(bgd, fs);
+                               if (bg_flags & EXT4_BG_BLOCK_UNINIT) {
                                        memcpy(fs->blk_bmaps[i], zero_buffer,
                                               fs->blksz);
+                                       put_ext4(b_bitmap_blk * fs->blksz,
+                                                fs->blk_bmaps[i], fs->blksz);
+                                       bg_flags &= ~EXT4_BG_BLOCK_UNINIT;
+                                       ext4fs_bg_set_flags(bgd, bg_flags);
                                }
                                fs->curr_blkno =
                                    _get_new_blk_no(fs->blk_bmaps[i]);
                                if (fs->curr_blkno == -1)
-                                       /* if block bitmap is completely fill */
+                                       /* block bitmap is completely filled */
                                        continue;
                                fs->curr_blkno = fs->curr_blkno +
                                                (i * fs->blksz * 8);
                                fs->first_pass_bbmap++;
-                               ext4fs_bg_free_blocks_dec(&bgd[i]);
+                               ext4fs_bg_free_blocks_dec(bgd, fs);
                                ext4fs_sb_free_blocks_dec(fs->sb);
-                               status = ext4fs_devread(
-                                                       (lbaint_t)le32_to_cpu(bgd[i].block_id) *
-                                                       fs->sect_perblk, 0,
-                                                       fs->blksz,
+                               status = ext4fs_devread(b_bitmap_blk *
+                                                       fs->sect_perblk,
+                                                       0, fs->blksz,
                                                        journal_buffer);
                                if (status == 0)
                                        goto fail;
                                if (ext4fs_log_journal(journal_buffer,
-                                                       le32_to_cpu(bgd[i].block_id)))
+                                                      b_bitmap_blk))
                                        goto fail;
                                goto success;
                        } else {
@@ -910,7 +1013,9 @@ restart:
                if (bg_idx >= fs->no_blkgrp)
                        goto fail;
 
-               if (bgd[bg_idx].free_blocks == 0) {
+               struct ext2_block_group *bgd = NULL;
+               bgd = ext4fs_get_group_descriptor(fs, bg_idx);
+               if (ext4fs_bg_get_free_blocks(bgd, fs) == 0) {
                        debug("block group %u is full. Skipping\n", bg_idx);
                        fs->curr_blkno = (bg_idx + 1) * blk_per_grp;
                        if (fs->blksz == 1024)
@@ -918,13 +1023,14 @@ restart:
                        goto restart;
                }
 
-               if (le16_to_cpu(bgd[bg_idx].bg_flags) & EXT4_BG_BLOCK_UNINIT) {
-                       uint16_t new_flags;
-                       put_ext4((uint64_t)le32_to_cpu(bgd[bg_idx].block_id) * fs->blksz,
-                                zero_buffer, fs->blksz);
+               uint16_t bg_flags = ext4fs_bg_get_flags(bgd);
+               uint64_t b_bitmap_blk = ext4fs_bg_get_block_id(bgd, fs);
+               if (bg_flags & EXT4_BG_BLOCK_UNINIT) {
                        memcpy(fs->blk_bmaps[bg_idx], zero_buffer, fs->blksz);
-                       new_flags = le16_to_cpu(bgd[bg_idx].bg_flags) & ~EXT4_BG_BLOCK_UNINIT;
-                       bgd[bg_idx].bg_flags = cpu_to_le16(new_flags);
+                       put_ext4(b_bitmap_blk * fs->blksz,
+                                zero_buffer, fs->blksz);
+                       bg_flags &= ~EXT4_BG_BLOCK_UNINIT;
+                       ext4fs_bg_set_flags(bgd, bg_flags);
                }
 
                if (ext4fs_set_block_bmap(fs->curr_blkno, fs->blk_bmaps[bg_idx],
@@ -937,19 +1043,16 @@ restart:
 
                /* journal backup */
                if (prev_bg_bitmap_index != bg_idx) {
-                       status = ext4fs_devread(
-                                               (lbaint_t)le32_to_cpu(bgd[bg_idx].block_id)
-                                               * fs->sect_perblk,
+                       status = ext4fs_devread(b_bitmap_blk * fs->sect_perblk,
                                                0, fs->blksz, journal_buffer);
                        if (status == 0)
                                goto fail;
-                       if (ext4fs_log_journal(journal_buffer,
-                                               le32_to_cpu(bgd[bg_idx].block_id)))
+                       if (ext4fs_log_journal(journal_buffer, b_bitmap_blk))
                                goto fail;
 
                        prev_bg_bitmap_index = bg_idx;
                }
-               ext4fs_bg_free_blocks_dec(&bgd[bg_idx]);
+               ext4fs_bg_free_blocks_dec(bgd, fs);
                ext4fs_sb_free_blocks_dec(fs->sb);
                goto success;
        }
@@ -977,46 +1080,49 @@ int ext4fs_get_new_inode_no(void)
        char *zero_buffer = zalloc(fs->blksz);
        if (!journal_buffer || !zero_buffer)
                goto fail;
-       struct ext2_block_group *bgd = (struct ext2_block_group *)fs->gdtable;
        int has_gdt_chksum = le32_to_cpu(fs->sb->feature_ro_compat) &
                EXT4_FEATURE_RO_COMPAT_GDT_CSUM ? 1 : 0;
 
        if (fs->first_pass_ibmap == 0) {
                for (i = 0; i < fs->no_blkgrp; i++) {
-                       if (bgd[i].free_inodes) {
+                       uint32_t free_inodes;
+                       struct ext2_block_group *bgd = NULL;
+                       bgd = ext4fs_get_group_descriptor(fs, i);
+                       free_inodes = ext4fs_bg_get_free_inodes(bgd, fs);
+                       if (free_inodes) {
+                               uint16_t bg_flags = ext4fs_bg_get_flags(bgd);
+                               uint64_t i_bitmap_blk =
+                                       ext4fs_bg_get_inode_id(bgd, fs);
                                if (has_gdt_chksum)
-                                       bgd[i].bg_itable_unused =
-                                               bgd[i].free_inodes;
-                               if (le16_to_cpu(bgd[i].bg_flags) & EXT4_BG_INODE_UNINIT) {
-                                       int new_flags;
-                                       put_ext4((uint64_t)le32_to_cpu(bgd[i].inode_id) * fs->blksz,
+                                       bgd->bg_itable_unused = free_inodes;
+                               if (bg_flags & EXT4_BG_INODE_UNINIT) {
+                                       put_ext4(i_bitmap_blk * fs->blksz,
                                                 zero_buffer, fs->blksz);
-                                       new_flags = le16_to_cpu(bgd[i].bg_flags) & ~EXT4_BG_INODE_UNINIT;
-                                       bgd[i].bg_flags = cpu_to_le16(new_flags);
+                                       bg_flags &= ~EXT4_BG_INODE_UNINIT;
+                                       ext4fs_bg_set_flags(bgd, bg_flags);
                                        memcpy(fs->inode_bmaps[i],
                                               zero_buffer, fs->blksz);
                                }
                                fs->curr_inode_no =
                                    _get_new_inode_no(fs->inode_bmaps[i]);
                                if (fs->curr_inode_no == -1)
-                                       /* if block bitmap is completely fill */
+                                       /* inode bitmap is completely filled */
                                        continue;
                                fs->curr_inode_no = fs->curr_inode_no +
                                                        (i * inodes_per_grp);
                                fs->first_pass_ibmap++;
-                               ext4fs_bg_free_inodes_dec(&bgd[i]);
+                               ext4fs_bg_free_inodes_dec(bgd, fs);
                                if (has_gdt_chksum)
-                                       ext4fs_bg_itable_unused_dec(&bgd[i]);
+                                       ext4fs_bg_itable_unused_dec(bgd, fs);
                                ext4fs_sb_free_inodes_dec(fs->sb);
-                               status = ext4fs_devread(
-                                                       (lbaint_t)le32_to_cpu(bgd[i].inode_id) *
-                                                       fs->sect_perblk, 0,
-                                                       fs->blksz,
+                               status = ext4fs_devread(i_bitmap_blk *
+                                                       fs->sect_perblk,
+                                                       0, fs->blksz,
                                                        journal_buffer);
                                if (status == 0)
                                        goto fail;
                                if (ext4fs_log_journal(journal_buffer,
-                                                       le32_to_cpu(bgd[i].inode_id)))
+                                                      i_bitmap_blk))
                                        goto fail;
                                goto success;
                        } else
@@ -1028,12 +1134,16 @@ restart:
                fs->curr_inode_no++;
                /* get the blockbitmap index respective to blockno */
                ibmap_idx = fs->curr_inode_no / inodes_per_grp;
-               if (le16_to_cpu(bgd[ibmap_idx].bg_flags) & EXT4_BG_INODE_UNINIT) {
-                       int new_flags;
-                       put_ext4((uint64_t)le32_to_cpu(bgd[ibmap_idx].inode_id) * fs->blksz,
+               struct ext2_block_group *bgd =
+                       ext4fs_get_group_descriptor(fs, ibmap_idx);
+               uint16_t bg_flags = ext4fs_bg_get_flags(bgd);
+               uint64_t i_bitmap_blk = ext4fs_bg_get_inode_id(bgd, fs);
+
+               if (bg_flags & EXT4_BG_INODE_UNINIT) {
+                       put_ext4(i_bitmap_blk * fs->blksz,
                                 zero_buffer, fs->blksz);
-                       new_flags = le16_to_cpu(bgd[ibmap_idx].bg_flags) & ~EXT4_BG_INODE_UNINIT;
-                       bgd[ibmap_idx].bg_flags = cpu_to_le16(new_flags);
+                       bg_flags &= ~EXT4_BG_INODE_UNINIT;
+                       ext4fs_bg_set_flags(bgd, bg_flags);
                        memcpy(fs->inode_bmaps[ibmap_idx], zero_buffer,
                                fs->blksz);
                }
@@ -1048,22 +1158,18 @@ restart:
 
                /* journal backup */
                if (prev_inode_bitmap_index != ibmap_idx) {
-                       memset(journal_buffer, '\0', fs->blksz);
-                       status = ext4fs_devread(
-                                               (lbaint_t)le32_to_cpu(bgd[ibmap_idx].inode_id)
-                                               * fs->sect_perblk,
+                       status = ext4fs_devread(i_bitmap_blk * fs->sect_perblk,
                                                0, fs->blksz, journal_buffer);
                        if (status == 0)
                                goto fail;
                        if (ext4fs_log_journal(journal_buffer,
-                                               le32_to_cpu(bgd[ibmap_idx].inode_id)))
+                                               le32_to_cpu(bgd->inode_id)))
                                goto fail;
                        prev_inode_bitmap_index = ibmap_idx;
                }
-               ext4fs_bg_free_inodes_dec(&bgd[ibmap_idx]);
+               ext4fs_bg_free_inodes_dec(bgd, fs);
                if (has_gdt_chksum)
-                       bgd[ibmap_idx].bg_itable_unused =
-                                       bgd[ibmap_idx].free_inodes;
+                       bgd->bg_itable_unused = bgd->free_inodes;
                ext4fs_sb_free_inodes_dec(fs->sb);
                goto success;
        }
@@ -1445,20 +1551,20 @@ static int ext4fs_blockgroup
        long int blkno;
        unsigned int blkoff, desc_per_blk;
        int log2blksz = get_fs()->dev_desc->log2blksz;
+       int desc_size = get_fs()->gdsize;
 
-       desc_per_blk = EXT2_BLOCK_SIZE(data) / sizeof(struct ext2_block_group);
+       desc_per_blk = EXT2_BLOCK_SIZE(data) / desc_size;
 
        blkno = le32_to_cpu(data->sblock.first_data_block) + 1 +
                        group / desc_per_blk;
-       blkoff = (group % desc_per_blk) * sizeof(struct ext2_block_group);
+       blkoff = (group % desc_per_blk) * desc_size;
 
        debug("ext4fs read %d group descriptor (blkno %ld blkoff %u)\n",
              group, blkno, blkoff);
 
        return ext4fs_devread((lbaint_t)blkno <<
                              (LOG2_BLOCK_SIZE(data) - log2blksz),
-                             blkoff, sizeof(struct ext2_block_group),
-                             (char *)blkgrp);
+                             blkoff, desc_size, (char *)blkgrp);
 }
 
 int ext4fs_read_inode(struct ext2_data *data, int ino, struct ext2_inode *inode)
@@ -1479,7 +1585,7 @@ int ext4fs_read_inode(struct ext2_data *data, int ino, struct ext2_inode *inode)
                return 0;
 
        inodes_per_block = EXT2_BLOCK_SIZE(data) / fs->inodesz;
-       blkno = le32_to_cpu(blkgrp.inode_table_id) +
+       blkno = ext4fs_bg_get_inode_table_id(&blkgrp, fs) +
            (ino % le32_to_cpu(sblock->inodes_per_group)) / inodes_per_block;
        blkoff = (ino % inodes_per_block) * fs->inodesz;
        /* Read the inode. */
@@ -2223,23 +2329,24 @@ int ext4fs_mount(unsigned part_length)
        if (le16_to_cpu(data->sblock.magic) != EXT2_MAGIC)
                goto fail;
 
-       /*
-        * The 64bit feature was enabled when metadata_csum was enabled
-        * and we do not support metadata_csum (and cannot reliably find
-        * files when it is set.  Refuse to mount.
-        */
-       if (le32_to_cpu(data->sblock.feature_incompat) & EXT4_FEATURE_INCOMPAT_64BIT) {
-               printf("Unsupported feature found (64bit, possibly metadata_csum), not mounting\n");
-               goto fail;
-       }
 
-       if (le32_to_cpu(data->sblock.revision_level) == 0)
+       if (le32_to_cpu(data->sblock.revision_level) == 0) {
                fs->inodesz = 128;
-       else
+       } else {
+               debug("EXT4 features COMPAT: %08x INCOMPAT: %08x RO_COMPAT: %08x\n",
+                     __le32_to_cpu(data->sblock.feature_compatibility),
+                     __le32_to_cpu(data->sblock.feature_incompat),
+                     __le32_to_cpu(data->sblock.feature_ro_compat));
+
                fs->inodesz = le16_to_cpu(data->sblock.inode_size);
+               fs->gdsize = le32_to_cpu(data->sblock.feature_incompat) &
+                       EXT4_FEATURE_INCOMPAT_64BIT ?
+                       le16_to_cpu(data->sblock.descriptor_size) : 32;
+       }
 
-       debug("EXT2 rev %d, inode_size %d\n",
-              le32_to_cpu(data->sblock.revision_level), fs->inodesz);
+       debug("EXT2 rev %d, inode_size %d, descriptor size %d\n",
+             le32_to_cpu(data->sblock.revision_level),
+             fs->inodesz, fs->gdsize);
 
        data->diropen.data = data;
        data->diropen.ino = 2;