ReactOS  0.4.15-dev-4872-g8a3db97
QueryPoints.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS api tests
3  * LICENSE: GPLv2+ - See COPYING in the top level directory
4  * PURPOSE: Test for QueryPoints IOCTL
5  * PROGRAMMER: Pierre Schweitzer
6  */
7 
8 #include "precomp.h"
9 
10 VOID
12  PMOUNTMGR_MOUNT_POINT MountPoint)
13 {
14  trace("MountPoint: %p\n", MountPoint);
15  trace("\tSymbolicOffset: %ld\n", MountPoint->SymbolicLinkNameOffset);
16  trace("\tSymbolicLinkName: %.*S\n", MountPoint->SymbolicLinkNameLength / sizeof(WCHAR), (PWSTR)((ULONG_PTR)MountPoints + MountPoint->SymbolicLinkNameOffset));
17  trace("\tDeviceOffset: %ld\n", MountPoint->DeviceNameOffset);
18  trace("\tDeviceName: %.*S\n", MountPoint->DeviceNameLength / sizeof(WCHAR), (PWSTR)((ULONG_PTR)MountPoints + MountPoint->DeviceNameOffset));
19 }
20 
21 START_TEST(QueryPoints)
22 {
23  BOOL Ret;
24  HANDLE MountMgrHandle;
25  DWORD BytesReturned, Drives, i;
26  struct {
28  WCHAR Buffer[sizeof(L"\\DosDevice\\A:")];
29  } SinglePoint;
30  MOUNTMGR_MOUNT_POINTS MountPoints;
31  PMOUNTMGR_MOUNT_POINTS AllocatedPoints;
32 
33  MountMgrHandle = CreateFileW(MOUNTMGR_DOS_DEVICE_NAME, 0,
37  if (MountMgrHandle == INVALID_HANDLE_VALUE)
38  {
39  win_skip("MountMgr unavailable: %lx\n", GetLastError());
40  return;
41  }
42 
43  ZeroMemory(&SinglePoint, sizeof(SinglePoint));
44 
45  Ret = DeviceIoControl(MountMgrHandle, IOCTL_MOUNTMGR_QUERY_POINTS,
46  &SinglePoint, sizeof(MOUNTMGR_MOUNT_POINT),
47  &MountPoints, sizeof(MOUNTMGR_MOUNT_POINTS),
49  ok(Ret == FALSE, "IOCTL unexpectedly succeed\n");
50  ok(GetLastError() == ERROR_MORE_DATA, "Unexcepted failure: %lx\n", GetLastError());
51 
52  AllocatedPoints = RtlAllocateHeap(RtlGetProcessHeap(), 0, MountPoints.Size);
53  if (AllocatedPoints == NULL)
54  {
55  win_skip("Insufficiant memory\n");
56  }
57  else
58  {
59  AllocatedPoints->NumberOfMountPoints = 0;
60 
61  Ret = DeviceIoControl(MountMgrHandle, IOCTL_MOUNTMGR_QUERY_POINTS,
62  &SinglePoint, sizeof(MOUNTMGR_MOUNT_POINT),
63  AllocatedPoints, MountPoints.Size,
65  ok(Ret == TRUE, "IOCTL unexpectedly failed %lx\n", GetLastError());
66 
67  for (i = 0; i < AllocatedPoints->NumberOfMountPoints; ++i)
68  {
69  TraceMountPoint(AllocatedPoints, &AllocatedPoints->MountPoints[i]);
70  }
71 
72  RtlFreeHeap(RtlGetProcessHeap(), 0, AllocatedPoints);
73  }
74 
75  Drives = GetLogicalDrives();
76  if (Drives == 0)
77  {
78  win_skip("Drives map unavailable: %lx\n", GetLastError());
79  goto Done;
80  }
81 
82  for (i = 0; i < 26; i++)
83  {
84  if (!(Drives & (1 << i)))
85  {
86  break;
87  }
88  }
89 
90  if (i == 26)
91  {
92  win_skip("All the drive letters are in use, skipping\n");
93  goto Done;
94  }
95 
96  SinglePoint.SymbolicLinkNameOffset = sizeof(MOUNTMGR_MOUNT_POINT);
97  SinglePoint.SymbolicLinkNameLength = sizeof(L"\\DosDevice\\A:") - sizeof(UNICODE_NULL);
98  StringCbPrintfW((PWSTR)((ULONG_PTR)&SinglePoint + sizeof(MOUNTMGR_MOUNT_POINT)),
99  sizeof(L"\\DosDevice\\A:"),
100  L"\\DosDevice\\%C:",
101  i + L'A');
102 
103  Ret = DeviceIoControl(MountMgrHandle, IOCTL_MOUNTMGR_QUERY_POINTS,
104  &SinglePoint, sizeof(SinglePoint),
105  &MountPoints, sizeof(MOUNTMGR_MOUNT_POINTS),
106  &BytesReturned, NULL);
107  ok(Ret == FALSE, "IOCTL unexpectedly succeed\n");
108  ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Unexcepted failure: %lx\n", GetLastError());
109 
110 Done:
111  CloseHandle(MountMgrHandle);
112 }
#define CloseHandle
Definition: compat.h:598
#define TRUE
Definition: types.h:120
uint16_t * PWSTR
Definition: typedefs.h:56
struct _MOUNTMGR_MOUNT_POINT MOUNTMGR_MOUNT_POINT
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
#define ZeroMemory
Definition: winbase.h:1667
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:136
_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:1039
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IOCTL_MOUNTMGR_QUERY_POINTS
Definition: mountmgr.h:30
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
unsigned int BOOL
Definition: ntddk_ex.h:94
STRSAFEAPI StringCbPrintfW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:557
#define MOUNTMGR_DOS_DEVICE_NAME
Definition: mountmgr.h:11
Definition: bufpool.h:45
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define OPEN_EXISTING
Definition: compat.h:634
USHORT DeviceNameLength
Definition: imports.h:171
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define trace
Definition: atltest.h:70
__wchar_t WCHAR
Definition: xmlstorage.h:180
VOID TraceMountPoint(PMOUNTMGR_MOUNT_POINTS MountPoints, PMOUNTMGR_MOUNT_POINT MountPoint)
Definition: QueryPoints.c:11
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define ERROR_MORE_DATA
Definition: dderror.h:13
DWORD WINAPI GetLogicalDrives(VOID)
Definition: disk.c:110
MOUNTMGR_MOUNT_POINT MountPoints[1]
Definition: imports.h:177
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
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 ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
#define CreateFileW
Definition: compat.h:600
ULONG SymbolicLinkNameOffset
Definition: imports.h:166
USHORT SymbolicLinkNameLength
Definition: imports.h:167
#define win_skip
Definition: test.h:160
START_TEST(QueryPoints)
Definition: QueryPoints.c:21