diff --git a/src/core.c b/src/core.c index 634969a5..a47a9c08 100644 --- a/src/core.c +++ b/src/core.c @@ -20536,14 +20536,13 @@ LIBMDBX_API int mdbx_env_copyW(MDBX_env *env, const wchar_t *dest_path, /* no locking required since the file opened with ShareMode == 0 */ #else if (rc == MDBX_SUCCESS) { - struct flock lock_op; + MDBX_STRUCT_FLOCK lock_op; memset(&lock_op, 0, sizeof(lock_op)); lock_op.l_type = F_WRLCK; lock_op.l_whence = SEEK_SET; lock_op.l_start = 0; - lock_op.l_len = - (sizeof(lock_op.l_len) > 4 ? INT64_MAX : INT32_MAX) & ~(size_t)0xffff; - if (fcntl(newfd, F_SETLK, &lock_op) + lock_op.l_len = OFF_T_MAX; + if (MDBX_FCNTL(newfd, MDBX_F_SETLK, &lock_op) #if (defined(__linux__) || defined(__gnu_linux__)) && defined(LOCK_EX) && \ (!defined(__ANDROID_API__) || __ANDROID_API__ >= 24) || flock(newfd, LOCK_EX | LOCK_NB) diff --git a/src/lck-posix.c b/src/lck-posix.c index b881698d..afbe542b 100644 --- a/src/lck-posix.c +++ b/src/lck-posix.c @@ -178,26 +178,21 @@ __cold static void choice_fcntl(void) { of reliability reasons */ #endif /* linux */ ) { - op_setlk = F_OFD_SETLK; - op_setlkw = F_OFD_SETLKW; - op_getlk = F_OFD_GETLK; + op_setlk = MDBX_F_OFD_SETLK; + op_setlkw = MDBX_F_OFD_SETLKW; + op_getlk = MDBX_F_OFD_GETLK; return; } - op_setlk = F_SETLK; - op_setlkw = F_SETLKW; - op_getlk = F_GETLK; + op_setlk = MDBX_F_SETLK; + op_setlkw = MDBX_F_SETLKW; + op_getlk = MDBX_F_GETLK; } #else -#define op_setlk F_SETLK -#define op_setlkw F_SETLKW -#define op_getlk F_GETLK +#define op_setlk MDBX_F_SETLK +#define op_setlkw MDBX_F_SETLKW +#define op_getlk MDBX_F_GETLK #endif /* MDBX_USE_OFDLOCKS */ -#ifndef OFF_T_MAX -#define OFF_T_MAX \ - (((sizeof(off_t) > 4) ? INT64_MAX : INT32_MAX) & ~(size_t)0xffff) -#endif - static int lck_op(const mdbx_filehandle_t fd, int cmd, const int lck, const off_t offset, off_t len) { STATIC_ASSERT(sizeof(off_t) >= sizeof(void *) && @@ -220,7 +215,7 @@ static int lck_op(const mdbx_filehandle_t fd, int cmd, const int lck, assert((uint64_t)((off_t)((uint64_t)offset + (uint64_t)len)) == ((uint64_t)offset + (uint64_t)len)); for (;;) { - struct flock lock_op; + MDBX_STRUCT_FLOCK lock_op; STATIC_ASSERT_MSG(sizeof(off_t) <= sizeof(lock_op.l_start) && sizeof(off_t) <= sizeof(lock_op.l_len) && OFF_T_MAX == (off_t)OFF_T_MAX, @@ -232,7 +227,7 @@ static int lck_op(const mdbx_filehandle_t fd, int cmd, const int lck, lock_op.l_whence = SEEK_SET; lock_op.l_start = offset; lock_op.l_len = len; - int rc = fcntl(fd, cmd, &lock_op); + int rc = MDBX_FCNTL(fd, cmd, &lock_op); jitter4testing(true); if (rc != -1) { if (cmd == op_getlk) { @@ -246,18 +241,18 @@ static int lck_op(const mdbx_filehandle_t fd, int cmd, const int lck, } rc = errno; #if MDBX_USE_OFDLOCKS - if (rc == EINVAL && - (cmd == F_OFD_SETLK || cmd == F_OFD_SETLKW || cmd == F_OFD_GETLK)) { + if (rc == EINVAL && (cmd == MDBX_F_OFD_SETLK || cmd == MDBX_F_OFD_SETLKW || + cmd == MDBX_F_OFD_GETLK)) { /* fallback to non-OFD locks */ - if (cmd == F_OFD_SETLK) - cmd = F_SETLK; - else if (cmd == F_OFD_SETLKW) - cmd = F_SETLKW; + if (cmd == MDBX_F_OFD_SETLK) + cmd = MDBX_F_SETLK; + else if (cmd == MDBX_F_OFD_SETLKW) + cmd = MDBX_F_SETLKW; else - cmd = F_GETLK; - op_setlk = F_SETLK; - op_setlkw = F_SETLKW; - op_getlk = F_GETLK; + cmd = MDBX_F_GETLK; + op_setlk = MDBX_F_SETLK; + op_setlkw = MDBX_F_SETLKW; + op_getlk = MDBX_F_GETLK; continue; } #endif /* MDBX_USE_OFDLOCKS */ diff --git a/src/options.h b/src/options.h index c81529fd..762bd2eb 100644 --- a/src/options.h +++ b/src/options.h @@ -269,7 +269,10 @@ /** Advanced: Using POSIX OFD-locks (autodetection by default). */ #ifndef MDBX_USE_OFDLOCKS -#if defined(F_OFD_SETLK) && defined(F_OFD_SETLKW) && defined(F_OFD_GETLK) && \ +#if ((defined(F_OFD_SETLK) && defined(F_OFD_SETLKW) && \ + defined(F_OFD_GETLK)) || \ + (defined(F_OFD_SETLK64) && defined(F_OFD_SETLKW64) && \ + defined(F_OFD_GETLK64))) && \ !defined(MDBX_SAFE4QEMU) && \ !defined(__sun) /* OFD-lock are broken on Solaris */ #define MDBX_USE_OFDLOCKS 1 diff --git a/src/osal.h b/src/osal.h index b3eda1c0..6876911b 100644 --- a/src/osal.h +++ b/src/osal.h @@ -425,6 +425,40 @@ MDBX_MAYBE_UNUSED static __inline void jitter4testing(bool tiny); #define MAX_WRITE UINT32_C(0x04000000) #else #define MAX_WRITE UINT32_C(0x3f000000) + +#if defined(F_GETLK64) && defined(F_SETLK64) && defined(F_SETLKW64) && \ + !defined(__ANDROID_API__) +#define MDBX_F_SETLK F_SETLK64 +#define MDBX_F_SETLKW F_SETLKW64 +#define MDBX_F_GETLK F_GETLK64 +#define MDBX_FCNTL fcntl64 +#define MDBX_STRUCT_FLOCK struct flock64 +#ifndef OFF_T_MAX +#define OFF_T_MAX UINT64_C(0x7fffFFFFfff00000) +#endif /* OFF_T_MAX */ +#else +#define MDBX_F_SETLK F_SETLK +#define MDBX_F_SETLKW F_SETLKW +#define MDBX_F_GETLK F_GETLK +#define MDBX_FCNTL fcntl +#define MDBX_STRUCT_FLOCK struct flock +#endif /* MDBX_F_SETLK, MDBX_F_SETLKW, MDBX_F_GETLK */ + +#if defined(F_OFD_SETLK64) && defined(F_OFD_SETLKW64) && \ + defined(F_OFD_GETLK64) && !defined(__ANDROID_API__) +#define MDBX_F_OFD_SETLK F_OFD_SETLK64 +#define MDBX_F_OFD_SETLKW F_OFD_SETLKW64 +#define MDBX_F_OFD_GETLK F_OFD_GETLK64 +#else +#define MDBX_F_OFD_SETLK F_OFD_SETLK +#define MDBX_F_OFD_SETLKW F_OFD_SETLKW +#define MDBX_F_OFD_GETLK F_OFD_GETLK +#ifndef OFF_T_MAX +#define OFF_T_MAX \ + (((sizeof(off_t) > 4) ? INT64_MAX : INT32_MAX) & ~(size_t)0xFffff) +#endif /* OFF_T_MAX */ +#endif /* MDBX_F_OFD_SETLK64, MDBX_F_OFD_SETLKW64, MDBX_F_OFD_GETLK64 */ + #endif #if defined(__linux__) || defined(__gnu_linux__)