From 7d16d1f663d41c08771f9cd348996e218ccb0723 Mon Sep 17 00:00:00 2001 From: Avi Deitcher Date: Fri, 28 Jun 2024 09:48:58 +0300 Subject: [PATCH] read GDT table from correct block Signed-off-by: Avi Deitcher --- filesystem/ext4/ext4.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/filesystem/ext4/ext4.go b/filesystem/ext4/ext4.go index df7121a9..660c3c1d 100644 --- a/filesystem/ext4/ext4.go +++ b/filesystem/ext4/ext4.go @@ -639,7 +639,16 @@ func Read(file util.File, size, start, sectorsize int64) (*FileSystem, error) { gdtSize := uint64(sb.groupDescriptorSize) * sb.blockGroupCount() gdtBytes := make([]byte, gdtSize) - n, err = file.ReadAt(gdtBytes, start+int64(BootSectorSize)+int64(SuperblockSize)) + // where do we find the GDT? + // - if blocksize is 1024, then 1024 padding for BootSector is block 0, 1024 for superblock is block 1 + // and then the GDT starts at block 2 + // - if blocksize is larger than 1024, then 1024 padding for BootSector followed by 1024 for superblock + // is block 0, and then the GDT starts at block 1 + gdtBlock := 1 + if sb.blockSize == 1024 { + gdtBlock = 2 + } + n, err = file.ReadAt(gdtBytes, start+int64(gdtBlock)*int64(sb.blockSize)) if err != nil { return nil, fmt.Errorf("could not read Group Descriptor Table bytes from file: %v", err) }