summaryrefslogtreecommitdiffstats
path: root/lib/libc/db/btree/bt_open.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/db/btree/bt_open.c')
-rw-r--r--lib/libc/db/btree/bt_open.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/libc/db/btree/bt_open.c b/lib/libc/db/btree/bt_open.c
index 7422ca4..47f3646 100644
--- a/lib/libc/db/btree/bt_open.c
+++ b/lib/libc/db/btree/bt_open.c
@@ -352,18 +352,25 @@ nroot(BTREE *t)
PAGE *meta, *root;
pgno_t npg;
- if ((meta = mpool_get(t->bt_mp, 0, 0)) != NULL) {
- mpool_put(t->bt_mp, meta, 0);
- return (RET_SUCCESS);
+ if ((root = mpool_get(t->bt_mp, 1, 0)) != NULL) {
+ if (root->lower == 0 &&
+ root->pgno == 0 &&
+ root->linp[0] == 0) {
+ mpool_delete(t->bt_mp, root);
+ errno = EINVAL;
+ } else {
+ mpool_put(t->bt_mp, root, 0);
+ return (RET_SUCCESS);
+ }
}
if (errno != EINVAL) /* It's OK to not exist. */
return (RET_ERROR);
errno = 0;
- if ((meta = mpool_new(t->bt_mp, &npg)) == NULL)
+ if ((meta = mpool_new(t->bt_mp, &npg, MPOOL_PAGE_NEXT)) == NULL)
return (RET_ERROR);
- if ((root = mpool_new(t->bt_mp, &npg)) == NULL)
+ if ((root = mpool_new(t->bt_mp, &npg, MPOOL_PAGE_NEXT)) == NULL)
return (RET_ERROR);
if (npg != P_ROOT)
OpenPOWER on IntegriCloud