fix free slots skipping
This commit is contained in:
parent
48642f67cd
commit
89b37412db
2 changed files with 33 additions and 35 deletions
|
@ -242,6 +242,7 @@ void viewer_jump_to_free_slot(App_State &app, u64 free_slot_idx)
|
|||
|
||||
Byte_Range free_slot = app.tfile_data.free_slots[idx];
|
||||
|
||||
printf("%lu 0x%lX\n", app.tfile_data.n_free_slots, free_slot.start);
|
||||
app.viewer.latest_free_slot_gone_to = idx;
|
||||
viewer_jump_to(app, free_slot.start);
|
||||
}
|
||||
|
|
|
@ -336,46 +336,43 @@ b8 walk_tkeys(Arena *arena, const u8 *data, u64 data_len, u32 flags, TFile_Data
|
|||
sec_header.range.len += sec_header.post_size;
|
||||
}
|
||||
|
||||
#if 1
|
||||
// Collect free slots.
|
||||
{
|
||||
cur = tkeys_data.sections[Sec_TFile_FreeList].range.start;
|
||||
// collect free slots
|
||||
TFile_Free_Slot fs;
|
||||
u64 free_slot_size = sizeof(u16) + (is_big_file ? sizeof(fs.rng.rng_long) : sizeof(fs.rng.rng_short));
|
||||
u64 free_slots_start = tkeys_data.sections[Sec_TFile_FreeList].range.start + 65; // XXX: the keylen should be subtracted above!
|
||||
u64 free_slots_end = tkeys_data.sections[Sec_TFile_FreeList].range.end();
|
||||
u64 n_free_slots = (free_slots_end - free_slots_start) / free_slot_size;
|
||||
if (n_free_slots) {
|
||||
tfile_data.free_slots = arena_push_array_nozero<Byte_Range>(arena, n_free_slots);
|
||||
u64 cur = free_slots_start;
|
||||
for (u64 i = 0; i < n_free_slots; ) {
|
||||
memcpy(&fs, data + cur, free_slot_size);
|
||||
Byte_Range *free_slot = &tfile_data.free_slots[i];
|
||||
u64 start, end;
|
||||
if (is_big_file) {
|
||||
start = bswap(fs.rng.rng_long.start);
|
||||
end = min(data_len, bswap(fs.rng.rng_long.end));
|
||||
} else {
|
||||
start = bswap(fs.rng.rng_short.start);
|
||||
end = min(data_len, bswap(fs.rng.rng_short.end));
|
||||
}
|
||||
|
||||
TFile_Free_Slot fs;
|
||||
u64 free_slot_size = sizeof(u16) + (is_big_file ? sizeof(fs.rng.rng_long) : sizeof(fs.rng.rng_short));
|
||||
u64 free_slots_start = tkeys_data.sections[Sec_TFile_FreeList].range.start + 65; // TEMP
|
||||
u64 free_slots_end = tkeys_data.sections[Sec_TFile_FreeList].range.end();
|
||||
printf("start: 0x%lX\n", free_slots_start);
|
||||
u64 n_free_slots = (free_slots_end - free_slots_start) / free_slot_size;
|
||||
if (n_free_slots) {
|
||||
tfile_data.free_slots = arena_push_array_nozero<Byte_Range>(arena, n_free_slots);
|
||||
tfile_data.n_free_slots = n_free_slots;
|
||||
for (u64 i = 0; i < n_free_slots; ++i) {
|
||||
u64 cur = free_slots_start + i * free_slot_size;
|
||||
memcpy(&fs, data + cur, free_slot_size);
|
||||
Byte_Range *free_slot = &tfile_data.free_slots[i];
|
||||
u64 start, end;
|
||||
if (is_big_file) {
|
||||
start = bswap(fs.rng.rng_long.start);
|
||||
end = min(data_len, bswap(fs.rng.rng_long.end));
|
||||
} else {
|
||||
start = bswap(fs.rng.rng_short.start);
|
||||
end = min(data_len, bswap(fs.rng.rng_short.end));
|
||||
}
|
||||
cur += free_slot_size;
|
||||
|
||||
// The free slot might not be a "real" slot (if its end is lower than its start or if it starts past the end of
|
||||
// the file): in this case, don't add it to the list.
|
||||
printf("0x%lX: 0x%lX - 0x%lX / 0x%lX\n", cur, start, end, data_len);
|
||||
if (end >= start && start < data_len) {
|
||||
free_slot->start = start;
|
||||
free_slot->len = end - start + 1; // +1 because `end` is inclusive
|
||||
} else {
|
||||
--tfile_data.n_free_slots;
|
||||
}
|
||||
printf("0x%lX - 0x%lX\n", start, end);
|
||||
|
||||
// The free slot might not be a "real" slot (if its end is lower than its start or if it starts past the end of
|
||||
// the file): in this case, don't add it to the list.
|
||||
if (end >= start && start < data_len) {
|
||||
free_slot->start = start;
|
||||
free_slot->len = end - start + 1; // +1 because `end` is inclusive
|
||||
++i;
|
||||
} else {
|
||||
--n_free_slots;
|
||||
}
|
||||
}
|
||||
tfile_data.n_free_slots = n_free_slots;
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue