r23795: more v2->v3 conversion
[samba.git] / source4 / lib / tdb / common / open.c
index 29ce1242ccf9922f6f3704addd6fef6cf6fc5736..a856ab78b1b91557266517c8998773d294133479 100644 (file)
@@ -14,7 +14,7 @@
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
-   version 2 of the License, or (at your option) any later version.
+   version 3 of the License, or (at your option) any later version.
 
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -54,7 +54,7 @@ static int tdb_new_database(struct tdb_context *tdb, int hash_size)
 
        /* We make it up in memory, then write it out if not internal */
        size = sizeof(struct tdb_header) + (hash_size+1)*sizeof(tdb_off_t);
-       if (!(newdb = calloc(size, 1)))
+       if (!(newdb = (struct tdb_header *)calloc(size, 1)))
                return TDB_ERRCODE(TDB_ERR_OOM, -1);
 
        /* Fill in the header */
@@ -140,7 +140,7 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
        unsigned char *vp;
        u32 vertest;
 
-       if (!(tdb = calloc(1, sizeof *tdb))) {
+       if (!(tdb = (struct tdb_context *)calloc(1, sizeof *tdb))) {
                /* Can't log this */
                errno = ENOMEM;
                goto fail;
@@ -263,14 +263,7 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
        tdb->map_size = st.st_size;
        tdb->device = st.st_dev;
        tdb->inode = st.st_ino;
-       tdb->locked = calloc(tdb->header.hash_size+1, sizeof(tdb->locked[0]));
-       if (!tdb->locked) {
-               TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: "
-                        "failed to allocate lock structure for %s\n",
-                        name));
-               errno = ENOMEM;
-               goto fail;
-       }
+       tdb->max_dead_records = 0;
        tdb_mmap(tdb);
        if (locked) {
                if (tdb->methods->tdb_brlock(tdb, ACTIVE_LOCK, F_UNLCK, F_SETLK, 0, 1) == -1) {
@@ -323,13 +316,21 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
        if (tdb->fd != -1)
                if (close(tdb->fd) != 0)
                        TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: failed to close tdb->fd on error!\n"));
-       SAFE_FREE(tdb->locked);
        SAFE_FREE(tdb);
        errno = save_errno;
        return NULL;
        }
 }
 
+/*
+ * Set the maximum number of dead records per hash chain
+ */
+
+void tdb_set_max_dead(struct tdb_context *tdb, int max_dead)
+{
+       tdb->max_dead_records = max_dead;
+}
+
 /**
  * Close a database.
  *
@@ -353,7 +354,7 @@ int tdb_close(struct tdb_context *tdb)
        SAFE_FREE(tdb->name);
        if (tdb->fd != -1)
                ret = close(tdb->fd);
-       SAFE_FREE(tdb->locked);
+       SAFE_FREE(tdb->lockrecs);
 
        /* Remove from contexts list */
        for (i = &tdbs; *i; i = &(*i)->next) {
@@ -371,9 +372,9 @@ int tdb_close(struct tdb_context *tdb)
 
 /* register a loging function */
 void tdb_set_logging_function(struct tdb_context *tdb,
-                              const struct tdb_logging_context *log)
+                              const struct tdb_logging_context *log_ctx)
 {
-        tdb->log = *log;
+        tdb->log = *log_ctx;
 }
 
 void *tdb_get_logging_private(struct tdb_context *tdb)