From: Howard Chu Date: Fri, 23 Sep 2011 01:05:06 +0000 (-0700) Subject: Add MDB_NOSUBDIR option X-Git-Tag: OPENLDAP_REL_ENG_2_4_27~148^2~13 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=7a40080dd185cdce547769a6c747238a54c1013e;p=openldap Add MDB_NOSUBDIR option Create the data file using exactly the given pathname, and the lock file using a suffix on the data file name. --- diff --git a/libraries/libmdb/mdb.c b/libraries/libmdb/mdb.c index 89048ae272..dd60fb1af0 100644 --- a/libraries/libmdb/mdb.c +++ b/libraries/libmdb/mdb.c @@ -2657,6 +2657,9 @@ fail: #define LOCKNAME "/lock.mdb" /** The name of the data file in the DB environment */ #define DATANAME "/data.mdb" + /** The suffix of the lock file when no subdir is used */ +#define LOCKSUFF "-lock" + int mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mode_t mode) { @@ -2664,12 +2667,23 @@ mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mode_t mode) char *lpath, *dpath; len = strlen(path); - lpath = malloc(len + sizeof(LOCKNAME) + len + sizeof(DATANAME)); + if (flags & MDB_NOSUBDIR) { + rc = len + sizeof(LOCKSUFF) + len + 1; + } else { + rc = len + sizeof(LOCKNAME) + len + sizeof(DATANAME); + } + lpath = malloc(rc); if (!lpath) return ENOMEM; - dpath = lpath + len + sizeof(LOCKNAME); - sprintf(lpath, "%s" LOCKNAME, path); - sprintf(dpath, "%s" DATANAME, path); + if (flags & MDB_NOSUBDIR) { + dpath = lpath + len + sizeof(LOCKSUFF); + sprintf(lpath, "%s" LOCKSUFF, path); + strcpy(dpath, path); + } else { + dpath = lpath + len + sizeof(LOCKNAME); + sprintf(lpath, "%s" LOCKNAME, path); + sprintf(dpath, "%s" DATANAME, path); + } rc = mdb_env_setup_locks(env, lpath, mode, &excl); if (rc) diff --git a/libraries/libmdb/mdb.h b/libraries/libmdb/mdb.h index 949936782f..7653542e6b 100644 --- a/libraries/libmdb/mdb.h +++ b/libraries/libmdb/mdb.h @@ -149,6 +149,8 @@ typedef void (MDB_rel_func)(MDB_val *item, void *oldptr, void *newptr, void *rel */ /** mmap at a fixed address */ #define MDB_FIXEDMAP 0x01 + /** no environment directory */ +#define MDB_NOSUBDIR 0x02 /** don't fsync after commit */ #define MDB_NOSYNC 0x10000 /** read only */