156500Sbostic /*- 256500Sbostic * Copyright (c) 1990 The Regents of the University of California. 356500Sbostic * All rights reserved. 456500Sbostic * 556500Sbostic * %sccs.include.redist.c% 656500Sbostic */ 756500Sbostic 856500Sbostic #if defined(LIBC_SCCS) && !defined(lint) 9*57932Sbostic static char sccsid[] = "@(#)bt_page.c 5.3 (Berkeley) 02/11/93"; 1056500Sbostic #endif /* LIBC_SCCS and not lint */ 1156500Sbostic 1256500Sbostic #include <sys/types.h> 1356739Sbostic 1456500Sbostic #define __DBINTERFACE_PRIVATE 1556500Sbostic #include <stdio.h> 1656500Sbostic 17*57932Sbostic #include <db.h> 1856500Sbostic #include "btree.h" 1956500Sbostic 2056500Sbostic /* 2156500Sbostic * __BT_FREE -- Put a page on the freelist. 2256500Sbostic * 2356500Sbostic * Parameters: 2456500Sbostic * t: tree 2556500Sbostic * h: page to free 2656500Sbostic * 2756500Sbostic * Returns: 2856500Sbostic * RET_ERROR, RET_SUCCESS 2956500Sbostic */ 3056500Sbostic int 3156500Sbostic __bt_free(t, h) 3256500Sbostic BTREE *t; 3356500Sbostic PAGE *h; 3456500Sbostic { 3556500Sbostic /* Insert the page at the start of the free list. */ 3656500Sbostic h->prevpg = P_INVALID; 3756500Sbostic h->nextpg = t->bt_free; 3856500Sbostic t->bt_free = h->pgno; 3956500Sbostic 4056500Sbostic /* Make sure the page gets written back. */ 4156500Sbostic return (mpool_put(t->bt_mp, h, MPOOL_DIRTY)); 4256500Sbostic } 4356500Sbostic 4456500Sbostic /* 4556500Sbostic * __BT_NEW -- Get a new page, preferably from the freelist. 4656500Sbostic * 4756500Sbostic * Parameters: 4856500Sbostic * t: tree 4956500Sbostic * npg: storage for page number. 5056500Sbostic * 5156500Sbostic * Returns: 5256500Sbostic * Pointer to a page, NULL on error. 5356500Sbostic */ 5456500Sbostic PAGE * 5556500Sbostic __bt_new(t, npg) 5656500Sbostic BTREE *t; 5756500Sbostic pgno_t *npg; 5856500Sbostic { 5956500Sbostic PAGE *h; 6056500Sbostic 6156500Sbostic if (t->bt_free != P_INVALID && 6256500Sbostic (h = mpool_get(t->bt_mp, t->bt_free, 0)) != NULL) { 6356500Sbostic *npg = t->bt_free; 6456500Sbostic t->bt_free = h->nextpg; 6556500Sbostic return (h); 6656500Sbostic } 6756500Sbostic return (mpool_new(t->bt_mp, npg)); 6856500Sbostic } 69