summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source3/tdb/tdb.c35
-rw-r--r--source3/tdb/tdbtool.c3
2 files changed, 38 insertions, 0 deletions
diff --git a/source3/tdb/tdb.c b/source3/tdb/tdb.c
index 7e39e8fa6f..87c145cb8c 100644
--- a/source3/tdb/tdb.c
+++ b/source3/tdb/tdb.c
@@ -1308,3 +1308,38 @@ int tdb_unlockchain(TDB_CONTEXT *tdb, TDB_DATA key)
}
+#if TDB_DEBUG
+void tdb_printfreelist(TDB_CONTEXT *tdb)
+{
+ tdb_off offset, rec_ptr, last_ptr;
+ struct list_struct rec, lastrec, newrec;
+
+ tdb_lock(tdb, -1, F_WRLCK);
+
+ last_ptr = 0;
+ offset = FREELIST_TOP;
+
+ /* read in the freelist top */
+ if (ofs_read(tdb, offset, &rec_ptr) == -1) {
+ return;
+ }
+
+ while (rec_ptr) {
+ if (tdb_read(tdb, rec_ptr, (char *)&rec, sizeof(rec)) == -1) {
+ return;
+ }
+
+ if (rec.magic != TDB_FREE_MAGIC) {
+ printf("bad magic 0x%08x in free list\n", rec.magic);
+ return;
+ }
+
+ printf("entry offset=[0x%08x], rec.rec_len = [0x%08x]\n", rec.next, rec.rec_len );
+
+ /* move to the next record */
+ rec_ptr = rec.next;
+ }
+
+ tdb_unlock(tdb, -1);
+}
+#endif
diff --git a/source3/tdb/tdbtool.c b/source3/tdb/tdbtool.c
index 4400f5d8e0..0373aee9a7 100644
--- a/source3/tdb/tdbtool.c
+++ b/source3/tdb/tdbtool.c
@@ -67,6 +67,7 @@ tdbtool:
store key data : store a record (replace)
show key : show a record by key
delete key : delete a record by key
+ free : print the database freelist
");
}
@@ -273,6 +274,8 @@ int main(int argc, char *argv[])
tdb_traverse(tdb, print_rec, NULL);
} else if (strcmp(tok,"info") == 0) {
info_tdb();
+ } else if (strcmp(tok, "free") == 0) {
+ tdb_printfreelist(tdb);
} else {
help();
}