summaryrefslogtreecommitdiff
path: root/lib/tdb2/tdb1_open.c
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2011-09-14 07:47:13 +0930
committerRusty Russell <rusty@rustcorp.com.au>2011-09-14 07:47:13 +0930
commit6e16e29d532d7542c210fd725bf61df1e7a97795 (patch)
tree463f4867fe4ff441d924672b564f508632e57c02 /lib/tdb2/tdb1_open.c
parentf8dbfad23c9cab9d52b366d56e8491666a90f714 (diff)
downloadsamba-6e16e29d532d7542c210fd725bf61df1e7a97795.tar.gz
samba-6e16e29d532d7542c210fd725bf61df1e7a97795.tar.bz2
samba-6e16e29d532d7542c210fd725bf61df1e7a97795.zip
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 <rusty@rustcorp.com.au> (Imported from CCAN commit 49475d68deecd0b31597ed6094229171d2699b11)
Diffstat (limited to 'lib/tdb2/tdb1_open.c')
-rw-r--r--lib/tdb2/tdb1_open.c27
1 files changed, 22 insertions, 5 deletions
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 <http://www.gnu.org/licenses/>.
*/
-
+#include <assert.h>
#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);
}