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