ReactOS  0.4.14-dev-342-gdc047f9
IoVolume.c
Go to the documentation of this file.
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 static
13  _Inout_ PUNICODE_STRING VolumeDeviceName,
14  _Inout_ PULONG VolumeNumber,
15  _In_ NTSTATUS PreviousStatus)
16 {
18 
19 #ifndef __REACTOS__
20  *VolumeNumber++;
21  Status = RtlStringCbPrintfW(VolumeDeviceName->Buffer,
22  VolumeDeviceName->MaximumLength,
23  L"\\Device\\HarddiskVolume%lu",
24  *VolumeNumber);
25 #else
26  /* ROS's storage stack is old an broken, we don't have HarddiskVolumeN */
27  ULONG DiskNumber, PartitionNumber;
28  DiskNumber = *VolumeNumber >> 16;
29  PartitionNumber = *VolumeNumber & 0xffff;
30  if (!NT_SUCCESS(PreviousStatus))
31  {
32  if (PartitionNumber == 1)
33  {
34  /* Looks like this disk doesn't exist (or has no partitions),
35  * so we're done */
37  }
38  DiskNumber++;
39  PartitionNumber = 0;
40  }
42  Status = RtlStringCbPrintfW(VolumeDeviceName->Buffer,
43  VolumeDeviceName->MaximumLength,
44  L"\\Device\\Harddisk%lu\\Partition%lu",
45  DiskNumber,
47  *VolumeNumber = DiskNumber << 16 | PartitionNumber;
48 #endif
49  return Status;
50 }
51 
52 static
53 void
55 {
57  ULONG VolumeNumber;
58  WCHAR VolumeDeviceNameBuffer[32];
59  UNICODE_STRING VolumeDeviceName;
63  UNICODE_STRING DosVolumePrefix = RTL_CONSTANT_STRING(L"\\\\?\\Volume");
64 
65  RtlInitEmptyUnicodeString(&VolumeDeviceName,
66  VolumeDeviceNameBuffer,
67  sizeof(VolumeDeviceNameBuffer));
68  VolumeNumber = 0;
70  while (1)
71  {
72  Status = GetNextVolumeDevice(&VolumeDeviceName,
73  &VolumeNumber,
74  Status);
75  if (!NT_SUCCESS(Status))
76  {
77  trace("GetNextVolumeDevice(0x%lx) failed with %lx\n",
78  VolumeNumber, Status);
79  break;
80  }
81 
82  RtlInitUnicodeString(&VolumeDeviceName, VolumeDeviceNameBuffer);
83  Status = IoGetDeviceObjectPointer(&VolumeDeviceName,
85  &FileObject,
86  &DeviceObject);
87  if (!NT_SUCCESS(Status))
88  {
89  trace("IoGetDeviceObjectPointer(%wZ) failed with %lx\n",
90  &VolumeDeviceName, Status);
91  continue;
92  }
93 
96  if (!skip(NT_SUCCESS(Status), "No DOS name\n"))
97  {
98  trace("DOS name for %wZ is %wZ\n", &VolumeDeviceName, &DosName);
99  if (DosName.Length == 2 * sizeof(WCHAR))
100  {
101  ok(DosName.Buffer[0] >= L'A' &&
102  DosName.Buffer[0] <= L'Z' &&
103  DosName.Buffer[1] == L':',
104  "Unexpected drive letter: %wZ\n", &DosName);
105  }
106  else
107  {
108  ok(RtlPrefixUnicodeString(&DosVolumePrefix, &DosName, FALSE),
109  "Unexpected volume path: %wZ\n", &DosName);
110  }
112  }
115  }
116  ok(VolumeNumber > 1, "No volumes found\n");
117 }
118 
119 START_TEST(IoVolume)
120 {
122 }
#define STATUS_NO_MORE_ENTRIES
Definition: ntstatus.h:193
LONG NTSTATUS
Definition: precomp.h:26
static void TestIoVolumeDeviceToDosName(void)
Definition: IoVolume.c:54
NTSTATUS NTAPI IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1435
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2056
START_TEST(IoVolume)
Definition: IoVolume.c:119
NTSTATUS NTAPI IoVolumeDeviceToDosName(IN PVOID VolumeDeviceObject, OUT PUNICODE_STRING DosName)
Definition: volume.c:1284
static NTSTATUS GetNextVolumeDevice(_Inout_ PUNICODE_STRING VolumeDeviceName, _Inout_ PULONG VolumeNumber, _In_ NTSTATUS PreviousStatus)
Definition: IoVolume.c:12
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define trace
Definition: atltest.h:70
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTRSAFEVAPI RtlStringCbPrintfW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1173
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define _Inout_
Definition: no_sal2.h:244
* PFILE_OBJECT
Definition: iotypes.h:1955
#define READ_CONTROL
Definition: nt_native.h:58
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define ok(value,...)
Definition: atltest.h:57
_Out_ PUNICODE_STRING DosName
Definition: rtlfuncs.h:1270
unsigned int * PULONG
Definition: retypes.h:1
NTSYSAPI BOOLEAN NTAPI RtlPrefixUnicodeString(IN PUNICODE_STRING String1, IN PUNICODE_STRING String2, IN BOOLEAN CaseInSensitive)
#define skip(...)
Definition: atltest.h:64
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define ok_eq_hex(value, expected)
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14