summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Adamansky <adamansky@gmail.com>2015-07-10 12:57:21 +0600
committerAnton Adamansky <adamansky@gmail.com>2015-07-10 12:57:21 +0600
commit8965b74aafc7e7fba104031f2166f7802512c49b (patch)
treed3156ffd67c8392b6c00663257bb51288375b675
parent5cc701a95c261840c75075a00c2908896d1f9fb8 (diff)
parent14e629e841b0468a484165f9fe232d0b393450b1 (diff)
downloadejdb-8965b74aafc7e7fba104031f2166f7802512c49b.tar.gz
ejdb-8965b74aafc7e7fba104031f2166f7802512c49b.tar.bz2
ejdb-8965b74aafc7e7fba104031f2166f7802512c49b.zip
Merge branch 'ticket149'
-rw-r--r--CMakeLists.txt1
-rw-r--r--Changelog1
-rw-r--r--src/tchdb/tchdb.c22
-rw-r--r--src/tcutil/win32/platform.h1
4 files changed, 14 insertions, 11 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ff23dc4..5d6c68d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -44,6 +44,7 @@ endif(POLICY CMP0042)
if (CMAKE_SIZEOF_VOID_P MATCHES 8)
set(PROJECT_ARCH "x86_64")
+ add_definitions("-D_FILE_OFFSET_BITS=64")
else(CMAKE_SIZEOF_VOID_P MATCHES 8)
set(PROJECT_ARCH "x86")
endif(CMAKE_SIZEOF_VOID_P MATCHES 8)
diff --git a/Changelog b/Changelog
index 84219a4..795c47e 100644
--- a/Changelog
+++ b/Changelog
@@ -1,6 +1,7 @@
ejdb (1.2.9) UNRELEASED; urgency=low
* Fix: Builds shared lib when -DBUILD_SHARED_LIBS:BOOL=OFF #143
+ * Fix: Not able to store data above 2GB on windows #149
-- Anton Adamansky <adamansky@gmail.com> Tue, 09 Jun 2015 12:04:51 +0600
diff --git a/src/tchdb/tchdb.c b/src/tchdb/tchdb.c
index 8ea46fb..45dee6a 100644
--- a/src/tchdb/tchdb.c
+++ b/src/tchdb/tchdb.c
@@ -45,11 +45,11 @@
#define HDBDEFFPOW 10 // default free block pool power
#define HDBMAXFPOW 20 // maximum free block pool power
-#ifdef _WIN32
-#define HDBDEFXMSIZ _maxof(off_t) // default size of the extra mapped memory
-#else
+//#ifdef _WIN32
+//#define HDBDEFXMSIZ _maxof(off_t) // default size of the extra mapped memory
+//#else
#define HDBDEFXMSIZ (64LL<<20) // default size of the extra mapped memory
-#endif
+//#endif
#define HDBXFSIZINC 1048576 // 1MB increment of extra file size
#define HDBMINRUNIT 48 // minimum record reading unit
#define HDBMAXHSIZ 32 // maximum record header size
@@ -359,10 +359,6 @@ bool tchdbsetcache(TCHDB *hdb, int32_t rcnum) {
/* Set the size of the extra mapped memory of a hash database object. */
bool tchdbsetxmsiz(TCHDB *hdb, int64_t xmsiz) {
-#if defined (_WIN32)
- //fprintf(stderr, "\ntchdbsetxmsiz does not takes effect on windows platform\n");
- return true;
-#else
assert(hdb);
if (!INVALIDHANDLE(hdb->fd)) {
tchdbsetecode(hdb, TCEINVALID, __FILE__, __LINE__, __func__);
@@ -370,7 +366,6 @@ bool tchdbsetxmsiz(TCHDB *hdb, int64_t xmsiz) {
}
hdb->xmsiz = (xmsiz > 0) ? tcpagealign(xmsiz) : 0;
return true;
-#endif
}
/* Set the unit step number of auto defragmentation of a hash database object. */
@@ -5645,7 +5640,7 @@ static bool tchdbftruncate2(TCHDB *hdb, off_t length, int opts) {
}
#else
bool err = false;
- LARGE_INTEGER size;
+ LARGE_INTEGER size, msize;
//MSDN: Applications should test for files with a length of 0 (zero) and reject those files.
size.QuadPart = (hdb->omode & HDBOWRITER) ? tcpagealign((length == 0) ? 1 : length) : length;
if (hdb->map &&
@@ -5656,11 +5651,13 @@ static bool tchdbftruncate2(TCHDB *hdb, off_t length, int opts) {
if (!(opts & HDBOPTNOSMLOCK) && !HDBLOCKSMEMPTR2(hdb, true)) {
return false;
}
+
if ((hdb->omode & HDBOWRITER) && size.QuadPart > xfsiz && !(opts & HDBTRALLOWSHRINK)) {
off_t o1 = tcpagealign((_maxof(off_t) - (off_t) size.QuadPart < HDBXFSIZINC) ? size.QuadPart : size.QuadPart + HDBXFSIZINC);
off_t o2 = tcpagealign((((uint64_t) size.QuadPart) * 3) >> 1);
size.QuadPart = MAX(o1, o2);
}
+ msize = size;
if (hdb->map) {
FlushViewOfFile((LPCVOID) hdb->map, 0);
if (!UnmapViewOfFile((LPCVOID) hdb->map) || !CloseHandle(hdb->w32hmap)) {
@@ -5678,9 +5675,12 @@ static bool tchdbftruncate2(TCHDB *hdb, off_t length, int opts) {
goto finish;
}
}
+ if (msize.QuadPart > hdb->xmsiz) {
+ msize.QuadPart = hdb->xmsiz;
+ }
hdb->w32hmap = CreateFileMapping(hdb->fd, NULL,
((hdb->omode & HDBOWRITER) ? PAGE_READWRITE : PAGE_READONLY),
- size.HighPart, size.LowPart, NULL);
+ msize.HighPart, msize.LowPart, NULL);
if (INVALIDHANDLE(hdb->w32hmap)) {
tchdbsetecode(hdb, TCEMMAP, __FILE__, __LINE__, __func__);
err = true;
diff --git a/src/tcutil/win32/platform.h b/src/tcutil/win32/platform.h
index a111070..a037e21 100644
--- a/src/tcutil/win32/platform.h
+++ b/src/tcutil/win32/platform.h
@@ -46,6 +46,7 @@ ssize_t win_pwrite(HANDLE fd, const void *buf, size_t count, off_t offset);
ssize_t win_pread(HANDLE fd, void *buf, size_t size, off_t off);
#define mkdir(a, b) _mkdir(a)
+#undef fstat
#define fstat win_fstat
#define lstat stat
#define sysconf_SC_CLK_TCK 64