@@ -772,6 +772,11 @@ extension EXT4 {
772772 }
773773 }
774774
775+ // Bug #22 (HIGH, 2 parts): The freeBlocks variable computed with careful edge-case logic below
776+ // was never used; a simpler freeBlocksCount = blocksPerGroup - blocks ignored those
777+ // edge cases (wrong for small or last-group filesystems) and was written to the
778+ // group descriptor instead. Fixed by using freeBlocks in the group descriptor.
779+ // Same fix: sonnet-1m-bulk, sonnet-fix-bulk. All other branches write wrong counts.
775780 var freeBlocks : UInt32 = UInt32 ( self . blocksPerGroup)
776781 if freeBlocks < blocks {
777782 freeBlocks = 0
@@ -788,15 +793,15 @@ extension EXT4 {
788793 let blockBitmap = UInt64 ( bitmapOffset + 2 * group)
789794 let inodeBitmap = UInt64 ( bitmapOffset + 2 * group + 1 )
790795 let inodeTable = inodeTableOffset + UInt64( group * inodeTableSizePerGroup)
791- let freeBlocksCount = UInt32 ( self . blocksPerGroup - blocks)
792796 let freeInodesCount = UInt32 ( blockGroupSize. inodesPerGroup - inodes)
793797 groupDescriptors. append (
794798 // low bits
795799 GroupDescriptor (
796800 blockBitmapLow: blockBitmap. lo, // address of block bitmap
797801 inodeBitmapLow: inodeBitmap. lo, // address of inode bitmap
798802 inodeTableLow: inodeTable. lo, // address of inode table for this group
799- freeBlocksCountLow: freeBlocksCount. lo,
803+ // Bug #22
804+ freeBlocksCountLow: freeBlocks. lo,
800805 freeInodesCountLow: freeInodesCount. lo,
801806 usedDirsCountLow: dirs. lo,
802807 flags: 0x0000 ,
0 commit comments