Initial remote commit
This commit is contained in:
52
test/testoffset.sh
Normal file
52
test/testoffset.sh
Normal file
@@ -0,0 +1,52 @@
|
||||
python3 -c "
|
||||
import struct
|
||||
|
||||
# Read what's actually at the start of our NBD device
|
||||
with open('/dev/nbd0','rb') as f:
|
||||
# Block 0 (should be boot block, all zeros for non-bootable)
|
||||
block0 = f.read(4096)
|
||||
# Superblock at byte 1024
|
||||
f.seek(1024)
|
||||
sb = f.read(256)
|
||||
|
||||
# Check block 0
|
||||
nonzero = sum(1 for b in block0 if b != 0)
|
||||
print(f'Block 0 non-zero bytes: {nonzero} (should be 0 for ext4)')
|
||||
print(f'Block 0 first 16: {block0[:16].hex()}')
|
||||
|
||||
# Check superblock
|
||||
magic = struct.unpack_from('<H', sb, 56)[0]
|
||||
uuid = sb[104:120].hex()
|
||||
first_data_block = struct.unpack_from('<I', sb, 20)[0]
|
||||
blocks_per_group = struct.unpack_from('<I', sb, 40)[0]
|
||||
print(f'SB magic: 0x{magic:04x} (want 0xef53)')
|
||||
print(f'SB uuid: {uuid}')
|
||||
print(f'first_data_block: {first_data_block} (0 for bsize>1024, 1 for bsize=1024)')
|
||||
print(f'blocks_per_group: {blocks_per_group}')
|
||||
|
||||
# The GDT should be at block 1 = byte 4096
|
||||
# But if first_data_block=1, GDT is at block 2 = byte 8192
|
||||
f2 = open('/dev/nbd0','rb')
|
||||
f2.seek(4096)
|
||||
gdt0 = f2.read(64)
|
||||
bb = struct.unpack_from('<I',gdt0,0)[0]
|
||||
ib = struct.unpack_from('<I',gdt0,4)[0]
|
||||
it = struct.unpack_from('<I',gdt0,8)[0]
|
||||
cs = struct.unpack_from('<H',gdt0,30)[0]
|
||||
print(f'At byte 4096 (block 1): bb={bb} ib={ib} it={it} csum=0x{cs:04x}')
|
||||
|
||||
f2.seek(8192)
|
||||
gdt0b = f2.read(64)
|
||||
bb = struct.unpack_from('<I',gdt0b,0)[0]
|
||||
ib = struct.unpack_from('<I',gdt0b,4)[0]
|
||||
it = struct.unpack_from('<I',gdt0b,8)[0]
|
||||
cs = struct.unpack_from('<H',gdt0b,30)[0]
|
||||
print(f'At byte 8192 (block 2): bb={bb} ib={ib} it={it} csum=0x{cs:04x}')
|
||||
|
||||
# Check what libext2fs would see as the device size
|
||||
import os
|
||||
f2.seek(0,2)
|
||||
size = f2.tell()
|
||||
print(f'NBD device size: {size} bytes = {size//4096} blocks')
|
||||
f2.close()
|
||||
"
|
||||
Reference in New Issue
Block a user