# Run this standalone first to verify the block is readable and contains dir entries
import struct

BLOCK = 4096
DEV = '/dev/dm-0'

phys = 3153952  # from first debug inode
with open(DEV, 'rb') as f:
    f.seek(phys * BLOCK)
    data = f.read(BLOCK)

print(f"Read {len(data)} bytes")
print(f"First 32 bytes: {data[:32].hex()}")

# Try parsing as dir entries
offset = 0
while offset < 128:
    ino, rec_len, name_len, ftype = struct.unpack_from('<IHBB', data, offset)
    print(f"  offset={offset}: inode={ino} rec_len={rec_len} name_len={name_len} ftype={ftype}")
    if rec_len < 8:
        break
    if name_len > 0:
        name = data[offset+8:offset+8+name_len].decode('utf-8', errors='replace')
        print(f"    name='{name}'")
    offset += rec_len
