From 040de369b2bb983c853577f57da1c972a93a0acf Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 2 Dec 2000 01:04:11 +0000 Subject: Added print_freelist command. Jeremy. (This used to be commit ee89ca9e68abb23fc26cd1378e02e56d0d725e55) --- source3/tdb/tdb.c | 35 +++++++++++++++++++++++++++++++++++ source3/tdb/tdbtool.c | 3 +++ 2 files changed, 38 insertions(+) (limited to 'source3/tdb') 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(); } -- cgit