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