mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-20 05:18:21 +08:00
mdbx-windows: use SetFileInformationByHandle() when available.
Change-Id: I27d9d4271d4328947ad68cdf30af61a31978b4f9
This commit is contained in:
parent
e3ff44d01b
commit
624968b74c
@ -663,6 +663,7 @@ MDBX_srwlock_function mdbx_srwlock_Init, mdbx_srwlock_AcquireShared,
|
|||||||
MDBX_GetFileInformationByHandleEx mdbx_GetFileInformationByHandleEx;
|
MDBX_GetFileInformationByHandleEx mdbx_GetFileInformationByHandleEx;
|
||||||
MDBX_GetVolumeInformationByHandleW mdbx_GetVolumeInformationByHandleW;
|
MDBX_GetVolumeInformationByHandleW mdbx_GetVolumeInformationByHandleW;
|
||||||
MDBX_GetFinalPathNameByHandleW mdbx_GetFinalPathNameByHandleW;
|
MDBX_GetFinalPathNameByHandleW mdbx_GetFinalPathNameByHandleW;
|
||||||
|
MDBX_SetFileInformationByHandle mdbx_SetFileInformationByHandle;
|
||||||
MDBX_NtFsControlFile mdbx_NtFsControlFile;
|
MDBX_NtFsControlFile mdbx_NtFsControlFile;
|
||||||
|
|
||||||
static void mdbx_winnt_import(void) {
|
static void mdbx_winnt_import(void) {
|
||||||
@ -699,6 +700,10 @@ static void mdbx_winnt_import(void) {
|
|||||||
(MDBX_GetFinalPathNameByHandleW)GetProcAddress(
|
(MDBX_GetFinalPathNameByHandleW)GetProcAddress(
|
||||||
hKernel32dll, "GetFinalPathNameByHandleW");
|
hKernel32dll, "GetFinalPathNameByHandleW");
|
||||||
|
|
||||||
|
mdbx_SetFileInformationByHandle =
|
||||||
|
(MDBX_SetFileInformationByHandle)GetProcAddress(
|
||||||
|
hKernel32dll, "SetFileInformationByHandle");
|
||||||
|
|
||||||
const HINSTANCE hNtdll = GetModuleHandleA("ntdll.dll");
|
const HINSTANCE hNtdll = GetModuleHandleA("ntdll.dll");
|
||||||
mdbx_NtFsControlFile =
|
mdbx_NtFsControlFile =
|
||||||
(MDBX_NtFsControlFile)GetProcAddress(hNtdll, "NtFsControlFile");
|
(MDBX_NtFsControlFile)GetProcAddress(hNtdll, "NtFsControlFile");
|
||||||
|
20
src/osal.c
20
src/osal.c
@ -741,11 +741,21 @@ int mdbx_filesize(mdbx_filehandle_t fd, uint64_t *length) {
|
|||||||
|
|
||||||
int mdbx_ftruncate(mdbx_filehandle_t fd, uint64_t length) {
|
int mdbx_ftruncate(mdbx_filehandle_t fd, uint64_t length) {
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
LARGE_INTEGER li;
|
if (mdbx_SetFileInformationByHandle) {
|
||||||
li.QuadPart = length;
|
FILE_END_OF_FILE_INFO EndOfFileInfo;
|
||||||
return (SetFilePointerEx(fd, li, NULL, FILE_BEGIN) && SetEndOfFile(fd))
|
EndOfFileInfo.EndOfFile.QuadPart = length;
|
||||||
? MDBX_SUCCESS
|
return mdbx_SetFileInformationByHandle(fd, FileEndOfFileInfo,
|
||||||
: GetLastError();
|
&EndOfFileInfo,
|
||||||
|
sizeof(FILE_END_OF_FILE_INFO))
|
||||||
|
? MDBX_SUCCESS
|
||||||
|
: GetLastError();
|
||||||
|
} else {
|
||||||
|
LARGE_INTEGER li;
|
||||||
|
li.QuadPart = length;
|
||||||
|
return (SetFilePointerEx(fd, li, NULL, FILE_BEGIN) && SetEndOfFile(fd))
|
||||||
|
? MDBX_SUCCESS
|
||||||
|
: GetLastError();
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
STATIC_ASSERT_MSG(sizeof(off_t) >= sizeof(size_t),
|
STATIC_ASSERT_MSG(sizeof(off_t) >= sizeof(size_t),
|
||||||
"libmdbx requires 64-bit file I/O on 64-bit systems");
|
"libmdbx requires 64-bit file I/O on 64-bit systems");
|
||||||
|
@ -627,6 +627,12 @@ typedef DWORD(WINAPI *MDBX_GetFinalPathNameByHandleW)(_In_ HANDLE hFile,
|
|||||||
_In_ DWORD dwFlags);
|
_In_ DWORD dwFlags);
|
||||||
extern MDBX_GetFinalPathNameByHandleW mdbx_GetFinalPathNameByHandleW;
|
extern MDBX_GetFinalPathNameByHandleW mdbx_GetFinalPathNameByHandleW;
|
||||||
|
|
||||||
|
typedef BOOL(WINAPI *MDBX_SetFileInformationByHandle)(
|
||||||
|
_In_ HANDLE hFile, _In_ FILE_INFO_BY_HANDLE_CLASS FileInformationClass,
|
||||||
|
_Out_ LPVOID lpFileInformation, _In_ DWORD dwBufferSize);
|
||||||
|
|
||||||
|
extern MDBX_SetFileInformationByHandle mdbx_SetFileInformationByHandle;
|
||||||
|
|
||||||
typedef NTSTATUS(NTAPI *MDBX_NtFsControlFile)(
|
typedef NTSTATUS(NTAPI *MDBX_NtFsControlFile)(
|
||||||
IN HANDLE FileHandle, IN OUT HANDLE Event,
|
IN HANDLE FileHandle, IN OUT HANDLE Event,
|
||||||
IN OUT PVOID /* PIO_APC_ROUTINE */ ApcRoutine, IN OUT PVOID ApcContext,
|
IN OUT PVOID /* PIO_APC_ROUTINE */ ApcRoutine, IN OUT PVOID ApcContext,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user