1 /*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8 #if defined(LIBC_SCCS) && !defined(lint)
9 static char sccsid[] = "@(#)bt_page.c 8.2 (Berkeley) 02/21/94";
10 #endif /* LIBC_SCCS and not lint */
11
12 #include <sys/types.h>
13
14 #include <stdio.h>
15
16 #include <db.h>
17 #include "btree.h"
18
19 /*
20 * __BT_FREE -- Put a page on the freelist.
21 *
22 * Parameters:
23 * t: tree
24 * h: page to free
25 *
26 * Returns:
27 * RET_ERROR, RET_SUCCESS
28 */
29 int
__bt_free(t,h)30 __bt_free(t, h)
31 BTREE *t;
32 PAGE *h;
33 {
34 /* Insert the page at the start of the free list. */
35 h->prevpg = P_INVALID;
36 h->nextpg = t->bt_free;
37 t->bt_free = h->pgno;
38
39 /* Make sure the page gets written back. */
40 return (mpool_put(t->bt_mp, h, MPOOL_DIRTY));
41 }
42
43 /*
44 * __BT_NEW -- Get a new page, preferably from the freelist.
45 *
46 * Parameters:
47 * t: tree
48 * npg: storage for page number.
49 *
50 * Returns:
51 * Pointer to a page, NULL on error.
52 */
53 PAGE *
__bt_new(t,npg)54 __bt_new(t, npg)
55 BTREE *t;
56 pgno_t *npg;
57 {
58 PAGE *h;
59
60 if (t->bt_free != P_INVALID &&
61 (h = mpool_get(t->bt_mp, t->bt_free, 0)) != NULL) {
62 *npg = t->bt_free;
63 t->bt_free = h->nextpg;
64 return (h);
65 }
66 return (mpool_new(t->bt_mp, npg));
67 }
68