diff --git a/rust/ares_pma/c-src/btest.c b/rust/ares_pma/c-src/btest.c index 3c07779..0fd0ed1 100644 --- a/rust/ares_pma/c-src/btest.c +++ b/rust/ares_pma/c-src/btest.c @@ -307,11 +307,26 @@ int main(int argc, char *argv[]) return errno; assert(SUCC(bt_state_open(state4, "./pmatest4", 0, 0644))); +#define PMA_INITIAL_SIZE_p PMA_GROW_SIZE_p BYTE *t4a = bt_malloc(state4, PMA_GROW_SIZE_p * 2); BYTE *t4b = t4a; for (size_t i = 0; i < PMA_GROW_SIZE_b * 2; i++) { *t4b++ = rand(); } + assert(state4->file_size_p == PMA_INITIAL_SIZE_p + PMA_GROW_SIZE_p * 2); + /* given the allocation pattern the head of the flist should also be the + tail. The hi page here should match the file size */ + assert(state4->flist->hi == state4->file_size_p); + + bt_state_close(state4); + + bt_state_new(&state4); + + assert(SUCC(bt_state_open(state4, "./pmatest4", 0, 0644))); + + assert(state4->file_size_p == PMA_INITIAL_SIZE_p + PMA_GROW_SIZE_p * 2); + assert(state4->flist->hi == state4->file_size_p); + return 0; } diff --git a/rust/ares_pma/c-src/btree.c b/rust/ares_pma/c-src/btree.c index 17adf44..fc34a85 100644 --- a/rust/ares_pma/c-src/btree.c +++ b/rust/ares_pma/c-src/btree.c @@ -2374,6 +2374,14 @@ _bt_state_load(BT_state *state) assert(SUCC(_mlist_new(state))); } else { + /* Set the file length */ + if (fstat(state->data_fd, &stat) != 0) + return errno; + + /* the file size should be a multiple of our pagesize */ + assert((stat.st_size % BT_PAGESIZE) == 0); + state->file_size_p = stat.st_size / BT_PAGESIZE; + /* restore data memory maps */ _bt_state_restore_maps(state); @@ -2382,15 +2390,6 @@ _bt_state_load(BT_state *state) /* Dirty the metapage and root page */ assert(SUCC(_bt_flip_meta(state))); - - /* Set the file length */ - // XX make sure the flist is updated with this! - if (fstat(state->data_fd, &stat) != 0) - return errno; - - /* the file size should be a multiple of our pagesize */ - assert((stat.st_size % BT_PAGESIZE) == 0); - state->file_size_p = stat.st_size / BT_PAGESIZE; } return BT_SUCC;