171a9aa6c9911c6e37843ba18647f2e2afc4c56f
* Copyright (c) 1990 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* %sccs.include.redist.c%
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid
[] = "@(#)bt_close.c 5.7 (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
static int bt_meta
__P((BTREE
*));
* BT_CLOSE -- Close a btree.
* dbp: pointer to access method
* Delete any already deleted record that we've been saving
* because the cursor pointed to it.
if (ISSET(t
, BTF_DELCRSR
) && __bt_crsrdel(t
, &t
->bt_bcursor
))
if (__bt_sync(dbp
) == RET_ERROR
)
if (mpool_close(t
->bt_mp
) == RET_ERROR
)
return (close(fd
) ? RET_ERROR
: RET_SUCCESS
);
* BT_SYNC -- sync the btree to disk.
* dbp: pointer to access method
* RET_SUCCESS, RET_ERROR.
if (ISSET(t
, BTF_INMEM
| BTF_RDONLY
) || !ISSET(t
, BTF_MODIFIED
))
if (ISSET(t
, BTF_METADIRTY
) && bt_meta(t
) == 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
if (ISSET(t
, BTF_DELCRSR
)) {
if ((p
= malloc(t
->bt_psize
)) == NULL
)
if ((h
= mpool_get(t
->bt_mp
, t
->bt_bcursor
.pgno
, 0)) == NULL
)
bcopy(h
, p
, t
->bt_psize
);
__bt_dleaf(t
, h
, t
->bt_bcursor
.index
) == RET_ERROR
)
if ((status
= mpool_sync(t
->bt_mp
)) == RET_SUCCESS
)
ecrsr
: if (ISSET(t
, BTF_DELCRSR
)) {
bcopy(p
, h
, t
->bt_psize
);
mpool_put(t
->bt_mp
, h
, 0);
* BT_META -- write the tree meta data to disk.
if ((p
= mpool_get(t
->bt_mp
, P_META
, 0)) == NULL
)
/* Fill in metadata -- lorder is host-independent. */
m
.m_version
= BTREEVERSION
;
m
.m_flags
= t
->bt_flags
& SAVEMETA
;
m
.m_lorder
= htonl((u_long
)t
->bt_lorder
);
if (t
->bt_lorder
!= BYTE_ORDER
) {
bcopy(&m
, p
, sizeof(BTMETA
));
mpool_put(t
->bt_mp
, p
, MPOOL_DIRTY
);