ReactOS 0.4.16-dev-927-g467dec4
QueryPoints.c File Reference
#include "precomp.h"
Include dependency graph for QueryPoints.c:

Go to the source code of this file.

Functions

VOID TraceMountPoint (_In_ const MOUNTMGR_MOUNT_POINTS *MountPoints, _In_ const MOUNTMGR_MOUNT_POINT *MountPoint)
 
 START_TEST (QueryPoints)
 

Function Documentation

◆ START_TEST()

START_TEST ( QueryPoints  )

Definition at line 26 of file QueryPoints.c.

27{
28 BOOL Ret;
29 HANDLE MountMgrHandle;
30 DWORD LastError, BytesReturned, Drives, i;
31 struct
32 {
34 WCHAR Buffer[sizeof("\\DosDevice\\A:")];
35 } SinglePoint;
36 MOUNTMGR_MOUNT_POINTS MountPoints;
37 PMOUNTMGR_MOUNT_POINTS AllocatedPoints;
38
40 if (!MountMgrHandle)
41 {
42 win_skip("MountMgr unavailable: %lu\n", GetLastError());
43 return;
44 }
45
46 ZeroMemory(&SinglePoint, sizeof(SinglePoint));
47
48 /* Retrieve the size needed to enumerate all the existing mount points */
49 Ret = DeviceIoControl(MountMgrHandle, IOCTL_MOUNTMGR_QUERY_POINTS,
50 &SinglePoint, sizeof(MOUNTMGR_MOUNT_POINT), // Size without the string.
51 &MountPoints, sizeof(MountPoints),
53 LastError = GetLastError();
54 ok(Ret == FALSE, "IOCTL unexpectedly succeeded\n");
55 ok(LastError == ERROR_MORE_DATA, "Unexpected failure: %lu\n", LastError);
56
57 /* Allocate a suitably-sized buffer for the mount points */
58 AllocatedPoints = RtlAllocateHeap(RtlGetProcessHeap(), 0, MountPoints.Size);
59 if (AllocatedPoints == NULL)
60 {
61 skip("Insufficient memory\n");
62 }
63 else
64 {
65 AllocatedPoints->NumberOfMountPoints = 0;
66
67 /* Retrieve the list of all the existing mount points */
68 Ret = DeviceIoControl(MountMgrHandle, IOCTL_MOUNTMGR_QUERY_POINTS,
69 &SinglePoint, sizeof(MOUNTMGR_MOUNT_POINT), // Size without the string.
70 AllocatedPoints, MountPoints.Size,
72 ok(Ret == TRUE, "IOCTL unexpectedly failed: %lu\n", GetLastError());
73
74 for (i = 0; i < AllocatedPoints->NumberOfMountPoints; ++i)
75 {
76 TraceMountPoint(AllocatedPoints, &AllocatedPoints->MountPoints[i]);
77 }
78
79 RtlFreeHeap(RtlGetProcessHeap(), 0, AllocatedPoints);
80 }
81
82 /* Now, find the first unused drive letter */
83 Drives = GetLogicalDrives();
84 if (Drives == 0)
85 {
86 skip("Drives map unavailable: %lu\n", GetLastError());
87 goto Done;
88 }
89 for (i = 0; i <= 'Z'-'A'; ++i)
90 {
91 if (!(Drives & (1 << i)))
92 break;
93 }
94 if (i > 'Z'-'A')
95 {
96 skip("All the drive letters are in use, skipping\n");
97 goto Done;
98 }
99
100 /* Check that this drive letter is not an existing mount point */
101 SinglePoint.SymbolicLinkNameOffset = ((ULONG_PTR)&SinglePoint.Buffer - (ULONG_PTR)&SinglePoint);
102 SinglePoint.SymbolicLinkNameLength = sizeof(SinglePoint.Buffer) - sizeof(UNICODE_NULL);
103 StringCbPrintfW(SinglePoint.Buffer, sizeof(SinglePoint.Buffer),
104 L"\\DosDevice\\%C:", L'A' + i);
105
106 Ret = DeviceIoControl(MountMgrHandle, IOCTL_MOUNTMGR_QUERY_POINTS,
107 &SinglePoint, sizeof(SinglePoint),
108 &MountPoints, sizeof(MountPoints),
110 LastError = GetLastError();
111 ok(Ret == FALSE, "IOCTL unexpectedly succeeded\n");
112 ok(LastError == ERROR_FILE_NOT_FOUND, "Unexpected failure: %lu\n", LastError);
113
114Done:
115 CloseHandle(MountMgrHandle);
116}
VOID TraceMountPoint(_In_ const MOUNTMGR_MOUNT_POINTS *MountPoints, _In_ const MOUNTMGR_MOUNT_POINT *MountPoint)
Definition: QueryPoints.c:11
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:616
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:634
Definition: bufpool.h:45
#define ERROR_MORE_DATA
Definition: dderror.h:13
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define ULONG_PTR
Definition: config.h:101
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
struct _MOUNTMGR_MOUNT_POINT MOUNTMGR_MOUNT_POINT
HANDLE GetMountMgrHandle(_In_ ACCESS_MASK DesiredAccess)
Retrieves a handle to the MountMgr controlling device. The handle should be closed with NtClose() onc...
Definition: utils.c:22
#define IOCTL_MOUNTMGR_QUERY_POINTS
Definition: mountmgr.h:49
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define UNICODE_NULL
#define L(x)
Definition: ntvdm.h:50
#define win_skip
Definition: test.h:164
STRSAFEAPI StringCbPrintfW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:557
MOUNTMGR_MOUNT_POINT MountPoints[1]
Definition: imports.h:175
uint32_t ULONG_PTR
Definition: typedefs.h:65
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_ ULONG _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesReturned
Definition: wdfiotarget.h:1052
#define ZeroMemory
Definition: winbase.h:1743
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
DWORD WINAPI GetLogicalDrives(void)
Definition: disk.c:110
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ TraceMountPoint()

VOID TraceMountPoint ( _In_ const MOUNTMGR_MOUNT_POINTS MountPoints,
_In_ const MOUNTMGR_MOUNT_POINT MountPoint 
)

Definition at line 11 of file QueryPoints.c.

14{
15 trace("MountPoint: %p\n", MountPoint);
16 trace("\tSymbolicOffset: %ld\n", MountPoint->SymbolicLinkNameOffset);
17 trace("\tSymbolicLinkName: %.*S\n",
18 MountPoint->SymbolicLinkNameLength / sizeof(WCHAR),
19 (PWCHAR)((ULONG_PTR)MountPoints + MountPoint->SymbolicLinkNameOffset));
20 trace("\tDeviceOffset: %ld\n", MountPoint->DeviceNameOffset);
21 trace("\tDeviceName: %.*S\n",
22 MountPoint->DeviceNameLength / sizeof(WCHAR),
23 (PWCHAR)((ULONG_PTR)MountPoints + MountPoint->DeviceNameOffset));
24}
#define trace
Definition: atltest.h:70
uint16_t * PWCHAR
Definition: typedefs.h:56

Referenced by START_TEST().