/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 1990, 1993, 19944* The Regents of the University of California. All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14* 3. Neither the name of the University nor the names of its contributors15* may be used to endorse or promote products derived from this software16* without specific prior written permission.17*18* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND19* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE20* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE21* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE22* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL23* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS24* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)25* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY27* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF28* SUCH DAMAGE.29*/3031#include <sys/types.h>3233#include <stdio.h>3435#include <db.h>36#include "btree.h"3738/*39* __bt_free --40* Put a page on the freelist.41*42* Parameters:43* t: tree44* h: page to free45*46* Returns:47* RET_ERROR, RET_SUCCESS48*49* Side-effect:50* mpool_put's the page.51*/52int53__bt_free(BTREE *t, PAGE *h)54{55/* Insert the page at the head of the free list. */56h->prevpg = P_INVALID;57h->nextpg = t->bt_free;58t->bt_free = h->pgno;59F_SET(t, B_METADIRTY);6061/* Make sure the page gets written back. */62return (mpool_put(t->bt_mp, h, MPOOL_DIRTY));63}6465/*66* __bt_new --67* Get a new page, preferably from the freelist.68*69* Parameters:70* t: tree71* npg: storage for page number.72*73* Returns:74* Pointer to a page, NULL on error.75*/76PAGE *77__bt_new(BTREE *t, pgno_t *npg)78{79PAGE *h;8081if (t->bt_free != P_INVALID &&82(h = mpool_get(t->bt_mp, t->bt_free, 0)) != NULL) {83*npg = t->bt_free;84t->bt_free = h->nextpg;85F_SET(t, B_METADIRTY);86return (h);87}88return (mpool_new(t->bt_mp, npg, MPOOL_PAGE_NEXT));89}909192