2017-03-02 19:33:25 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS api tests
|
|
|
|
* LICENSE: GPLv2+ - See COPYING in the top level directory
|
|
|
|
* PURPOSE: Test for DeviceIoControl
|
|
|
|
* PROGRAMMER: Pierre Schweitzer <pierre@reactos.org>
|
|
|
|
*/
|
|
|
|
|
2017-12-13 12:48:26 +00:00
|
|
|
#include "precomp.h"
|
|
|
|
|
2017-03-02 19:33:25 +00:00
|
|
|
#include <winioctl.h>
|
2017-10-07 10:09:27 +00:00
|
|
|
#include <mountdev.h>
|
2017-03-02 19:33:25 +00:00
|
|
|
|
2017-04-30 11:43:04 +00:00
|
|
|
WCHAR Letter;
|
|
|
|
HANDLE Device;
|
2017-10-07 12:06:34 +00:00
|
|
|
UINT DriveType;
|
|
|
|
|
|
|
|
#define ok_type(condition, format, ...) ok(condition, "(%d): " format, DriveType, ##__VA_ARGS__)
|
|
|
|
#define skip_type(format, ...) skip("(%d): " format, DriveType, ##__VA_ARGS__)
|
2017-04-30 11:43:04 +00:00
|
|
|
|
|
|
|
static
|
2017-10-07 12:06:34 +00:00
|
|
|
BOOL
|
2017-04-30 11:43:04 +00:00
|
|
|
GetDiskGeometry(VOID)
|
2017-03-02 19:33:25 +00:00
|
|
|
{
|
|
|
|
UINT Ret;
|
|
|
|
DISK_GEOMETRY DG;
|
|
|
|
DWORD Size, Error;
|
|
|
|
DISK_GEOMETRY_EX DGE;
|
|
|
|
|
|
|
|
Size = 0;
|
|
|
|
Ret = DeviceIoControl(Device, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &DG, sizeof(DG) - 1, &Size, NULL);
|
2017-10-07 12:06:34 +00:00
|
|
|
ok_type(Ret == 0, "DeviceIoControl succeed\n");
|
2017-03-02 19:33:25 +00:00
|
|
|
Error = GetLastError();
|
2017-10-07 12:06:34 +00:00
|
|
|
ok_type(Error == ERROR_INSUFFICIENT_BUFFER, "Expecting ERROR_INSUFFICIENT_BUFFER, got %ld\n", Error);
|
|
|
|
ok_type(Size == 0, "Invalid output size: %ld\n", Size);
|
2017-03-02 19:33:25 +00:00
|
|
|
|
|
|
|
Size = 0;
|
|
|
|
Ret = DeviceIoControl(Device, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &DG, sizeof(DG), &Size, NULL);
|
2017-10-07 12:06:34 +00:00
|
|
|
/* Specific for CDROM, no disk present */
|
|
|
|
if (Ret == 0 && GetLastError() == ERROR_NOT_READY)
|
|
|
|
{
|
|
|
|
skip_type("No CDROM present\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
ok_type(Ret != 0, "DeviceIoControl failed: %ld\n", GetLastError());
|
|
|
|
ok_type(Size == sizeof(DG), "Invalid output size: %ld\n", Size);
|
2017-03-02 19:33:25 +00:00
|
|
|
|
|
|
|
Size = 0;
|
|
|
|
Ret = DeviceIoControl(Device, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &DGE, FIELD_OFFSET(DISK_GEOMETRY_EX, Data) - 1, &Size, NULL);
|
2017-10-07 12:06:34 +00:00
|
|
|
ok_type(Ret == 0, "DeviceIoControl succeed\n");
|
2017-03-02 19:33:25 +00:00
|
|
|
Error = GetLastError();
|
2017-10-07 12:06:34 +00:00
|
|
|
ok_type(Error == ERROR_INSUFFICIENT_BUFFER, "Expecting ERROR_INSUFFICIENT_BUFFER, got %ld\n", Error);
|
|
|
|
ok_type(Size == 0, "Invalid output size: %ld\n", Size);
|
2017-03-02 19:33:25 +00:00
|
|
|
|
|
|
|
Size = 0;
|
|
|
|
Ret = DeviceIoControl(Device, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &DGE, FIELD_OFFSET(DISK_GEOMETRY_EX, Data), &Size, NULL);
|
2017-10-07 12:06:34 +00:00
|
|
|
ok_type(Ret != 0, "DeviceIoControl failed: %ld\n", GetLastError());
|
|
|
|
ok_type(Size == FIELD_OFFSET(DISK_GEOMETRY_EX, Data), "Invalid output size: %ld\n", Size);
|
2017-03-02 19:33:25 +00:00
|
|
|
|
|
|
|
Size = 0;
|
|
|
|
Ret = DeviceIoControl(Device, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &DGE, sizeof(DGE), &Size, NULL);
|
2017-10-07 12:06:34 +00:00
|
|
|
ok_type(Ret != 0, "DeviceIoControl failed: %ld\n", GetLastError());
|
|
|
|
if (DriveType == DRIVE_FIXED)
|
|
|
|
{
|
|
|
|
ok_type(Size == sizeof(DGE), "Invalid output size: %ld\n", Size);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok_type(Size == FIELD_OFFSET(DISK_GEOMETRY_EX, Data), "Invalid output size: %ld\n", Size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2017-04-30 11:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
VOID
|
|
|
|
QueryDeviceName(VOID)
|
|
|
|
{
|
|
|
|
UINT Ret;
|
|
|
|
BOOL IsValid;
|
|
|
|
DWORD Size, Error;
|
|
|
|
MOUNTDEV_NAME MDN, *AllocatedMDN;
|
|
|
|
|
2017-10-07 10:11:17 +00:00
|
|
|
Size = 0;
|
2017-04-30 11:43:04 +00:00
|
|
|
Ret = DeviceIoControl(Device, IOCTL_MOUNTDEV_QUERY_DEVICE_NAME, NULL, 0, &MDN, sizeof(MDN) - 1, &Size, NULL);
|
2017-10-07 12:06:34 +00:00
|
|
|
ok_type(Ret == 0, "DeviceIoControl succeed\n");
|
2017-04-30 11:43:04 +00:00
|
|
|
Error = GetLastError();
|
2017-10-07 12:06:34 +00:00
|
|
|
if (DriveType == DRIVE_FIXED)
|
|
|
|
{
|
|
|
|
ok_type(Error == ERROR_INVALID_PARAMETER, "Expecting ERROR_INVALID_PARAMETER, got %ld\n", Error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok_type(Error == ERROR_INSUFFICIENT_BUFFER, "Expecting ERROR_INSUFFICIENT_BUFFER, got %ld\n", Error);
|
|
|
|
}
|
|
|
|
ok_type(Size == 0, "Invalid output size: %ld\n", Size);
|
2017-04-30 11:43:04 +00:00
|
|
|
|
|
|
|
Ret = DeviceIoControl(Device, IOCTL_MOUNTDEV_QUERY_DEVICE_NAME, NULL, 0, &MDN, sizeof(MDN), &Size, NULL);
|
2017-10-07 12:06:34 +00:00
|
|
|
ok_type(Ret == 0, "DeviceIoControl succeed\n");
|
2017-04-30 11:43:04 +00:00
|
|
|
Error = GetLastError();
|
2017-10-07 12:06:34 +00:00
|
|
|
ok_type(Error == ERROR_MORE_DATA, "Expecting ERROR_MORE_DATA, got %ld\n", Error);
|
|
|
|
ok_type(Size == sizeof(MOUNTDEV_NAME), "Invalid output size: %ld\n", Size);
|
2017-04-30 11:43:04 +00:00
|
|
|
|
|
|
|
AllocatedMDN = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(MOUNTDEV_NAME, Name) + MDN.NameLength + sizeof(UNICODE_NULL));
|
|
|
|
if (AllocatedMDN == NULL)
|
|
|
|
{
|
2017-10-07 12:06:34 +00:00
|
|
|
skip_type("Memory allocation failure\n");
|
2017-04-30 11:43:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Size = 0;
|
|
|
|
Ret = DeviceIoControl(Device, IOCTL_MOUNTDEV_QUERY_DEVICE_NAME, NULL, 0, AllocatedMDN, FIELD_OFFSET(MOUNTDEV_NAME, Name) + MDN.NameLength, &Size, NULL);
|
2017-10-07 12:06:34 +00:00
|
|
|
ok_type(Ret != 0, "DeviceIoControl failed: %ld\n", GetLastError());
|
|
|
|
ok_type(Size == FIELD_OFFSET(MOUNTDEV_NAME, Name) + MDN.NameLength, "Invalid output size: %ld\n", Size);
|
|
|
|
ok_type(AllocatedMDN->NameLength == MDN.NameLength, "Mismatching sizes: %d %d\n", AllocatedMDN->NameLength, MDN.NameLength);
|
2017-04-30 11:43:04 +00:00
|
|
|
|
|
|
|
if (Ret != 0)
|
|
|
|
{
|
|
|
|
IsValid = FALSE;
|
|
|
|
AllocatedMDN->Name[AllocatedMDN->NameLength / sizeof(WCHAR) - 1] = UNICODE_NULL;
|
|
|
|
|
2017-10-07 12:06:34 +00:00
|
|
|
if ((DriveType == DRIVE_FIXED && wcsstr(AllocatedMDN->Name, L"\\Device\\HarddiskVolume") != NULL) ||
|
|
|
|
(DriveType == DRIVE_CDROM && wcsstr(AllocatedMDN->Name, L"\\Device\\CdRom") != NULL))
|
2017-04-30 11:43:04 +00:00
|
|
|
{
|
|
|
|
IsValid = TRUE;
|
|
|
|
}
|
|
|
|
else if (wcsstr(AllocatedMDN->Name, L"\\DosDevices\\") != NULL)
|
|
|
|
{
|
|
|
|
IsValid = (AllocatedMDN->Name[12] == Letter && AllocatedMDN->Name[13] == L':');
|
|
|
|
}
|
|
|
|
|
2017-10-07 12:06:34 +00:00
|
|
|
ok_type(IsValid, "Invalid name: %.*S\n", AllocatedMDN->NameLength, AllocatedMDN->Name);
|
2017-04-30 11:43:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-07 12:06:34 +00:00
|
|
|
skip_type("Failed to query device name\n");
|
2017-04-30 11:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, AllocatedMDN);
|
|
|
|
}
|
|
|
|
|
2017-10-07 10:09:27 +00:00
|
|
|
static
|
|
|
|
VOID
|
|
|
|
QueryUniqueId(VOID)
|
|
|
|
{
|
|
|
|
UINT Ret;
|
|
|
|
DWORD Size, Error;
|
|
|
|
MOUNTDEV_UNIQUE_ID MUI, *AllocatedMUI;
|
|
|
|
|
2017-10-07 10:11:17 +00:00
|
|
|
Size = 0;
|
2017-10-07 10:09:27 +00:00
|
|
|
Ret = DeviceIoControl(Device, IOCTL_MOUNTDEV_QUERY_UNIQUE_ID, NULL, 0, &MUI, sizeof(MUI) - 1, &Size, NULL);
|
2017-10-07 12:06:34 +00:00
|
|
|
ok_type(Ret == 0, "DeviceIoControl succeed\n");
|
2017-10-07 10:09:27 +00:00
|
|
|
Error = GetLastError();
|
2017-10-07 12:06:34 +00:00
|
|
|
if (DriveType == DRIVE_FIXED)
|
|
|
|
{
|
|
|
|
ok_type(Error == ERROR_INVALID_PARAMETER, "Expecting ERROR_INVALID_PARAMETER, got %ld\n", Error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok_type(Error == ERROR_INSUFFICIENT_BUFFER, "Expecting ERROR_INSUFFICIENT_BUFFER, got %ld\n", Error);
|
|
|
|
}
|
|
|
|
ok_type(Size == 0, "Invalid output size: %ld\n", Size);
|
2017-10-07 10:09:27 +00:00
|
|
|
|
|
|
|
Ret = DeviceIoControl(Device, IOCTL_MOUNTDEV_QUERY_UNIQUE_ID, NULL, 0, &MUI, sizeof(MUI), &Size, NULL);
|
2017-10-07 12:06:34 +00:00
|
|
|
ok_type(Ret == 0, "DeviceIoControl succeed\n");
|
2017-10-07 10:09:27 +00:00
|
|
|
Error = GetLastError();
|
2017-10-07 12:06:34 +00:00
|
|
|
ok_type(Error == ERROR_MORE_DATA, "Expecting ERROR_MORE_DATA, got %ld\n", Error);
|
|
|
|
ok_type(Size == sizeof(MOUNTDEV_UNIQUE_ID), "Invalid output size: %ld\n", Size);
|
2017-10-07 10:09:27 +00:00
|
|
|
|
|
|
|
AllocatedMUI = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(MOUNTDEV_UNIQUE_ID, UniqueId) + MUI.UniqueIdLength + sizeof(UNICODE_NULL));
|
|
|
|
if (AllocatedMUI == NULL)
|
|
|
|
{
|
2017-10-07 12:06:34 +00:00
|
|
|
skip_type("Memory allocation failure\n");
|
2017-10-07 10:09:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Size = 0;
|
|
|
|
Ret = DeviceIoControl(Device, IOCTL_MOUNTDEV_QUERY_UNIQUE_ID, NULL, 0, AllocatedMUI, FIELD_OFFSET(MOUNTDEV_UNIQUE_ID, UniqueId) + MUI.UniqueIdLength, &Size, NULL);
|
2017-10-07 12:06:34 +00:00
|
|
|
ok_type(Ret != 0, "DeviceIoControl failed: %ld\n", GetLastError());
|
|
|
|
ok_type(Size == FIELD_OFFSET(MOUNTDEV_UNIQUE_ID, UniqueId) + MUI.UniqueIdLength, "Invalid output size: %ld\n", Size);
|
|
|
|
ok_type(AllocatedMUI->UniqueIdLength == MUI.UniqueIdLength, "Mismatching sizes: %d %d\n", AllocatedMUI->UniqueIdLength, MUI.UniqueIdLength);
|
2017-10-07 10:09:27 +00:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, AllocatedMUI);
|
|
|
|
}
|
|
|
|
|
2017-10-08 08:12:08 +00:00
|
|
|
static
|
|
|
|
VOID
|
|
|
|
QuerySuggestedLinkName(VOID)
|
|
|
|
{
|
|
|
|
UINT Ret;
|
|
|
|
DWORD Size, Error;
|
|
|
|
MOUNTDEV_SUGGESTED_LINK_NAME MSLN;
|
|
|
|
|
|
|
|
Size = 0;
|
|
|
|
Ret = DeviceIoControl(Device, IOCTL_MOUNTDEV_QUERY_SUGGESTED_LINK_NAME, NULL, 0, &MSLN, sizeof(MSLN) - 1, &Size, NULL);
|
|
|
|
ok_type(Ret == 0, "DeviceIoControl succeed\n");
|
|
|
|
Error = GetLastError();
|
|
|
|
if (DriveType == DRIVE_FIXED)
|
|
|
|
{
|
|
|
|
ok_type(Error == ERROR_INVALID_PARAMETER, "Expecting ERROR_INVALID_PARAMETER, got %ld\n", Error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok_type(Error == ERROR_INSUFFICIENT_BUFFER, "Expecting ERROR_INSUFFICIENT_BUFFER, got %ld\n", Error);
|
|
|
|
}
|
|
|
|
ok_type(Size == 0, "Invalid output size: %ld\n", Size);
|
|
|
|
|
|
|
|
Ret = DeviceIoControl(Device, IOCTL_MOUNTDEV_QUERY_SUGGESTED_LINK_NAME, NULL, 0, &MSLN, sizeof(MSLN), &Size, NULL);
|
|
|
|
ok_type(Ret == 0, "DeviceIoControl succeed\n");
|
|
|
|
Error = GetLastError();
|
|
|
|
if (DriveType == DRIVE_FIXED)
|
|
|
|
{
|
|
|
|
ok_type(Error == ERROR_NOT_FOUND, "Expecting ERROR_NOT_FOUND, got %ld\n", Error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok_type(Error == ERROR_FILE_NOT_FOUND, "Expecting ERROR_FILE_NOT_FOUND, got %ld\n", Error);
|
|
|
|
}
|
|
|
|
ok_type(Size == 0, "Invalid output size: %ld\n", Size);
|
|
|
|
}
|
|
|
|
|
2017-04-30 11:43:04 +00:00
|
|
|
START_TEST(DeviceIoControl)
|
|
|
|
{
|
|
|
|
UINT Ret;
|
|
|
|
WCHAR Path[MAX_PATH];
|
2017-10-07 12:06:34 +00:00
|
|
|
DWORD DriveMap, Current;
|
|
|
|
BOOL DiskDone, CdRomDone;
|
2017-04-30 11:43:04 +00:00
|
|
|
|
2017-10-07 12:06:34 +00:00
|
|
|
DiskDone = FALSE;
|
|
|
|
CdRomDone = FALSE;
|
|
|
|
DriveMap = GetLogicalDrives();
|
|
|
|
for (Current = 0; Current < 26; ++Current)
|
2017-04-30 11:43:04 +00:00
|
|
|
{
|
2017-10-07 12:06:34 +00:00
|
|
|
if (DriveMap & (1 << Current))
|
|
|
|
{
|
|
|
|
Ret = StringCchPrintfW(Path, MAX_PATH, L"%c:\\", Current + L'A');
|
|
|
|
ok(Ret == S_OK, "StringCchPrintfW failed: %d\n", Ret);
|
|
|
|
|
|
|
|
DriveType = GetDriveTypeW(Path);
|
|
|
|
if ((DriveType == DRIVE_FIXED && !DiskDone) ||
|
|
|
|
(DriveType == DRIVE_CDROM && !CdRomDone))
|
|
|
|
{
|
|
|
|
Ret = StringCchPrintfW(Path, MAX_PATH, L"\\\\?\\%c:", Current + L'A');
|
|
|
|
ok(Ret == S_OK, "StringCchPrintfW failed: %d\n", Ret);
|
|
|
|
|
|
|
|
Device = CreateFileW(Path, 0, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if (Device == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
skip_type("CreateFileW for %S failed: %ld\n", Path, GetLastError());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
DiskDone = (DiskDone || (DriveType == DRIVE_FIXED));
|
|
|
|
CdRomDone = (CdRomDone || (DriveType == DRIVE_CDROM));
|
|
|
|
|
|
|
|
if (GetDiskGeometry())
|
|
|
|
{
|
|
|
|
QueryDeviceName();
|
|
|
|
QueryUniqueId();
|
2017-10-08 08:12:08 +00:00
|
|
|
QuerySuggestedLinkName();
|
2017-10-07 12:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(Device);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CdRomDone && DiskDone)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-04-30 11:43:04 +00:00
|
|
|
}
|
|
|
|
|
2017-10-07 12:06:34 +00:00
|
|
|
if (!DiskDone)
|
|
|
|
{
|
|
|
|
skip("No disk drive found\n");
|
|
|
|
}
|
2017-03-02 19:33:25 +00:00
|
|
|
|
2017-10-07 12:06:34 +00:00
|
|
|
if (!CdRomDone)
|
|
|
|
{
|
|
|
|
skip("No CDROM drive found\n");
|
|
|
|
}
|
2017-03-02 19:33:25 +00:00
|
|
|
}
|