]> git.sur5r.net Git - openldap/commitdiff
Add mfree utility to show the freelist
authorHoward Chu <hyc@symas.com>
Wed, 28 Mar 2012 16:20:18 +0000 (09:20 -0700)
committerQuanah Gibson-Mount <quanah@openldap.org>
Wed, 28 Mar 2012 17:34:24 +0000 (10:34 -0700)
libraries/libmdb/Makefile
libraries/libmdb/mfree.c [new file with mode: 0644]

index 88297078e195a102b158e215aceda17278638cad..1fde58889c16cf241a0227ad5eecb1dd02cede9f 100644 (file)
@@ -28,6 +28,7 @@ mtest3:       mtest3.o libmdb.a
 mtest4:        mtest4.o libmdb.a
 mtest5:        mtest5.o libmdb.a
 mtest6:        mtest6.o libmdb.a
+mfree: mfree.o libmdb.a
 
 mdb.o: mdb.c mdb.h midl.h
        $(CC) $(CFLAGS) -fPIC $(CPPFLAGS) -c mdb.c
diff --git a/libraries/libmdb/mfree.c b/libraries/libmdb/mfree.c
new file mode 100644 (file)
index 0000000..0833b22
--- /dev/null
@@ -0,0 +1,56 @@
+/* mfree.c - memory-mapped database freelist scanner */
+/*
+ * Copyright 2011 Howard Chu, Symas Corp.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+#define _XOPEN_SOURCE 500              /* srandom(), random() */
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include "mdb.h"
+#include "midl.h"
+
+int main(int argc,char * argv[])
+{
+       int rc;
+       MDB_env *env;
+       MDB_dbi dbi;
+       MDB_val key, data;
+       MDB_txn *txn;
+       MDB_stat mst;
+       MDB_cursor *cursor;
+       ID i, j, *iptr;
+
+       if (argc != 2) {
+               fprintf(stderr, "usage: %s <pathname>\n", argv[0]);
+               exit(1);
+       }
+
+       rc = mdb_env_create(&env);
+       rc = mdb_env_open(env, argv[1], MDB_RDONLY, 0664);
+       rc = mdb_txn_begin(env, NULL, MDB_RDONLY, &txn);
+       dbi = 0;
+       rc = mdb_cursor_open(txn, dbi, &cursor);
+       while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
+               printf("key: %p %zu, data: %p\n",
+                       key.mv_data,  *(ID *) key.mv_data,
+                       data.mv_data);
+               iptr = data.mv_data;
+               j = *iptr++;
+               for (i=0; i<j; i++)
+                       printf(" %zu\n", iptr[i]);
+       }
+       mdb_cursor_close(cursor);
+       mdb_txn_abort(txn);
+       mdb_env_close(env);
+
+       return 0;
+}