diff options
author | George Hazan <ghazan@miranda.im> | 2018-01-15 18:05:23 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-01-15 18:05:23 +0300 |
commit | 5b0699740c8998327a2681f79347e1d630bbaab6 (patch) | |
tree | bbf96260e53fc238773a0eb3673a6f327d8f7b37 /plugins/Dbx_mdbx | |
parent | 43ed4bffa381bbe6db5b22a3cbd1f39045b315b6 (diff) |
more XP compatibility
Diffstat (limited to 'plugins/Dbx_mdbx')
-rw-r--r-- | plugins/Dbx_mdbx/src/libmdbx/src/osal.c | 80 |
1 files changed, 42 insertions, 38 deletions
diff --git a/plugins/Dbx_mdbx/src/libmdbx/src/osal.c b/plugins/Dbx_mdbx/src/libmdbx/src/osal.c index 344a76c9bb..fa6fe279da 100644 --- a/plugins/Dbx_mdbx/src/libmdbx/src/osal.c +++ b/plugins/Dbx_mdbx/src/libmdbx/src/osal.c @@ -813,49 +813,53 @@ int mdbx_mmap(int flags, mdbx_mmap_t *map, size_t size, size_t limit) { #endif WCHAR PathBuffer[INT16_MAX]; - DWORD VolumeSerialNumber, FileSystemFlags; - if (!GetVolumeInformationByHandleW(map->fd, PathBuffer, INT16_MAX, - &VolumeSerialNumber, NULL, - &FileSystemFlags, NULL, 0)) - return GetLastError(); - - if ((flags & MDBX_RDONLY) == 0) { - if (FileSystemFlags & (FILE_SEQUENTIAL_WRITE_ONCE | FILE_READ_ONLY_VOLUME | - FILE_VOLUME_IS_COMPRESSED)) - return ERROR_FILE_OFFLINE; + typedef BOOL (WINAPI *pfnGetVolumeInformationByHandle)(HANDLE, LPWSTR, DWORD, LPDWORD, LPDWORD, LPDWORD, LPWSTR, DWORD); + pfnGetVolumeInformationByHandle pvol = (pfnGetVolumeInformationByHandle)GetProcAddress(GetModuleHandleA("kernel32.dll"), "GetVolumeInformationByHandleW"); + if (pvol) { + DWORD VolumeSerialNumber, FileSystemFlags; + if (!pvol(map->fd, PathBuffer, INT16_MAX, &VolumeSerialNumber, NULL, &FileSystemFlags, NULL, 0)) + return GetLastError(); + + if ((flags & MDBX_RDONLY) == 0) { + if (FileSystemFlags & (FILE_SEQUENTIAL_WRITE_ONCE | FILE_READ_ONLY_VOLUME | + FILE_VOLUME_IS_COMPRESSED)) + return ERROR_FILE_OFFLINE; + } } - if (!GetFinalPathNameByHandleW(map->fd, PathBuffer, INT16_MAX, - FILE_NAME_NORMALIZED | VOLUME_NAME_NT)) - return GetLastError(); + typedef DWORD (WINAPI *pfnGetFinalPathNameByHandle)(HANDLE, LPWSTR, DWORD, DWORD); + pfnGetFinalPathNameByHandle pfname = (pfnGetFinalPathNameByHandle)GetProcAddress(GetModuleHandleA("kernel32.dll"), "GetFinalPathNameByHandleW"); + if (pfname) { + if (!pfname(map->fd, PathBuffer, INT16_MAX, FILE_NAME_NORMALIZED | VOLUME_NAME_NT)) + return GetLastError(); - if (_wcsnicmp(PathBuffer, L"\\Device\\Mup\\", 12) == 0) - return ERROR_FILE_OFFLINE; + if (_wcsnicmp(PathBuffer, L"\\Device\\Mup\\", 12) == 0) + return ERROR_FILE_OFFLINE; - if (GetFinalPathNameByHandleW(map->fd, PathBuffer, INT16_MAX, - FILE_NAME_NORMALIZED | VOLUME_NAME_DOS)) { - UINT DriveType = GetDriveTypeW(PathBuffer); - if (DriveType == DRIVE_NO_ROOT_DIR && - wcsncmp(PathBuffer, L"\\\\?\\", 4) == 0 && - wcsncmp(PathBuffer + 5, L":\\", 2) == 0) { - PathBuffer[7] = 0; - DriveType = GetDriveTypeW(PathBuffer + 4); - } - switch (DriveType) { - case DRIVE_CDROM: - if (flags & MDBX_RDONLY) + if (pfname(map->fd, PathBuffer, INT16_MAX, FILE_NAME_NORMALIZED | VOLUME_NAME_DOS)) { + UINT DriveType = GetDriveTypeW(PathBuffer); + if (DriveType == DRIVE_NO_ROOT_DIR && + wcsncmp(PathBuffer, L"\\\\?\\", 4) == 0 && + wcsncmp(PathBuffer + 5, L":\\", 2) == 0) { + PathBuffer[7] = 0; + DriveType = GetDriveTypeW(PathBuffer + 4); + } + switch (DriveType) { + case DRIVE_CDROM: + if (flags & MDBX_RDONLY) + break; + // fall through + case DRIVE_UNKNOWN: + case DRIVE_NO_ROOT_DIR: + case DRIVE_REMOTE: + default: + return ERROR_FILE_OFFLINE; + case DRIVE_REMOVABLE: + case DRIVE_FIXED: + case DRIVE_RAMDISK: break; - // fall through - case DRIVE_UNKNOWN: - case DRIVE_NO_ROOT_DIR: - case DRIVE_REMOTE: - default: - return ERROR_FILE_OFFLINE; - case DRIVE_REMOVABLE: - case DRIVE_FIXED: - case DRIVE_RAMDISK: - break; - } + } + } } rc = mdbx_filesize(map->fd, &map->filesize); |