From c30c3def8b94a18b0368c0c6bc2003be30200804 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Thu, 8 Jul 2021 13:18:51 +0300 Subject: [PATCH] mdbx: the `filesize` field of `mdbx_mmap_t` now is not specific for Windows. --- src/osal.c | 27 ++++++++++++--------------- src/osal.h | 2 +- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/osal.c b/src/osal.c index 42abda20..a6c355d4 100644 --- a/src/osal.c +++ b/src/osal.c @@ -1384,9 +1384,9 @@ MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map, map->limit = 0; map->current = 0; map->address = nullptr; + map->filesize = 0; #if defined(_WIN32) || defined(_WIN64) map->section = NULL; - map->filesize = 0; #endif /* Windows */ int err = mdbx_check_fs_local(map->fd, flags); @@ -1397,21 +1397,17 @@ MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map, err = mdbx_ftruncate(map->fd, size); if (err != MDBX_SUCCESS) return err; -#if defined(_WIN32) || defined(_WIN64) map->filesize = size; -#else +#if !(defined(_WIN32) || defined(_WIN64)) map->current = size; -#endif /* ! Windows */ +#endif /* !Windows */ } else { - uint64_t filesize = 0; - err = mdbx_filesize(map->fd, &filesize); + err = mdbx_filesize(map->fd, &map->filesize); if (err != MDBX_SUCCESS) return err; -#if defined(_WIN32) || defined(_WIN64) - map->filesize = filesize; -#else - map->current = (filesize > limit) ? limit : (size_t)filesize; -#endif /* ! Windows */ +#if !(defined(_WIN32) || defined(_WIN64)) + map->current = (map->filesize > limit) ? limit : (size_t)map->filesize; +#endif /* !Windows */ } #if defined(_WIN32) || defined(_WIN64) @@ -1703,20 +1699,21 @@ retry_mapview:; #else /* Windows */ - uint64_t filesize = 0; - int rc = mdbx_filesize(map->fd, &filesize); + map->filesize = 0; + int rc = mdbx_filesize(map->fd, &map->filesize); if (rc != MDBX_SUCCESS) return rc; if (flags & MDBX_RDONLY) { - map->current = (filesize > limit) ? limit : (size_t)filesize; + map->current = (map->filesize > limit) ? limit : (size_t)map->filesize; if (map->current != size) rc = (size > map->current) ? MDBX_UNABLE_EXTEND_MAPSIZE : MDBX_RESULT_TRUE; - } else if (filesize != size) { + } else if (map->filesize != size) { rc = mdbx_ftruncate(map->fd, size); if (rc != MDBX_SUCCESS) return rc; + map->filesize = size; map->current = size; } diff --git a/src/osal.h b/src/osal.h index cdfcc3af..478b7328 100644 --- a/src/osal.h +++ b/src/osal.h @@ -460,8 +460,8 @@ typedef struct mdbx_mmap_param { mdbx_filehandle_t fd; size_t limit; /* mapping length, but NOT a size of file nor DB */ size_t current; /* mapped region size, i.e. the size of file and DB */ -#if defined(_WIN32) || defined(_WIN64) uint64_t filesize /* in-process cache of a file size */; +#if defined(_WIN32) || defined(_WIN64) HANDLE section; /* memory-mapped section handle */ #endif } mdbx_mmap_t;