|
|
@ -1239,7 +1239,7 @@ typedef struct MDB_pgstate { |
|
|
|
struct MDB_env { |
|
|
|
struct MDB_env { |
|
|
|
HANDLE me_fd; /**< The main data file */ |
|
|
|
HANDLE me_fd; /**< The main data file */ |
|
|
|
HANDLE me_lfd; /**< The lock file */ |
|
|
|
HANDLE me_lfd; /**< The lock file */ |
|
|
|
HANDLE me_mfd; /**< just for writing the meta pages */ |
|
|
|
HANDLE me_mfd; /**< For writing and syncing the meta pages */ |
|
|
|
/** Failed to update the meta page. Probably an I/O error. */ |
|
|
|
/** Failed to update the meta page. Probably an I/O error. */ |
|
|
|
#define MDB_FATAL_ERROR 0x80000000U |
|
|
|
#define MDB_FATAL_ERROR 0x80000000U |
|
|
|
/** Some fields are initialized. */ |
|
|
|
/** Some fields are initialized. */ |
|
|
@ -3827,7 +3827,10 @@ mdb_env_write_meta(MDB_txn *txn) |
|
|
|
len = sizeof(MDB_meta) - off; |
|
|
|
len = sizeof(MDB_meta) - off; |
|
|
|
off += (char *)mp - env->me_map; |
|
|
|
off += (char *)mp - env->me_map; |
|
|
|
|
|
|
|
|
|
|
|
/* Write to the SYNC fd */ |
|
|
|
/* Write to the SYNC fd unless MDB_NOSYNC/MDB_NOMETASYNC.
|
|
|
|
|
|
|
|
* (me_mfd goes to the same file as me_fd, but writing to it |
|
|
|
|
|
|
|
* also syncs to disk. Avoids a separate fdatasync() call.) |
|
|
|
|
|
|
|
*/ |
|
|
|
mfd = (flags & (MDB_NOSYNC|MDB_NOMETASYNC)) ? env->me_fd : env->me_mfd; |
|
|
|
mfd = (flags & (MDB_NOSYNC|MDB_NOMETASYNC)) ? env->me_fd : env->me_mfd; |
|
|
|
#ifdef _WIN32 |
|
|
|
#ifdef _WIN32 |
|
|
|
{ |
|
|
|
{ |
|
|
@ -4156,7 +4159,7 @@ enum mdb_fopen_type { |
|
|
|
/* A comment in mdb_fopen() explains some O_* flag choices. */ |
|
|
|
/* A comment in mdb_fopen() explains some O_* flag choices. */ |
|
|
|
MDB_O_RDONLY= O_RDONLY, /**< for RDONLY me_fd */ |
|
|
|
MDB_O_RDONLY= O_RDONLY, /**< for RDONLY me_fd */ |
|
|
|
MDB_O_RDWR = O_RDWR |O_CREAT, /**< for me_fd */ |
|
|
|
MDB_O_RDWR = O_RDWR |O_CREAT, /**< for me_fd */ |
|
|
|
MDB_O_META = O_RDWR |MDB_DSYNC |MDB_CLOEXEC, /**< for me_mfd */ |
|
|
|
MDB_O_META = O_WRONLY|MDB_DSYNC |MDB_CLOEXEC, /**< for me_mfd */ |
|
|
|
MDB_O_COPY = O_WRONLY|O_CREAT|O_EXCL|MDB_CLOEXEC, /**< for #mdb_env_copy() */ |
|
|
|
MDB_O_COPY = O_WRONLY|O_CREAT|O_EXCL|MDB_CLOEXEC, /**< for #mdb_env_copy() */ |
|
|
|
/** Bitmask for open() flags in enum #mdb_fopen_type. The other bits
|
|
|
|
/** Bitmask for open() flags in enum #mdb_fopen_type. The other bits
|
|
|
|
* distinguish otherwise-equal MDB_O_* constants from each other. |
|
|
|
* distinguish otherwise-equal MDB_O_* constants from each other. |
|
|
@ -4217,6 +4220,7 @@ mdb_fopen(const MDB_env *env, MDB_name *fname, |
|
|
|
disp = OPEN_EXISTING; |
|
|
|
disp = OPEN_EXISTING; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case MDB_O_META: /* for writing metapages */ |
|
|
|
case MDB_O_META: /* for writing metapages */ |
|
|
|
|
|
|
|
acc = GENERIC_WRITE; |
|
|
|
disp = OPEN_EXISTING; |
|
|
|
disp = OPEN_EXISTING; |
|
|
|
attrs = FILE_ATTRIBUTE_NORMAL|FILE_FLAG_WRITE_THROUGH; |
|
|
|
attrs = FILE_ATTRIBUTE_NORMAL|FILE_FLAG_WRITE_THROUGH; |
|
|
|
break; |
|
|
|
break; |
|
|
@ -4955,9 +4959,7 @@ mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mdb_mode_t mode |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ((rc = mdb_env_open2(env)) == MDB_SUCCESS) { |
|
|
|
if ((rc = mdb_env_open2(env)) == MDB_SUCCESS) { |
|
|
|
if (flags & (MDB_RDONLY|MDB_WRITEMAP)) { |
|
|
|
if (!(flags & (MDB_RDONLY|MDB_WRITEMAP))) { |
|
|
|
env->me_mfd = env->me_fd; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
/* Synchronous fd for meta writes. Needed even with
|
|
|
|
/* Synchronous fd for meta writes. Needed even with
|
|
|
|
* MDB_NOSYNC/MDB_NOMETASYNC, in case these get reset. |
|
|
|
* MDB_NOSYNC/MDB_NOMETASYNC, in case these get reset. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -5040,7 +5042,7 @@ mdb_env_close0(MDB_env *env, int excl) |
|
|
|
if (env->me_map) { |
|
|
|
if (env->me_map) { |
|
|
|
munmap(env->me_map, env->me_mapsize); |
|
|
|
munmap(env->me_map, env->me_mapsize); |
|
|
|
} |
|
|
|
} |
|
|
|
if (env->me_mfd != env->me_fd && env->me_mfd != INVALID_HANDLE_VALUE) |
|
|
|
if (env->me_mfd != INVALID_HANDLE_VALUE) |
|
|
|
(void) close(env->me_mfd); |
|
|
|
(void) close(env->me_mfd); |
|
|
|
if (env->me_fd != INVALID_HANDLE_VALUE) |
|
|
|
if (env->me_fd != INVALID_HANDLE_VALUE) |
|
|
|
(void) close(env->me_fd); |
|
|
|
(void) close(env->me_fd); |
|
|
|