Files
ext4recovery/misc_tools/find_chunk_location.py
2026-04-30 11:04:05 +00:00

38 lines
1.3 KiB
Python

CHUNK = 128*512
LV_START = 5120000*512
BSIZE = 4096
found_byte = 47323856896
block_num = (found_byte - LV_START) // BSIZE
print(f'Found at md0 byte: {found_byte}')
print(f'LV_START: {LV_START}')
print(f'Offset from LV: {found_byte - LV_START}')
print(f'Block number: {block_num}')
virt = block_num * BSIZE
group = virt // (5*CHUNK)
in_group = virt % (5*CHUNK)
chunk_idx = in_group // CHUNK
intra = in_group % CHUNK
print(f'chunk_group={group} chunk_idx={chunk_idx} intra={intra}')
print()
# The block was found at chunk_idx=4 but IS readable
# This means our assumption that chunk_idx=4 = unreadable is WRONG
# The data IS there, we just need to read it
# Our current translation SKIPS chunk_idx=4
# But the data exists at: LV_START + group*5*CHUNK + 4*CHUNK + intra
# We've been computing: LV_START + group*4*CHUNK + chunk_idx*CHUNK + intra
# For chunk_idx < 4 these are equivalent
# For chunk_idx = 4 we skip it entirely
# So the fix is: for chunk_idx=4, read from the 5th physical chunk
# phys = LV_START + group*5*CHUNK + 4*CHUNK + intra
phys_5chunk = LV_START + group*5*CHUNK + 4*CHUNK + intra
print(f'Physical via 5-chunk formula: {phys_5chunk}')
print(f'Found at: {found_byte}')
print(f'Match: {phys_5chunk == found_byte}')