From 52e3adbdec847e3f8cd6ddcd35a7e4b94cd40e9f Mon Sep 17 00:00:00 2001 From: Hallvard Furuseth Date: Tue, 27 Nov 2012 23:56:47 +0100 Subject: [PATCH] Renumber MDB_NOSUBDIR. Check mdb_env_open() flags. MDB_NOSUBDIR was == MDB_REVERSEKEY. That affected the freelist: Env flags are stored in mm_flags alias mm_dbs[FREE_DBI].md_flags. It stays a persistent flag, in case mdb_env_open someday wants to pick/verify which lockfile to use with the datafile. Catch bad flags so they will no longer make it into the data file. --- libraries/libmdb/mdb.c | 13 +++++++------ libraries/libmdb/mdb.h | 6 +++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/libraries/libmdb/mdb.c b/libraries/libmdb/mdb.c index e1a8689..6771829 100644 --- a/libraries/libmdb/mdb.c +++ b/libraries/libmdb/mdb.c @@ -3146,6 +3146,12 @@ fail: #define DATANAME "/data.mdb" /** The suffix of the lock file when no subdir is used */ #define LOCKSUFF "-lock" + /** Only a subset of the @ref mdb_env flags can be changed + * at runtime. Changing other flags requires closing the + * environment and re-opening it with the new flags. + */ +#define CHANGEABLE (MDB_NOSYNC|MDB_NOMETASYNC|MDB_MAPASYNC) +#define CHANGELESS (MDB_FIXEDMAP|MDB_NOSUBDIR|MDB_RDONLY|MDB_WRITEMAP) int mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mode_t mode) @@ -3153,7 +3159,7 @@ mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mode_t mode) int oflags, rc, len, excl; char *lpath, *dpath; - if (env->me_fd != INVALID_HANDLE_VALUE) + if (env->me_fd!=INVALID_HANDLE_VALUE || (flags & ~(CHANGEABLE|CHANGELESS))) return EINVAL; len = strlen(path); @@ -6599,11 +6605,6 @@ mdb_put(MDB_txn *txn, MDB_dbi dbi, return mdb_cursor_put(&mc, key, data, flags); } -/** Only a subset of the @ref mdb_env flags can be changed - * at runtime. Changing other flags requires closing the environment - * and re-opening it with the new flags. - */ -#define CHANGEABLE (MDB_NOSYNC|MDB_NOMETASYNC|MDB_MAPASYNC) int mdb_env_set_flags(MDB_env *env, unsigned int flag, int onoff) { diff --git a/libraries/libmdb/mdb.h b/libraries/libmdb/mdb.h index e3fc129..e314595 100644 --- a/libraries/libmdb/mdb.h +++ b/libraries/libmdb/mdb.h @@ -213,12 +213,14 @@ typedef int (MDB_cmp_func)(const MDB_val *a, const MDB_val *b); typedef void (MDB_rel_func)(MDB_val *item, void *oldptr, void *newptr, void *relctx); /** @defgroup mdb_env Environment Flags + * + * Values do not overlap Database Flags. * @{ */ /** mmap at a fixed address */ #define MDB_FIXEDMAP 0x01 /** no environment directory */ -#define MDB_NOSUBDIR 0x02 +#define MDB_NOSUBDIR 0x4000 /** don't fsync after commit */ #define MDB_NOSYNC 0x10000 /** read only */ @@ -232,6 +234,8 @@ typedef void (MDB_rel_func)(MDB_val *item, void *oldptr, void *newptr, void *rel /** @} */ /** @defgroup mdb_open Database Flags + * + * Values do not overlap Environment Flags. * @{ */ /** use reverse string keys */