Skip to content

Commit

Permalink
Fix ext4 block group descriptor sizing
Browse files Browse the repository at this point in the history
Ext4 allows for arbitrarily sized block group descriptors when 64-bit
addressing is enabled, which was previously not properly supported. This
patch dynamically allocates a chunk of memory of the correct size.

Signed-off-by: Benjamin Lim <[email protected]>
  • Loading branch information
jarsp authored and trini committed Apr 10, 2019
1 parent e551979 commit febbc58
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions fs/ext4/ext4_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1587,25 +1587,36 @@ static int ext4fs_blockgroup

int ext4fs_read_inode(struct ext2_data *data, int ino, struct ext2_inode *inode)
{
struct ext2_block_group blkgrp;
struct ext2_block_group *blkgrp;
struct ext2_sblock *sblock = &data->sblock;
struct ext_filesystem *fs = get_fs();
int log2blksz = get_fs()->dev_desc->log2blksz;
int inodes_per_block, status;
long int blkno;
unsigned int blkoff;

/* Allocate blkgrp based on gdsize (for 64-bit support). */
blkgrp = zalloc(get_fs()->gdsize);
if (!blkgrp)
return 0;

/* It is easier to calculate if the first inode is 0. */
ino--;
status = ext4fs_blockgroup(data, ino / le32_to_cpu
(sblock->inodes_per_group), &blkgrp);
if (status == 0)
(sblock->inodes_per_group), blkgrp);
if (status == 0) {
free(blkgrp);
return 0;
}

inodes_per_block = EXT2_BLOCK_SIZE(data) / fs->inodesz;
blkno = ext4fs_bg_get_inode_table_id(&blkgrp, fs) +
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;

/* Free blkgrp as it is no longer required. */
free(blkgrp);

/* Read the inode. */
status = ext4fs_devread((lbaint_t)blkno << (LOG2_BLOCK_SIZE(data) -
log2blksz), blkoff,
Expand Down

0 comments on commit febbc58

Please sign in to comment.