Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

bt_reclaim.c

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1998-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: bt_reclaim.c,v 12.2 2005/06/16 20:20:19 bostic Exp $
00008  */
00009 
00010 #include "db_config.h"
00011 
00012 #ifndef NO_SYSTEM_INCLUDES
00013 #include <sys/types.h>
00014 
00015 #include <string.h>
00016 #endif
00017 
00018 #include "db_int.h"
00019 #include "dbinc/db_page.h"
00020 #include "dbinc/btree.h"
00021 
00022 /*
00023  * __bam_reclaim --
00024  *      Free a database.
00025  *
00026  * PUBLIC: int __bam_reclaim __P((DB *, DB_TXN *));
00027  */
00028 int
00029 __bam_reclaim(dbp, txn)
00030         DB *dbp;
00031         DB_TXN *txn;
00032 {
00033         DBC *dbc;
00034         int ret, t_ret;
00035 
00036         /* Acquire a cursor. */
00037         if ((ret = __db_cursor(dbp, txn, &dbc, 0)) != 0)
00038                 return (ret);
00039 
00040         /* Walk the tree, freeing pages. */
00041         ret = __bam_traverse(dbc,
00042             DB_LOCK_WRITE, dbc->internal->root, __db_reclaim_callback, dbc);
00043 
00044         /* Discard the cursor. */
00045         if ((t_ret = __db_c_close(dbc)) != 0 && ret == 0)
00046                 ret = t_ret;
00047 
00048         return (ret);
00049 }
00050 
00051 /*
00052  * __bam_truncate --
00053  *      Truncate a database.
00054  *
00055  * PUBLIC: int __bam_truncate __P((DBC *, u_int32_t *));
00056  */
00057 int
00058 __bam_truncate(dbc, countp)
00059         DBC *dbc;
00060         u_int32_t *countp;
00061 {
00062         db_trunc_param trunc;
00063         int ret;
00064 
00065         trunc.count = 0;
00066         trunc.dbc = dbc;
00067 
00068         /* Walk the tree, freeing pages. */
00069         ret = __bam_traverse(dbc,
00070             DB_LOCK_WRITE, dbc->internal->root, __db_truncate_callback, &trunc);
00071 
00072         if (countp != NULL)
00073                 *countp = trunc.count;
00074 
00075         return (ret);
00076 }

Generated on Sun Dec 25 12:14:13 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2