34 #if defined(LIBC_SCCS) && !defined(lint)
35 static char sccsid[] =
"@(#)rec_put.c 8.7 (Berkeley) 8/18/94";
38 #include <sys/types.h>
45 #include "../include/db.h"
62 __rec_put(dbp, key, data, flags)
76 if (t->bt_pinned != NULL) {
77 mpool_put(t->bt_mp, t->bt_pinned, 0);
86 if (F_ISSET(t, R_FIXLEN) && data->size != t->bt_reclen) {
87 if (data->size > t->bt_reclen)
90 if (t->bt_rdata.size < t->bt_reclen) {
91 t->bt_rdata.data = t->bt_rdata.data == NULL ?
92 malloc(t->bt_reclen) :
93 realloc(t->bt_rdata.data, t->bt_reclen);
94 if (t->bt_rdata.data == NULL)
96 t->bt_rdata.size = t->bt_reclen;
98 memmove(t->bt_rdata.data, data->data, data->size);
99 memset((
char *)t->bt_rdata.data + data->size,
100 t->bt_bval, t->bt_reclen - data->size);
101 fdata.data = t->bt_rdata.data;
102 fdata.size = t->bt_reclen;
104 fdata.data = data->data;
105 fdata.size = data->size;
110 if (!F_ISSET(&t->bt_cursor, CURS_INIT))
112 nrec = t->bt_cursor.rcursor;
115 if ((nrec = *(recno_t *)key->data) == 0)
119 if ((nrec = *(recno_t *)key->data) == 0) {
126 if ((nrec = *(recno_t *)key->data) == 0)
130 if ((nrec = *(recno_t *)key->data) == 0)
132 if (nrec <= t->bt_nrecs)
133 return (RET_SPECIAL);
136 einval: errno = EINVAL;
144 if (nrec > t->bt_nrecs) {
145 if (!F_ISSET(t, R_EOF | R_INMEM) &&
146 t->bt_irec(t, nrec) == RET_ERROR)
148 if (nrec > t->bt_nrecs + 1) {
149 if (F_ISSET(t, R_FIXLEN)) {
151 (
void *)malloc(t->bt_reclen)) == NULL)
153 tdata.size = t->bt_reclen;
154 memset(tdata.data, t->bt_bval, tdata.size);
159 while (nrec > t->bt_nrecs + 1)
161 t->bt_nrecs, &tdata, 0) != RET_SUCCESS)
163 if (F_ISSET(t, R_FIXLEN))
168 if ((status = __rec_iput(t, nrec - 1, &fdata, flags)) != RET_SUCCESS)
171 if (flags == R_SETCURSOR)
172 t->bt_cursor.rcursor = nrec;
174 F_SET(t, R_MODIFIED);
175 return (__rec_ret(t, NULL, nrec, key, NULL));
190 __rec_iput(t, nrec, data, flags)
199 indx_t idx, nxtindex;
203 char *dest, db[NOVFLSIZE];
211 if (data->size > t->bt_ovflsize) {
212 if (__ovfl_put(t, data, &pg) == RET_ERROR)
215 tdata.size = NOVFLSIZE;
217 *(u_int32_t *)(db +
sizeof(pgno_t)) = data->size;
224 if ((e = __rec_search(t, nrec,
225 nrec > t->bt_nrecs || flags == R_IAFTER || flags == R_IBEFORE ?
226 SINSERT : SEARCH)) == NULL)
245 if (nrec < t->bt_nrecs &&
246 __rec_dleaf(t, h, idx) == RET_ERROR) {
247 mpool_put(t->bt_mp, h, 0);
258 nbytes = NRLEAFDBT(data->size);
259 if ((u_int32_t) (h->upper - h->lower) < nbytes +
sizeof(indx_t)) {
260 status = __bt_split(t, h, NULL, data, dflags, nbytes, idx);
261 if (status == RET_SUCCESS)
266 if (idx < (nxtindex = NEXTINDEX(h)))
267 memmove(h->linp + idx + 1, h->linp + idx,
268 (nxtindex - idx) *
sizeof(indx_t));
269 h->lower +=
sizeof(indx_t);
271 h->linp[idx] = h->upper -= nbytes;
272 dest = (
char *)h + h->upper;
273 WR_RLEAF(dest, data, dflags);
276 F_SET(t, B_MODIFIED);
277 mpool_put(t->bt_mp, h, MPOOL_DIRTY);
279 return (RET_SUCCESS);