mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-20 05:18:21 +08:00
mdbx: the filesize
field of mdbx_mmap_t
now is not specific for Windows.
This commit is contained in:
parent
2f74f405ae
commit
c30c3def8b
27
src/osal.c
27
src/osal.c
@ -1384,9 +1384,9 @@ MDBX_INTERNAL_FUNC int mdbx_mmap(const int flags, mdbx_mmap_t *map,
|
|||||||
map->limit = 0;
|
map->limit = 0;
|
||||||
map->current = 0;
|
map->current = 0;
|
||||||
map->address = nullptr;
|
map->address = nullptr;
|
||||||
|
map->filesize = 0;
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
map->section = NULL;
|
map->section = NULL;
|
||||||
map->filesize = 0;
|
|
||||||
#endif /* Windows */
|
#endif /* Windows */
|
||||||
|
|
||||||
int err = mdbx_check_fs_local(map->fd, flags);
|
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);
|
err = mdbx_ftruncate(map->fd, size);
|
||||||
if (err != MDBX_SUCCESS)
|
if (err != MDBX_SUCCESS)
|
||||||
return err;
|
return err;
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
|
||||||
map->filesize = size;
|
map->filesize = size;
|
||||||
#else
|
#if !(defined(_WIN32) || defined(_WIN64))
|
||||||
map->current = size;
|
map->current = size;
|
||||||
#endif /* ! Windows */
|
#endif /* !Windows */
|
||||||
} else {
|
} else {
|
||||||
uint64_t filesize = 0;
|
err = mdbx_filesize(map->fd, &map->filesize);
|
||||||
err = mdbx_filesize(map->fd, &filesize);
|
|
||||||
if (err != MDBX_SUCCESS)
|
if (err != MDBX_SUCCESS)
|
||||||
return err;
|
return err;
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if !(defined(_WIN32) || defined(_WIN64))
|
||||||
map->filesize = filesize;
|
map->current = (map->filesize > limit) ? limit : (size_t)map->filesize;
|
||||||
#else
|
#endif /* !Windows */
|
||||||
map->current = (filesize > limit) ? limit : (size_t)filesize;
|
|
||||||
#endif /* ! Windows */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
@ -1703,20 +1699,21 @@ retry_mapview:;
|
|||||||
|
|
||||||
#else /* Windows */
|
#else /* Windows */
|
||||||
|
|
||||||
uint64_t filesize = 0;
|
map->filesize = 0;
|
||||||
int rc = mdbx_filesize(map->fd, &filesize);
|
int rc = mdbx_filesize(map->fd, &map->filesize);
|
||||||
if (rc != MDBX_SUCCESS)
|
if (rc != MDBX_SUCCESS)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
if (flags & MDBX_RDONLY) {
|
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)
|
if (map->current != size)
|
||||||
rc =
|
rc =
|
||||||
(size > map->current) ? MDBX_UNABLE_EXTEND_MAPSIZE : MDBX_RESULT_TRUE;
|
(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);
|
rc = mdbx_ftruncate(map->fd, size);
|
||||||
if (rc != MDBX_SUCCESS)
|
if (rc != MDBX_SUCCESS)
|
||||||
return rc;
|
return rc;
|
||||||
|
map->filesize = size;
|
||||||
map->current = size;
|
map->current = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -460,8 +460,8 @@ typedef struct mdbx_mmap_param {
|
|||||||
mdbx_filehandle_t fd;
|
mdbx_filehandle_t fd;
|
||||||
size_t limit; /* mapping length, but NOT a size of file nor DB */
|
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 */
|
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 */;
|
uint64_t filesize /* in-process cache of a file size */;
|
||||||
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
HANDLE section; /* memory-mapped section handle */
|
HANDLE section; /* memory-mapped section handle */
|
||||||
#endif
|
#endif
|
||||||
} mdbx_mmap_t;
|
} mdbx_mmap_t;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user