From 6e16e29d532d7542c210fd725bf61df1e7a97795 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 14 Sep 2011 07:47:13 +0930 Subject: tdb2: add TDB_ATTRIBUTE_TDB1_HASHSIZE This replaces the tdb1_open "hash_size" argument. It will only be valid when you call tdb_open() with O_CREAT in open_flags, and TDB_VERSION1 in tdb_flags. Signed-off-by: Rusty Russell (Imported from CCAN commit 49475d68deecd0b31597ed6094229171d2699b11) --- lib/tdb2/tdb1_open.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'lib/tdb2/tdb1_open.c') diff --git a/lib/tdb2/tdb1_open.c b/lib/tdb2/tdb1_open.c index 1f23db0126..c1729b577f 100644 --- a/lib/tdb2/tdb1_open.c +++ b/lib/tdb2/tdb1_open.c @@ -24,7 +24,7 @@ You should have received a copy of the GNU Lesser General Public License along with this library; if not, see . */ - +#include #include "tdb1_private.h" /* We use two hashes to double-check they're using the right hash function. */ @@ -222,8 +222,6 @@ static struct tdb_context *tdb1_open_ex(const char *name, int hash_size, int tdb goto fail; } - if (hash_size == 0) - hash_size = TDB1_DEFAULT_HASH_SIZE; if ((open_flags & O_ACCMODE) == O_RDONLY) { tdb->flags |= TDB_RDONLY; /* read only databases don't do locking */ @@ -359,12 +357,13 @@ static struct tdb_context *tdb1_open_ex(const char *name, int hash_size, int tdb } /* Temporart wrapper for transition. */ -struct tdb_context *tdb1_open(const char *name, int hash_size, int tdb1_flags, +struct tdb_context *tdb1_open(const char *name, int tdb1_flags, int open_flags, mode_t mode, union tdb_attribute *attr) { struct tdb1_logging_context *log_ctx = NULL, log; tdb1_hash_func hash_fn = NULL; + struct tdb_attribute_tdb1_hashsize *hsize = NULL; while (attr) { switch (attr->base.attr) { @@ -376,13 +375,31 @@ struct tdb_context *tdb1_open(const char *name, int hash_size, int tdb1_flags, log.log_private = attr->log.data; log_ctx = &log; break; + case TDB_ATTRIBUTE_TDB1_HASHSIZE: + hsize = &attr->tdb1_hashsize; + break; + break; default: abort(); } attr = attr->base.next; } - return tdb1_open_ex(name, hash_size, tdb1_flags, open_flags, mode, + if (hsize && !(open_flags & O_CREAT)) { + if (log_ctx) { + log_ctx->log_fn(NULL, + TDB_ERR_EINVAL, + TDB_LOG_USE_ERROR, + "tdb_open: can only use" + " TDB_ATTRIBUTE_TDB1_HASHSIZE when" + " creating a tdb", + log_ctx->log_private); + } + errno = EINVAL; + return NULL; + } + return tdb1_open_ex(name, hsize ? hsize->hsize : TDB1_DEFAULT_HASH_SIZE, + tdb1_flags, open_flags, mode, log_ctx, hash_fn); } -- cgit