diff options
author | Volker Lendecke <vl@samba.org> | 2012-12-20 16:36:02 +0100 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2013-02-05 13:18:28 +0100 |
commit | 72cd5d5ff664dc46afb3dd6a5ea45a28ef7b8591 (patch) | |
tree | 345e21bb28f13b724fa9ec8ff28b266a2c06ec79 /lib/tdb/common/open.c | |
parent | 71247ec4bdefb3a1b16619f7ea7404bcbafb5b60 (diff) | |
download | samba-72cd5d5ff664dc46afb3dd6a5ea45a28ef7b8591.tar.gz |
tdb: Remove "header" from tdb_context
header.hash_size was the only thing we ever referenced outside of
tdb_open_ex and its direct callees. So this shrinks the tdb_context by
164 bytes.
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Autobuild-User(master): Stefan Metzmacher <metze@samba.org>
Autobuild-Date(master): Tue Feb 5 13:18:28 CET 2013 on sn-devel-104
Diffstat (limited to 'lib/tdb/common/open.c')
-rw-r--r-- | lib/tdb/common/open.c | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/lib/tdb/common/open.c b/lib/tdb/common/open.c index 6630d64eac2..08b9450a1c2 100644 --- a/lib/tdb/common/open.c +++ b/lib/tdb/common/open.c @@ -170,6 +170,7 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td const struct tdb_logging_context *log_ctx, tdb_hash_func hash_fn) { + struct tdb_header header; struct tdb_context *tdb; struct stat st; int rev = 0, locked = 0; @@ -179,6 +180,8 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td const char *hash_alg; uint32_t magic1, magic2; + ZERO_STRUCT(header); + if (!(tdb = (struct tdb_context *)calloc(1, sizeof *tdb))) { /* Can't log this */ errno = ENOMEM; @@ -288,10 +291,11 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td if (tdb->flags & TDB_INTERNAL) { tdb->flags |= (TDB_NOLOCK | TDB_NOMMAP); tdb->flags &= ~TDB_CLEAR_IF_FIRST; - if (tdb_new_database(tdb, &tdb->header, hash_size) != 0) { + if (tdb_new_database(tdb, &header, hash_size) != 0) { TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: tdb_new_database failed!")); goto fail; } + tdb->hash_size = hash_size; goto internal; } @@ -325,7 +329,7 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td name, strerror(errno))); goto fail; } - ret = tdb_new_database(tdb, &tdb->header, hash_size); + ret = tdb_new_database(tdb, &header, hash_size); if (ret == -1) { TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_open_ex: " "tdb_new_database failed for %s: %s\n", @@ -350,23 +354,23 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td } errno = 0; - if (read(tdb->fd, &tdb->header, sizeof(tdb->header)) != sizeof(tdb->header) - || strcmp(tdb->header.magic_food, TDB_MAGIC_FOOD) != 0) { + if (read(tdb->fd, &header, sizeof(header)) != sizeof(header) + || strcmp(header.magic_food, TDB_MAGIC_FOOD) != 0) { if (!(open_flags & O_CREAT) || - tdb_new_database(tdb, &tdb->header, hash_size) == -1) { + tdb_new_database(tdb, &header, hash_size) == -1) { if (errno == 0) { errno = EIO; /* ie bad format or something */ } goto fail; } rev = (tdb->flags & TDB_CONVERT); - } else if (tdb->header.version != TDB_VERSION - && !(rev = (tdb->header.version==TDB_BYTEREV(TDB_VERSION)))) { + } else if (header.version != TDB_VERSION + && !(rev = (header.version==TDB_BYTEREV(TDB_VERSION)))) { /* wrong version */ errno = EIO; goto fail; } - vp = (unsigned char *)&tdb->header.version; + vp = (unsigned char *)&header.version; vertest = (((uint32_t)vp[0]) << 24) | (((uint32_t)vp[1]) << 16) | (((uint32_t)vp[2]) << 8) | (uint32_t)vp[3]; tdb->flags |= (vertest==TDB_VERSION) ? TDB_BIGENDIAN : 0; @@ -374,32 +378,33 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td tdb->flags &= ~TDB_CONVERT; else { tdb->flags |= TDB_CONVERT; - tdb_convert(&tdb->header, sizeof(tdb->header)); + tdb_convert(&header, sizeof(header)); } if (fstat(tdb->fd, &st) == -1) goto fail; - if (tdb->header.rwlocks != 0 && - tdb->header.rwlocks != TDB_HASH_RWLOCK_MAGIC) { + if (header.rwlocks != 0 && + header.rwlocks != TDB_HASH_RWLOCK_MAGIC) { TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: spinlocks no longer supported\n")); goto fail; } + tdb->hash_size = header.hash_size; - if ((tdb->header.magic1_hash == 0) && (tdb->header.magic2_hash == 0)) { + if ((header.magic1_hash == 0) && (header.magic2_hash == 0)) { /* older TDB without magic hash references */ tdb->hash_fn = tdb_old_hash; - } else if (!check_header_hash(tdb, &tdb->header, !hash_fn, + } else if (!check_header_hash(tdb, &header, !hash_fn, &magic1, &magic2)) { TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_open_ex: " "%s was not created with %s hash function we are using\n" "magic1_hash[0x%08X %s 0x%08X] " "magic2_hash[0x%08X %s 0x%08X]\n", name, hash_alg, - tdb->header.magic1_hash, - (tdb->header.magic1_hash == magic1) ? "==" : "!=", + header.magic1_hash, + (header.magic1_hash == magic1) ? "==" : "!=", magic1, - tdb->header.magic2_hash, - (tdb->header.magic2_hash == magic2) ? "==" : "!=", + header.magic2_hash, + (header.magic2_hash == magic2) ? "==" : "!=", magic2)); errno = EINVAL; goto fail; |