Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ext2: add support to various inode sizes #92

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions hachoir/parser/file_system/ext2.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,13 @@ class Inode(FieldSet):
7: "Reserved group descriptors",
8: "EXT3 journal"
}
static_size = (68 + 15 * 4) * 8

def __init__(self, parent, name, index):
FieldSet.__init__(self, parent, name, None)
inode_size = self["/superblock/inode_size"].value
if inode_size == 0:
inode_size = 128
self._size = inode_size * 8
self.uniq_id = 1 + index

def createDescription(self):
Expand Down Expand Up @@ -751,7 +754,10 @@ def validate(self):
return "Invalid magic number"
if not (0 <= self["superblock/log_block_size"].value <= 2):
return "Invalid (log) block size"
if self["superblock/inode_size"].value not in (0, 128):
blocksize = (1 << 10) << self["superblock/log_block_size"].value
acceptable_inode_sizes = (s for s in [0, 128, 256, 512, 1024, 2048, 4096]
if s <= blocksize)
if self["superblock/inode_size"].value not in acceptable_inode_sizes:
return "Unsupported inode size"
return True

Expand Down
Binary file added tests/files/bsize-1024-isize-1024.ext2
Binary file not shown.
Binary file added tests/files/bsize-2048-isize-512.ext2
Binary file not shown.
Binary file added tests/files/bsize-4096-isize-128.ext2
Binary file not shown.
10 changes: 10 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,16 @@ def test_ext2_variety_inode_types(self):
self.checkDesc(parser, "/group[0]/inode_table/inode[12]",
"Inode 13: Symbolic link (-> XYZ), size=3 bytes, mode=lrwxrwxrwx")

def test_ext2_various_inode_sizes(self):
for bsize, isize in [(1024, 1024), (2048, 512), (4096, 128)]:
fname = "bsize-%d-isize-%d.ext2" % (bsize, isize)
parser = self.parse(fname)
self.checkValue(parser, "/superblock/inode_size", isize)
self.checkValue(parser, "/group[0]/inode_table/inode[11]/size", 6)
self.checkDesc(parser, "/group[0]/inode_table/inode[12]",
"Inode 13: Symbolic link (-> source), size=6 bytes, mode=lrwxrwxrwx")
self.checkValue(parser, "/group[0]/inode[11]block[0]", b"hello\n" + b'\0' * (bsize - 6))

def test_bmp2(self):
parser = self.parse("article01.bmp")
self.checkDisplay(parser, "/header/red_mask", '0x00ff0000')
Expand Down
Loading