Fix Windows I/O.

Don't put a 64-bit filesize in a 32-bit int before shifting
down.  Always pass &sizehi to SetFilePointer->maxsize, so
sizelo not is treated a signed distance.  Hide unused vars
when _WIN32.  Reinitialize OVERLAPPED before reuse.
vmware
Hallvard Furuseth 12 years ago
parent 3d4ba01e8b
commit a5701cf2fe
  1. 22
      libraries/liblmdb/mdb.c

@ -2211,7 +2211,6 @@ mdb_page_flush(MDB_txn *txn)
MDB_page *dp; MDB_page *dp;
#ifdef _WIN32 #ifdef _WIN32
OVERLAPPED ov; OVERLAPPED ov;
memset(&ov, 0, sizeof(ov));
#else #else
struct iovec iov[MDB_COMMIT_PAGES]; struct iovec iov[MDB_COMMIT_PAGES];
ssize_t wpos, wsize, wres; ssize_t wpos, wsize, wres;
@ -2251,9 +2250,9 @@ mdb_page_flush(MDB_txn *txn)
* system call. * system call.
*/ */
DPRINTF("committing page %zu", pgno); DPRINTF("committing page %zu", pgno);
memset(&ov, 0, sizeof(ov));
ov.Offset = pos & 0xffffffff; ov.Offset = pos & 0xffffffff;
ov.OffsetHigh = pos >> 16; ov.OffsetHigh = pos >> 16 >> 16;
ov.OffsetHigh >>= 16;
if (!WriteFile(env->me_fd, dp, size, NULL, &ov)) { if (!WriteFile(env->me_fd, dp, size, NULL, &ov)) {
rc = ErrCode(); rc = ErrCode();
DPRINTF("WriteFile: %d", rc); DPRINTF("WriteFile: %d", rc);
@ -2606,6 +2605,8 @@ mdb_env_write_meta(MDB_txn *txn)
HANDLE mfd; HANDLE mfd;
#ifdef _WIN32 #ifdef _WIN32
OVERLAPPED ov; OVERLAPPED ov;
#else
int r2;
#endif #endif
assert(txn != NULL); assert(txn != NULL);
@ -2674,7 +2675,6 @@ mdb_env_write_meta(MDB_txn *txn)
rc = pwrite(mfd, ptr, len, off); rc = pwrite(mfd, ptr, len, off);
#endif #endif
if (rc != len) { if (rc != len) {
int r2;
rc = ErrCode(); rc = ErrCode();
DPUTS("write failed, disk error?"); DPUTS("write failed, disk error?");
/* On a failure, the pagecache still contains the new data. /* On a failure, the pagecache still contains the new data.
@ -2782,9 +2782,12 @@ static int
mdb_env_open2(MDB_env *env) mdb_env_open2(MDB_env *env)
{ {
unsigned int flags = env->me_flags; unsigned int flags = env->me_flags;
int i, newenv = 0, prot; int i, newenv = 0;
MDB_meta meta; MDB_meta meta;
MDB_page *p; MDB_page *p;
#ifndef _WIN32
int prot;
#endif
memset(&meta, 0, sizeof(meta)); memset(&meta, 0, sizeof(meta));
@ -2815,16 +2818,15 @@ mdb_env_open2(MDB_env *env)
HANDLE mh; HANDLE mh;
LONG sizelo, sizehi; LONG sizelo, sizehi;
sizelo = env->me_mapsize & 0xffffffff; sizelo = env->me_mapsize & 0xffffffff;
sizehi = env->me_mapsize >> 16; /* pointless on WIN32, only needed on W64 */ sizehi = env->me_mapsize >> 16 >> 16; /* only needed on Win64 */
sizehi >>= 16;
/* Windows won't create mappings for zero length files. /* Windows won't create mappings for zero length files.
* Just allocate the maxsize right now. * Just allocate the maxsize right now.
*/ */
if (newenv) { if (newenv) {
SetFilePointer(env->me_fd, sizelo, sizehi ? &sizehi : NULL, 0); if (SetFilePointer(env->me_fd, sizelo, &sizehi, 0) != (DWORD)sizelo
if (!SetEndOfFile(env->me_fd)) || !SetEndOfFile(env->me_fd)
|| SetFilePointer(env->me_fd, 0, NULL, 0) != 0)
return ErrCode(); return ErrCode();
SetFilePointer(env->me_fd, 0, NULL, 0);
} }
mh = CreateFileMapping(env->me_fd, NULL, flags & MDB_WRITEMAP ? mh = CreateFileMapping(env->me_fd, NULL, flags & MDB_WRITEMAP ?
PAGE_READWRITE : PAGE_READONLY, PAGE_READWRITE : PAGE_READONLY,

Loading…
Cancel
Save