Commit a5f6b4f9 authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

Fix the code to determine sector size on Windows volume.

DeviceIoControl(IOCTL_STORAGE_QUERY_PROPERTY) needs volume handle,
not the handle to ordinary file.
parent def25806
...@@ -828,27 +828,62 @@ os_file_get_block_size( ...@@ -828,27 +828,62 @@ os_file_get_block_size(
} }
#endif /* UNIV_LINUX */ #endif /* UNIV_LINUX */
#ifdef _WIN32 #ifdef _WIN32
DWORD outsize;
STORAGE_PROPERTY_QUERY storageQuery; fblock_size = 0;
memset(&storageQuery, 0, sizeof(storageQuery));
storageQuery.PropertyId = StorageAccessAlignmentProperty; // Open volume for this file, find out it "physical bytes per sector"
storageQuery.QueryType = PropertyStandardQuery;
STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR diskAlignment; HANDLE volume_handle = INVALID_HANDLE_VALUE;
char volume[MAX_PATH + 4]="\\\\.\\"; // Special prefix required for volume names.
BOOL result = os_win32_device_io_control(file, if (!GetVolumePathName(name , volume + 4, MAX_PATH)) {
os_file_handle_error_no_exit(name,
"GetVolumePathName()", FALSE);
goto end;
}
size_t len = strlen(volume);
if (volume[len - 1] == '\\') {
// Trim trailing backslash from volume name.
volume[len - 1] = 0;
}
volume_handle = CreateFile(volume, FILE_READ_ATTRIBUTES,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
0, OPEN_EXISTING, 0, 0);
if (volume_handle == INVALID_HANDLE_VALUE) {
os_file_handle_error_no_exit(volume,
"CreateFile()", FALSE);
goto end;
}
DWORD tmp;
STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR disk_alignment;
STORAGE_PROPERTY_QUERY storage_query;
memset(&storage_query, 0, sizeof(storage_query));
storage_query.PropertyId = StorageAccessAlignmentProperty;
storage_query.QueryType = PropertyStandardQuery;
BOOL result = os_win32_device_io_control(volume_handle,
IOCTL_STORAGE_QUERY_PROPERTY, IOCTL_STORAGE_QUERY_PROPERTY,
&storageQuery, &storage_query,
sizeof(STORAGE_PROPERTY_QUERY), sizeof(storage_query),
&diskAlignment, &disk_alignment,
sizeof(STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR), sizeof(disk_alignment),
&outsize); &tmp);
CloseHandle(volume_handle);
if (!result) { if (!result) {
os_file_handle_error_no_exit(name, "DeviceIoControl()", FALSE); os_file_handle_error_no_exit(volume,
fblock_size = 0; "DeviceIoControl(IOCTL_STORAGE_QUERY_PROPERTY)", FALSE);
goto end;
} }
fblock_size = diskAlignment.BytesPerPhysicalSector; fblock_size = disk_alignment.BytesPerPhysicalSector;
end:
#endif /* _WIN32 */ #endif /* _WIN32 */
/* Currently we support file block size up to 4Kb */ /* Currently we support file block size up to 4Kb */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment