/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
*
* @APPLE_LICENSE_HEADER_END@
*/
-/*
- * Copyright (c) 1990, 1993
+/*-
+ * Copyright (c) 1990, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* SUCH DAMAGE.
*/
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)bt_close.c 8.7 (Berkeley) 8/17/94";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
+#ifndef __APPLE_
+#endif
#include <sys/param.h>
#include <db.h>
#include "btree.h"
-static int bt_meta __P((BTREE *));
+static int bt_meta(BTREE *);
/*
* BT_CLOSE -- Close a btree.
t->bt_pinned = NULL;
}
- /*
- * Delete any already deleted record that we've been saving
- * because the cursor pointed to it.
- */
- if (ISSET(t, B_DELCRSR) && __bt_crsrdel(t, &t->bt_bcursor))
- return (RET_ERROR);
-
+ /* Sync the tree. */
if (__bt_sync(dbp, 0) == RET_ERROR)
return (RET_ERROR);
+ /* Close the memory pool. */
if (mpool_close(t->bt_mp) == RET_ERROR)
return (RET_ERROR);
- if (t->bt_stack)
- free(t->bt_stack);
- if (t->bt_kbuf)
- free(t->bt_kbuf);
- if (t->bt_dbuf)
- free(t->bt_dbuf);
+ /* Free random memory. */
+ if (t->bt_cursor.key.data != NULL) {
+ free(t->bt_cursor.key.data);
+ t->bt_cursor.key.size = 0;
+ t->bt_cursor.key.data = NULL;
+ }
+ if (t->bt_rkey.data) {
+ free(t->bt_rkey.data);
+ t->bt_rkey.size = 0;
+ t->bt_rkey.data = NULL;
+ }
+ if (t->bt_rdata.data) {
+ free(t->bt_rdata.data);
+ t->bt_rdata.size = 0;
+ t->bt_rdata.data = NULL;
+ }
fd = t->bt_fd;
free(t);
{
BTREE *t;
int status;
- PAGE *h;
- void *p;
t = dbp->internal;
return (RET_ERROR);
}
- if (ISSET(t, B_INMEM | B_RDONLY) || !ISSET(t, B_MODIFIED))
+ if (F_ISSET(t, B_INMEM | B_RDONLY) || !F_ISSET(t, B_MODIFIED))
return (RET_SUCCESS);
- if (ISSET(t, B_METADIRTY) && bt_meta(t) == RET_ERROR)
+ if (F_ISSET(t, B_METADIRTY) && bt_meta(t) == RET_ERROR)
return (RET_ERROR);
- /*
- * Nastiness. If the cursor has been marked for deletion, but not
- * actually deleted, we have to make a copy of the page, delete the
- * key/data item, sync the file, and then restore the original page
- * contents.
- */
- if (ISSET(t, B_DELCRSR)) {
- if ((p = (void *)malloc(t->bt_psize)) == NULL)
- return (RET_ERROR);
- if ((h = mpool_get(t->bt_mp, t->bt_bcursor.pgno, 0)) == NULL)
- return (RET_ERROR);
- memmove(p, h, t->bt_psize);
- if ((status =
- __bt_dleaf(t, h, t->bt_bcursor.index)) == RET_ERROR)
- goto ecrsr;
- mpool_put(t->bt_mp, h, MPOOL_DIRTY);
- }
-
if ((status = mpool_sync(t->bt_mp)) == RET_SUCCESS)
- CLR(t, B_MODIFIED);
-
-ecrsr: if (ISSET(t, B_DELCRSR)) {
- if ((h = mpool_get(t->bt_mp, t->bt_bcursor.pgno, 0)) == NULL)
- return (RET_ERROR);
- memmove(h, p, t->bt_psize);
- free(p);
- mpool_put(t->bt_mp, h, MPOOL_DIRTY);
- }
+ F_CLR(t, B_MODIFIED);
+
return (status);
}
return (RET_ERROR);
/* Fill in metadata. */
- m.m_magic = BTREEMAGIC;
- m.m_version = BTREEVERSION;
- m.m_psize = t->bt_psize;
- m.m_free = t->bt_free;
- m.m_nrecs = t->bt_nrecs;
- m.m_flags = t->bt_flags & SAVEMETA;
+ m.magic = BTREEMAGIC;
+ m.version = BTREEVERSION;
+ m.psize = t->bt_psize;
+ m.free = t->bt_free;
+ m.nrecs = t->bt_nrecs;
+ m.flags = F_ISSET(t, SAVEMETA);
memmove(p, &m, sizeof(BTMETA));
mpool_put(t->bt_mp, p, MPOOL_DIRTY);