python3 -c "
import struct

data = bytearray(open('/tmp/merged_gdt.bin','rb').read())

# Fix group 0 specifically
# It has flags=0x0004 (INODE_ZEROED) but missing INODE_UNINIT
# and has non-zero ib_csum=0x9f37 which won't match zeroed bitmap

g = 0
off = 0  # group 0 offset in GDT

flags = struct.unpack_from('<H', data, off+18)[0]
print(f'Group 0 flags before: 0x{flags:04x}')

# Set INODE_UNINIT (0x0002) so libext2fs skips inode bitmap validation
flags |= 0x0002
struct.pack_into('<H', data, off+18, flags)

# Zero the inode bitmap checksum to match actual zeroed data
struct.pack_into('<H', data, off+26, 0)  # ib_csum_lo
struct.pack_into('<H', data, off+50, 0)  # ib_csum_hi

print(f'Group 0 flags after:  0x{flags:04x}')
print(f'Group 0 ib_csum now:  0x0000')

with open('/tmp/merged_gdt.bin','wb') as f:
    f.write(data)
print('Saved')
"

# Restart server
pkill -f nbd_server
nbd-client -d /dev/nbd0 2>/dev/null
sleep 1
python3 nbd_server_v9.py &
sleep 2
nbd-client 127.0.0.1 10809 /dev/nbd0 -N ""

e2fsck -n /dev/nbd0 2>&1 | head -20
