* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid
[] = "@(#)rec_put.c 8.3 (Berkeley) 3/1/94";
#endif /* LIBC_SCCS and not lint */
* __REC_PUT -- Add a recno item to the tree.
* dbp: pointer to access method
* flag: R_CURSOR, R_IAFTER, R_IBEFORE, R_NOOVERWRITE
* RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key is
* already in the tree and R_NOOVERWRITE specified.
__rec_put(dbp
, key
, data
, flags
)
/* Toss any page pinned across calls. */
if (t
->bt_pinned
!= NULL
) {
mpool_put(t
->bt_mp
, t
->bt_pinned
, 0);
if (!ISSET(t
, B_SEQINIT
))
if ((nrec
= *(recno_t
*)key
->data
) == 0)
if ((nrec
= *(recno_t
*)key
->data
) == 0) {
if ((nrec
= *(recno_t
*)key
->data
) == 0)
if ((nrec
= *(recno_t
*)key
->data
) == 0)
* Make sure that records up to and including the put record are
* already in the database. If skipping records, create empty ones.
if (nrec
> t
->bt_nrecs
) {
if (!ISSET(t
, R_EOF
| R_INMEM
) &&
t
->bt_irec(t
, nrec
) == RET_ERROR
)
if (nrec
> t
->bt_nrecs
+ 1) {
if (ISSET(t
, R_FIXLEN
)) {
(void *)malloc(t
->bt_reclen
)) == NULL
)
tdata
.size
= t
->bt_reclen
;
memset(tdata
.data
, t
->bt_bval
, tdata
.size
);
while (nrec
> t
->bt_nrecs
+ 1)
t
->bt_nrecs
, &tdata
, 0) != RET_SUCCESS
)
if ((status
= __rec_iput(t
, nrec
- 1, data
, flags
)) != RET_SUCCESS
)
if (flags
== R_SETCURSOR
)
return (__rec_ret(t
, NULL
, nrec
, key
, NULL
));
* __REC_IPUT -- Add a recno item to the tree.
__rec_iput(t
, nrec
, data
, flags
)
char *dest
, db
[NOVFLSIZE
];
* If the data won't fit on a page, store it on indirect pages.
* If the insert fails later on, these pages aren't recovered.
if (data
->size
> t
->bt_ovflsize
) {
if (__ovfl_put(t
, data
, &pg
) == RET_ERROR
)
*(size_t *)(db
+ sizeof(pgno_t
)) = data
->size
;
/* __rec_search pins the returned page. */
if ((e
= __rec_search(t
, nrec
,
nrec
> t
->bt_nrecs
|| flags
== R_IAFTER
|| flags
== R_IBEFORE
?
SINSERT
: SEARCH
)) == NULL
)
* Add the specified key/data pair to the tree. The R_IAFTER and
* R_IBEFORE flags insert the key after/before the specified key.
* Pages are split as required.
if (nrec
< t
->bt_nrecs
&&
__rec_dleaf(t
, h
, index
) == RET_ERROR
) {
mpool_put(t
->bt_mp
, h
, 0);
* If not enough room, split the page. The split code will insert
* the key and data and unpin the current page. If inserting into
* the offset array, shift the pointers up.
nbytes
= NRLEAFDBT(data
->size
);
if (h
->upper
- h
->lower
< nbytes
+ sizeof(indx_t
)) {
status
= __bt_split(t
, h
, NULL
, data
, dflags
, nbytes
, index
);
if (status
== RET_SUCCESS
)
if (index
< (nxtindex
= NEXTINDEX(h
)))
memmove(h
->linp
+ index
+ 1, h
->linp
+ index
,
(nxtindex
- index
) * sizeof(indx_t
));
h
->lower
+= sizeof(indx_t
);
h
->linp
[index
] = h
->upper
-= nbytes
;
dest
= (char *)h
+ h
->upper
;
WR_RLEAF(dest
, data
, dflags
);
mpool_put(t
->bt_mp
, h
, MPOOL_DIRTY
);