From 8fdd20b22f6b27b616b5b3a2285a267ffae0a262 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 19 Jun 2012 12:43:09 +0930 Subject: ntdb: add -h arg to ntdbrestore Since our default hashsize is 8192 not 131, we look fat when we convert near-empty TDBs. Signed-off-by: Rusty Russell --- lib/ntdb/tools/ntdbrestore.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/lib/ntdb/tools/ntdbrestore.c b/lib/ntdb/tools/ntdbrestore.c index dad591d562..1df9322e64 100644 --- a/lib/ntdb/tools/ntdbrestore.c +++ b/lib/ntdb/tools/ntdbrestore.c @@ -1,5 +1,6 @@ /* - ntdbrestore -- construct a ntdb from tdbdump output. + ntdbrestore -- construct a ntdb from (n)tdbdump output. + Copyright (C) Rusty Russell 2012 Copyright (C) Volker Lendecke 2010 Copyright (C) Simon McVittie 2005 @@ -188,11 +189,17 @@ fail: return ret; } -static int restore_ntdb(const char *fname) +static int restore_ntdb(const char *fname, unsigned int hsize) { struct ntdb_context *ntdb; + union ntdb_attribute hashsize; - ntdb = ntdb_open(fname, 0, O_RDWR|O_CREAT|O_EXCL, 0666, NULL); + hashsize.base.attr = NTDB_ATTRIBUTE_HASHSIZE; + hashsize.base.next = NULL; + hashsize.hashsize.size = hsize; + + ntdb = ntdb_open(fname, 0, O_RDWR|O_CREAT|O_EXCL, 0666, + hsize ? &hashsize : NULL); if (!ntdb) { perror("ntdb_open"); fprintf(stderr, "Failed to open %s\n", fname); @@ -218,14 +225,27 @@ static int restore_ntdb(const char *fname) int main(int argc, char *argv[]) { - char *fname; + unsigned int hsize = 0; + const char *execname = argv[0]; - if (argc < 2) { - printf("Usage: %s dbname < tdbdump_output\n", argv[0]); + if (argv[1] && strcmp(argv[1], "-h") == 0) { + if (argv[2]) { + hsize = atoi(argv[2]); + } + if (hsize == 0) { + fprintf(stderr, "-h requires a integer value" + " (eg. 128 or 131072)\n"); + exit(1); + } + argv += 2; + argc -= 2; + } + if (argc != 2) { + printf("Usage: %s [-h ] dbname < tdbdump_output\n", + execname); exit(1); } - fname = argv[1]; - return restore_ntdb(fname); + return restore_ntdb(argv[1], hsize); } -- cgit