/*-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* This code is derived from software contributed to Berkeley by7* Mike Olson.8*9* Redistribution and use in source and binary forms, with or without10* modification, are permitted provided that the following conditions11* are met:12* 1. Redistributions of source code must retain the above copyright13* notice, this list of conditions and the following disclaimer.14* 2. Redistributions in binary form must reproduce the above copyright15* notice, this list of conditions and the following disclaimer in the16* documentation and/or other materials provided with the distribution.17* 3. Neither the name of the University nor the names of its contributors18* may be used to endorse or promote products derived from this software19* without specific prior written permission.20*21* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND22* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE23* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE24* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE25* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL26* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS27* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)28* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT29* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY30* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF31* SUCH DAMAGE.32*/3334#include <sys/types.h>3536#include <errno.h>37#include <stddef.h>38#include <stdio.h>3940#include <db.h>41#include "btree.h"4243/*44* __BT_GET -- Get a record from the btree.45*46* Parameters:47* dbp: pointer to access method48* key: key to find49* data: data to return50* flag: currently unused51*52* Returns:53* RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found.54*/55int56__bt_get(const DB *dbp, const DBT *key, DBT *data, u_int flags)57{58BTREE *t;59EPG *e;60int exact, status;6162t = dbp->internal;6364/* Toss any page pinned across calls. */65if (t->bt_pinned != NULL) {66mpool_put(t->bt_mp, t->bt_pinned, 0);67t->bt_pinned = NULL;68}6970/* Get currently doesn't take any flags. */71if (flags) {72errno = EINVAL;73return (RET_ERROR);74}7576if ((e = __bt_search(t, key, &exact)) == NULL)77return (RET_ERROR);78if (!exact) {79mpool_put(t->bt_mp, e->page, 0);80return (RET_SPECIAL);81}8283status = __bt_ret(t, e, NULL, NULL, data, &t->bt_rdata, 0);8485/*86* If the user is doing concurrent access, we copied the87* key/data, toss the page.88*/89if (F_ISSET(t, B_DB_LOCK))90mpool_put(t->bt_mp, e->page, 0);91else92t->bt_pinned = e->page;93return (status);94}959697