Skip to content

Commit 6b4a2a1

Browse files
authored
Non 64-bit ext4 gdt (#311)
* ext4: GDT size set to 32 unless 64bit flag set Signed-off-by: Avi Deitcher <[email protected]> * handle GDT size 0 error Signed-off-by: Avi Deitcher <[email protected]> --------- Signed-off-by: Avi Deitcher <[email protected]>
1 parent 397e18e commit 6b4a2a1

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

filesystem/ext4/ext4.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,10 @@ func Read(b backend.Storage, size, start, sectorsize int64) (*FileSystem, error)
663663
// how big should the GDT be?
664664
gdtSize := uint64(sb.groupDescriptorSize) * sb.blockGroupCount()
665665

666+
if gdtSize == 0 {
667+
return nil, errors.New("calculated Group Descriptor Table size is zero")
668+
}
669+
666670
gdtBytes := make([]byte, gdtSize)
667671
// where do we find the GDT?
668672
// - if blocksize is 1024, then 1024 padding for BootSector is block 0, 1024 for superblock is block 1

filesystem/ext4/groupdescriptors.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ func (gds *groupDescriptors) equal(a *groupDescriptors) bool {
8787

8888
// groupDescriptorsFromBytes create a groupDescriptors struct from bytes
8989
func groupDescriptorsFromBytes(b []byte, gdSize uint16, hashSeed uint32, checksumType gdtChecksumType) (*groupDescriptors, error) {
90+
if gdSize == 0 {
91+
return nil, fmt.Errorf("group descriptor size cannot be zero")
92+
}
9093
gds := groupDescriptors{}
9194
gdSlice := make([]groupDescriptor, 0, 10)
9295

filesystem/ext4/superblock.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,10 @@ func superblockFromBytes(b []byte) (*superblock, error) {
347347

348348
sb.hashVersion = hashAlgorithm(b[0xfc])
349349

350-
sb.groupDescriptorSize = binary.LittleEndian.Uint16(b[0xfe:0x100])
350+
sb.groupDescriptorSize = 32
351+
if sb.features.fs64Bit {
352+
sb.groupDescriptorSize = binary.LittleEndian.Uint16(b[0xfe:0x100])
353+
}
351354

352355
sb.defaultMountOptions = parseMountOptions(binary.LittleEndian.Uint32(b[0x100:0x104]))
353356
sb.firstMetablockGroup = binary.LittleEndian.Uint32(b[0x104:0x108])

0 commit comments

Comments
 (0)