Fix ext2 non-working
Subsystems (2)
PATCH 1/1 Fix ext2 non-working
Hello, all?
Currently ext2ls, ext2load not working (I think sometimes it will work.) The reason is incorrect operations of ext2fs_read_inode and ext2fs_blockgroup.
I fix miscalculated block number(blkno) and offset (blkoff), and some hard coded values.
unsik Kim
---
Makefile +1 -0
@@ -403,6 +403,7 @@ TAG_SUBDIRS += fs/fat TAG_SUBDIRS += fs/fdos TAG_SUBDIRS += fs/jffs2 TAG_SUBDIRS += fs/yaffs2 +TAG_SUBDIRS += fs/ext2 TAG_SUBDIRS += net TAG_SUBDIRS += disk TAG_SUBDIRS += common
fs/ext2/ext2fs.c +22 -16
@@ -110,6 +110,7 @@ struct ext2_block_group {uint32_t inode_table_id;uint16_t free_blocks;uint16_t free_inodes; +uint16_t used_dir_cnt;uint16_t pad;uint32_t reserved[3 ]; };
@@ -182,14 +183,22 @@ int indir2_blkno = -1;static int ext2fs_blockgroup (struct ext2_data *data,int group,struct ext2_block_group *blkgrp) { +unsigned int blkno; +unsigned int blkoff; +unsigned int desc_per_blk; + + desc_per_blk =EXT2_BLOCK_SIZE (data) /sizeof (struct ext2_block_group ); + + blkno =__le32_to_cpu (data->sblock.first_data_block) +1 + + group / desc_per_blk; + blkoff = (group % desc_per_blk) *sizeof (struct ext2_block_group );#ifdef DEBUG -printf ("ext2fs read blockgroup\n" ); +printf ("ext2fs read %d group descriptor (blkno %d blkoff %d)\n" , + group, blkno, blkoff);#endif return (ext2fs_devread - (((__le32_to_cpu (data->sblock.first_data_block) + -1 ) <<LOG2_EXT2_BLOCK_SIZE (data)), - group *sizeof (struct ext2_block_group ), -sizeof (struct ext2_block_group ), (char *) blkgrp)); + (blkno <<LOG2_EXT2_BLOCK_SIZE (data), + blkoff,sizeof (struct ext2_block_group ), (char *)blkgrp)); }
@@ -203,11 +212,11 @@ static int ext2fs_read_inodeunsigned int blkno;unsigned int blkoff; -/* It is easier to calculate if the first inode is 0. */ - ino--;#ifdef DEBUG printf ("ext2fs read inode %d\n" , ino);#endif +/* It is easier to calculate if the first inode is 0. */ + ino--; status = ext2fs_blockgroup (data, ino / __le32_to_cpu (sblock->inodes_per_group),
@@ -215,19 +224,16 @@ static int ext2fs_read_inodeif (status ==0 ) {return (0 ); } - inodes_per_block =EXT2_BLOCK_SIZE (data) /128 ; - blkno = (ino %__le32_to_cpu (sblock->inodes_per_group)) / - inodes_per_block; - blkoff = (ino %__le32_to_cpu (sblock->inodes_per_group)) % - inodes_per_block; + inodes_per_block =EXT2_BLOCK_SIZE (data) /__le32_to_cpu (sblock->inode_size); + blkno = blkgrp.inode_table_id + + (ino %__le32_to_cpu (sblock->inodes_per_group)) / inodes_per_block; + blkoff = (ino % inodes_per_block) *__le32_to_cpu (sblock->inode_size);#ifdef DEBUG printf ("ext2fs read inode blkno %d blkoff %d\n" , blkno, blkoff);#endif /* Read the inode. */ - status =ext2fs_devread (((__le32_to_cpu (blkgrp.inode_table_id) + - blkno) <<LOG2_EXT2_BLOCK_SIZE (data)), -sizeof (struct ext2_inode ) * blkoff, -sizeof (struct ext2_inode ), (char *) inode); + status =ext2fs_devread (blkno <<LOG2_EXT2_BLOCK_SIZE (data), blkoff, +sizeof (struct ext2_inode ), (char *) inode);if (status ==0 ) {return (0 ); }
PATCH 1/1 Fix ext2 non-working
Dear unsik Kim,
Quoted 7 lines · In message <[email protected]> you…
Hello, all?
Currently ext2ls, ext2load not working (I think sometimes it will work.) The reason is incorrect operations of
ext2fs_read_inodeandext2fs_blockgroup.I fix miscalculated block number(blkno) and offset (blkoff), and some hard coded values.
Hm.... I tried the current code without your patch but I could not find any error case.
But with your patch applied, I got this:
=> ext2ls ide 0:4 bin
** ext2fs_devread() read outside partition sector 536870912
Failed to mount ext2 filesystem...
** Bad ext2 partition or disk - ide 0:4 **
I tested this on a PowerPC system (big endian). Any chance there might be some endianess issues with your patch?
Best regards,
Wolfgang Denk
Signature · 4 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de I read part of it all the way through.