Skip to content

Commit

Permalink
Merge pull request #232 from diskfs/fix-ext4-gdt-read
Browse files Browse the repository at this point in the history
read GDT table from correct block
  • Loading branch information
deitch authored Jun 28, 2024
2 parents 7062414 + 7d16d1f commit 13b7cc2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion filesystem/ext4/ext4.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 13b7cc2

Please sign in to comment.