1d605b506SThomas Faber /*
2d605b506SThomas Faber * PROJECT: ReactOS kernel-mode tests
3d605b506SThomas Faber * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4d605b506SThomas Faber * PURPOSE: Kernel-Mode Test Suite Volume Device test
5d605b506SThomas Faber * COPYRIGHT: Copyright 2019 Thomas Faber (thomas.faber@reactos.org)
6d605b506SThomas Faber */
7d605b506SThomas Faber
8d605b506SThomas Faber #include <kmt_test.h>
9d605b506SThomas Faber
10d605b506SThomas Faber
11d605b506SThomas Faber static
12d605b506SThomas Faber void
TestIoVolumeDeviceToDosName(void)13d605b506SThomas Faber TestIoVolumeDeviceToDosName(void)
14d605b506SThomas Faber {
15d605b506SThomas Faber NTSTATUS Status;
16d605b506SThomas Faber ULONG VolumeNumber;
17d605b506SThomas Faber WCHAR VolumeDeviceNameBuffer[32];
18d605b506SThomas Faber UNICODE_STRING VolumeDeviceName;
19d605b506SThomas Faber PFILE_OBJECT FileObject;
20d605b506SThomas Faber PDEVICE_OBJECT DeviceObject;
21d605b506SThomas Faber UNICODE_STRING DosName;
22d605b506SThomas Faber UNICODE_STRING DosVolumePrefix = RTL_CONSTANT_STRING(L"\\\\?\\Volume");
23d605b506SThomas Faber
24d605b506SThomas Faber RtlInitEmptyUnicodeString(&VolumeDeviceName,
25d605b506SThomas Faber VolumeDeviceNameBuffer,
26d605b506SThomas Faber sizeof(VolumeDeviceNameBuffer));
27d605b506SThomas Faber VolumeNumber = 0;
28d605b506SThomas Faber while (1)
29d605b506SThomas Faber {
30*78472514SVictor Perevertkin VolumeNumber++;
31*78472514SVictor Perevertkin Status = RtlStringCbPrintfW(VolumeDeviceName.Buffer,
32*78472514SVictor Perevertkin VolumeDeviceName.MaximumLength,
33*78472514SVictor Perevertkin L"\\Device\\HarddiskVolume%lu",
34*78472514SVictor Perevertkin VolumeNumber);
35d605b506SThomas Faber if (!NT_SUCCESS(Status))
36d605b506SThomas Faber {
37*78472514SVictor Perevertkin trace("RtlStringCbPrintfW(0x%lx) failed with %lx\n",
38d605b506SThomas Faber VolumeNumber, Status);
39d605b506SThomas Faber break;
40d605b506SThomas Faber }
41d605b506SThomas Faber
42d605b506SThomas Faber RtlInitUnicodeString(&VolumeDeviceName, VolumeDeviceNameBuffer);
43d605b506SThomas Faber Status = IoGetDeviceObjectPointer(&VolumeDeviceName,
44d605b506SThomas Faber READ_CONTROL,
45d605b506SThomas Faber &FileObject,
46d605b506SThomas Faber &DeviceObject);
47d605b506SThomas Faber if (!NT_SUCCESS(Status))
48d605b506SThomas Faber {
49d605b506SThomas Faber trace("IoGetDeviceObjectPointer(%wZ) failed with %lx\n",
50d605b506SThomas Faber &VolumeDeviceName, Status);
51d605b506SThomas Faber continue;
52d605b506SThomas Faber }
53d605b506SThomas Faber
54d605b506SThomas Faber Status = IoVolumeDeviceToDosName(DeviceObject, &DosName);
55d605b506SThomas Faber ok_eq_hex(Status, STATUS_SUCCESS);
56d605b506SThomas Faber if (!skip(NT_SUCCESS(Status), "No DOS name\n"))
57d605b506SThomas Faber {
58d605b506SThomas Faber trace("DOS name for %wZ is %wZ\n", &VolumeDeviceName, &DosName);
59d605b506SThomas Faber if (DosName.Length == 2 * sizeof(WCHAR))
60d605b506SThomas Faber {
61d605b506SThomas Faber ok(DosName.Buffer[0] >= L'A' &&
62d605b506SThomas Faber DosName.Buffer[0] <= L'Z' &&
63d605b506SThomas Faber DosName.Buffer[1] == L':',
64d605b506SThomas Faber "Unexpected drive letter: %wZ\n", &DosName);
65d605b506SThomas Faber }
66d605b506SThomas Faber else
67d605b506SThomas Faber {
68d605b506SThomas Faber ok(RtlPrefixUnicodeString(&DosVolumePrefix, &DosName, FALSE),
69d605b506SThomas Faber "Unexpected volume path: %wZ\n", &DosName);
70d605b506SThomas Faber }
71d605b506SThomas Faber RtlFreeUnicodeString(&DosName);
72d605b506SThomas Faber }
73d605b506SThomas Faber ObDereferenceObject(FileObject);
74d605b506SThomas Faber }
75d605b506SThomas Faber ok(VolumeNumber > 1, "No volumes found\n");
76d605b506SThomas Faber }
77d605b506SThomas Faber
START_TEST(IoVolume)78d605b506SThomas Faber START_TEST(IoVolume)
79d605b506SThomas Faber {
80d605b506SThomas Faber TestIoVolumeDeviceToDosName();
81d605b506SThomas Faber }
82