ReactOS 0.4.16-dev-2279-gc890759
mountmgr.c File Reference
#include "diskpart.h"
#include <mountmgr.h>
#include <debug.h>
Include dependency graph for mountmgr.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static NTSTATUS OpenMountManager (_Out_ PHANDLE MountMgrHandle, _In_ ACCESS_MASK Access)
 
BOOL GetAutomountState (_Out_ PBOOL State)
 
BOOL SetAutomountState (_In_ BOOL bEnable)
 
BOOL ScrubAutomount (VOID)
 
BOOL AssignDriveLetter (_In_ PWSTR DeviceName, _In_ WCHAR DriveLetter)
 
BOOL AssignNextDriveLetter (_In_ PWSTR DeviceName, _Out_ PWCHAR DriveLetter)
 
BOOL DeleteDriveLetter (_In_ WCHAR DriveLetter)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file mountmgr.c.

Function Documentation

◆ AssignDriveLetter()

BOOL AssignDriveLetter ( _In_ PWSTR  DeviceName,
_In_ WCHAR  DriveLetter 
)

Definition at line 181 of file mountmgr.c.

184{
186 ULONG DosDeviceNameLength, DeviceNameLength;
189 HANDLE MountMgrHandle = NULL;
192 BOOL Ret = TRUE;
193
194 DPRINT1("AssignDriveLetter(%S %c)\n", DeviceName, DriveLetter);
195
196 DeviceNameLength = wcslen(DeviceName) * sizeof(WCHAR);
197
198 swprintf(DosDeviceName, L"\\DosDevices\\%c:", DriveLetter);
199 DosDeviceNameLength = wcslen(DosDeviceName) * sizeof(WCHAR);
200
201 /* Allocate the input buffer for the MountMgr */
202 InputBufferLength = DosDeviceNameLength + DeviceNameLength + sizeof(MOUNTMGR_CREATE_POINT_INPUT);
204 if (InputBuffer == NULL)
205 {
206 DPRINT1("InputBuffer allocation failed!\n");
207 return FALSE;
208 }
209
210 /* Fill the input buffer */
211 InputBuffer->SymbolicLinkNameOffset = sizeof(MOUNTMGR_CREATE_POINT_INPUT);
212 InputBuffer->SymbolicLinkNameLength = DosDeviceNameLength;
213 InputBuffer->DeviceNameOffset = DosDeviceNameLength + sizeof(MOUNTMGR_CREATE_POINT_INPUT);
214 InputBuffer->DeviceNameLength = DeviceNameLength;
217 DosDeviceNameLength);
218 RtlCopyMemory((PVOID)((ULONG_PTR)InputBuffer + InputBuffer->DeviceNameOffset),
220 DeviceNameLength);
221
223 if (!NT_SUCCESS(Status))
224 {
225 DPRINT1("OpenMountManager() failed (Status 0x%08lx)\n", Status);
226 Ret = FALSE;
227 goto done;
228 }
229
230 Status = NtDeviceIoControlFile(MountMgrHandle,
231 NULL,
232 NULL,
233 NULL,
234 &Iosb,
238 NULL,
239 0);
240 if (!NT_SUCCESS(Status))
241 {
242 DPRINT1("NtDeviceIoControlFile() failed (Status 0x%08lx)\n", Status);
243 Ret = FALSE;
244 goto done;
245 }
246
247done:
248 if (MountMgrHandle)
249 NtClose(MountMgrHandle);
250
251 RtlFreeHeap(RtlGetProcessHeap(), 0, InputBuffer);
252
253 return Ret;
254}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
static NTSTATUS OpenMountManager(_Out_ PHANDLE MountMgrHandle, _In_ ACCESS_MASK Access)
Definition: mountmgr.c:20
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
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define GENERIC_READ
Definition: compat.h:135
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2983
#define swprintf
Definition: precomp.h:40
#define L(x)
Definition: resources.c:13
return Iosb
Definition: create.c:4403
unsigned int BOOL
Definition: ntddk_ex.h:94
Status
Definition: gdiplustypes.h:25
static char DosDeviceName[DEVICE_SIZE]
Definition: lsdd.c:26
struct _MOUNTMGR_CREATE_POINT_INPUT MOUNTMGR_CREATE_POINT_INPUT
#define IOCTL_MOUNTMGR_CREATE_POINT
Definition: imports.h:116
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define GENERIC_WRITE
Definition: nt_native.h:90
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3281
_In_ WDFREQUEST _In_ size_t _In_ size_t InputBufferLength
Definition: wdfio.h:322
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:953
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by assign_main().

◆ AssignNextDriveLetter()

BOOL AssignNextDriveLetter ( _In_ PWSTR  DeviceName,
_Out_ PWCHAR  DriveLetter 
)

Definition at line 258 of file mountmgr.c.

261{
264 ULONG DeviceNameLength, InputBufferLength;
265 HANDLE MountMgrHandle = NULL;
268 BOOL Ret = TRUE;
269
270 DPRINT("AssignNextDriveLetter(%S %p)\n", DeviceName, DriveLetter);
271
272 DeviceNameLength = wcslen(DeviceName) * sizeof(WCHAR);
273
276 if (InputBuffer == NULL)
277 {
278 DPRINT1("InputBuffer allocation failed!\n");
279 return FALSE;
280 }
281
282 /* And fill it with the device hat needs a drive letter */
283 InputBuffer->DeviceNameLength = DeviceNameLength;
284 RtlCopyMemory(&InputBuffer->DeviceName[0],
286 DeviceNameLength);
287
289 if (!NT_SUCCESS(Status))
290 {
291 DPRINT1("OpenMountManager() failed (Status 0x%08lx)\n", Status);
292 Ret = FALSE;
293 goto done;
294 }
295
296 Status = NtDeviceIoControlFile(MountMgrHandle,
297 NULL,
298 NULL,
299 NULL,
300 &Iosb,
304 &LetterInfo,
305 sizeof(LetterInfo));
306 if (!NT_SUCCESS(Status))
307 {
308 DPRINT1("NtDeviceIoControlFile() failed (Status 0x%08lx)\n", Status);
309 Ret = FALSE;
310 goto done;
311 }
312
313done:
314 if (MountMgrHandle)
315 NtClose(MountMgrHandle);
316
317 RtlFreeHeap(RtlGetProcessHeap(), 0, InputBuffer);
318
319 if (Ret)
320 {
321 if (LetterInfo.DriveLetterWasAssigned)
322 *DriveLetter = LetterInfo.CurrentDriveLetter;
323 else
324 *DriveLetter = UNICODE_NULL;
325 }
326
327 return Ret;
328}
#define UNICODE_NULL
#define DPRINT
Definition: sndvol32.h:73
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255

Referenced by assign_main().

◆ DeleteDriveLetter()

BOOL DeleteDriveLetter ( _In_ WCHAR  DriveLetter)

Definition at line 332 of file mountmgr.c.

334{
338 ULONG InputBufferLength, DosDeviceNameLength;
339 ULONG OutputBufferLength = 0x1000;
340 HANDLE MountMgrHandle = NULL;
343 BOOL Ret = TRUE;
344
345 DPRINT("DeleteDriveLetter(%c)\n", DriveLetter);
346
347 /* Setup the device name of the letter to delete */
348 swprintf(DosDeviceName, L"\\DosDevices\\%c:", DriveLetter);
349 DosDeviceNameLength = wcslen(DosDeviceName) * sizeof(WCHAR);
350
351 /* Allocate the input buffer for MountMgr */
352 InputBufferLength = DosDeviceNameLength + sizeof(MOUNTMGR_MOUNT_POINT);
354 if (InputBuffer == NULL)
355 {
356 DPRINT1("InputBuffer allocation failed!\n");
357 return FALSE;
358 }
359
360 /* Fill it in */
361 InputBuffer->SymbolicLinkNameOffset = sizeof(MOUNTMGR_MOUNT_POINT);
362 InputBuffer->SymbolicLinkNameLength = DosDeviceNameLength;
363 RtlCopyMemory(&InputBuffer[1], DosDeviceName, DosDeviceNameLength);
364
365 /* Allocate big enough output buffer (we don't care about the output) */
367 if (OutputBuffer == NULL)
368 {
369 DPRINT1("OutputBuffer allocation failed!\n");
370 Ret = FALSE;
371 goto done;
372 }
373
375
377 if (!NT_SUCCESS(Status))
378 {
379 DPRINT1("OpenMountManager() failed (Status 0x%08lx)\n", Status);
380 Ret = FALSE;
381 goto done;
382 }
383
384 Status = NtDeviceIoControlFile(MountMgrHandle,
385 NULL,
386 NULL,
387 NULL,
388 &Iosb,
394 if (!NT_SUCCESS(Status))
395 {
396 DPRINT1("NtDeviceIoControlFile() failed (Status 0x%08lx)\n", Status);
397 Ret = FALSE;
398 goto done;
399 }
400
401done:
402 if (MountMgrHandle)
403 NtClose(MountMgrHandle);
404
405 if (InputBuffer)
406 RtlFreeHeap(RtlGetProcessHeap(), 0, InputBuffer);
407
408 if (OutputBuffer)
409 RtlFreeHeap(RtlGetProcessHeap(), 0, OutputBuffer);
410
411 return Ret;
412}
#define GetProcessHeap()
Definition: compat.h:736
#define IOCTL_MOUNTMGR_DELETE_POINTS
Definition: imports.h:122
struct _MOUNTMGR_MOUNT_POINT MOUNTMGR_MOUNT_POINT
_In_ WDFREQUEST _In_ size_t OutputBufferLength
Definition: wdfio.h:320
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR OutputBuffer
Definition: wdfiotarget.h:863

Referenced by assign_main(), and remove_main().

◆ GetAutomountState()

BOOL GetAutomountState ( _Out_ PBOOL  State)

Definition at line 46 of file mountmgr.c.

48{
49 HANDLE MountMgrHandle;
53
54 DPRINT("ShowAutomountState()\n");
55
56 Status = OpenMountManager(&MountMgrHandle, GENERIC_READ);
57 if (!NT_SUCCESS(Status))
58 {
59 DPRINT1("OpenMountManager() Status 0x%08lx\n", Status);
60 return FALSE;
61 }
62
63 Status = NtDeviceIoControlFile(MountMgrHandle,
64 NULL,
65 NULL,
66 NULL,
67 &Iosb,
69 NULL,
70 0,
71 &AutoMount,
72 sizeof(AutoMount));
73
74 NtClose(MountMgrHandle);
75
76 if (!NT_SUCCESS(Status))
77 {
78 DPRINT1("NtDeviceIoControlFile() Status 0x%08lx\n", Status);
79 return FALSE;
80 }
81
82 if (State)
83 *State = (AutoMount.CurrentState == Enabled);
84
85 return TRUE;
86}
@ Enabled
Definition: mountmgr.h:179
#define IOCTL_MOUNTMGR_QUERY_AUTO_MOUNT
Definition: mountmgr.h:172
MOUNTMGR_AUTO_MOUNT_STATE CurrentState
Definition: mountmgr.h:183

Referenced by automount_main().

◆ OpenMountManager()

static NTSTATUS OpenMountManager ( _Out_ PHANDLE  MountMgrHandle,
_In_ ACCESS_MASK  Access 
)
static

Definition at line 20 of file mountmgr.c.

23{
27
29
32 0,
33 NULL,
34 NULL);
35
36 return NtOpenFile(MountMgrHandle,
37 Access | SYNCHRONIZE,
39 &Iosb,
40 0,
42}
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define MOUNTMGR_DEVICE_NAME
Definition: imports.h:74
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3953
#define SYNCHRONIZE
Definition: nt_native.h:61
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)

Referenced by AssignDriveLetter(), AssignNextDriveLetter(), DeleteDriveLetter(), GetAutomountState(), ScrubAutomount(), and SetAutomountState().

◆ ScrubAutomount()

BOOL ScrubAutomount ( VOID  )

Definition at line 141 of file mountmgr.c.

142{
143 HANDLE MountMgrHandle;
146
147 DPRINT("ScrubAutomount()\n");
148
150 if (!NT_SUCCESS(Status))
151 {
152 DPRINT1("OpenMountManager() Status 0x%08lx\n", Status);
153 return FALSE;
154 }
155
156 Status = NtDeviceIoControlFile(MountMgrHandle,
157 NULL,
158 NULL,
159 NULL,
160 &Iosb,
162 NULL,
163 0,
164 NULL,
165 0);
166
167 NtClose(MountMgrHandle);
168
169 if (!NT_SUCCESS(Status))
170 {
171 DPRINT1("NtDeviceIoControlFile() Status 0x%08lx\n", Status);
172 return FALSE;
173 }
174
175 return TRUE;
176}
#define IOCTL_MOUNTMGR_SCRUB_REGISTRY
Definition: mountmgr.h:170

Referenced by automount_main().

◆ SetAutomountState()

BOOL SetAutomountState ( _In_ BOOL  bEnable)

Definition at line 90 of file mountmgr.c.

92{
93 HANDLE MountMgrHandle;
97
98 DPRINT("SetAutomountState()\n");
99
101 if (!NT_SUCCESS(Status))
102 {
103 DPRINT1("OpenMountManager() Status 0x%08lx\n", Status);
104 return TRUE;
105 }
106
107 if (bEnable)
108 AutoMount.NewState = Enabled;
109 else
110 AutoMount.NewState = Disabled;
111
112 Status = NtDeviceIoControlFile(MountMgrHandle,
113 NULL,
114 NULL,
115 NULL,
116 &Iosb,
118 &AutoMount,
119 sizeof(AutoMount),
120 NULL,
121 0);
122
123 NtClose(MountMgrHandle);
124
125 if (!NT_SUCCESS(Status))
126 {
127 DPRINT1("NtDeviceIoControlFile() Status 0x%08lx\n", Status);
128 return TRUE;
129 }
130
131 if (AutoMount.NewState == Enabled)
133 else
135 ConPuts(StdOut, L"\n");
136
137 return TRUE;
138}
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
#define StdOut
Definition: fc.c:14
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
#define IDS_AUTOMOUNT_DISABLED
Definition: resource.h:27
#define IDS_AUTOMOUNT_ENABLED
Definition: resource.h:26
@ Disabled
Definition: mountmgr.h:178
#define IOCTL_MOUNTMGR_SET_AUTO_MOUNT
Definition: mountmgr.h:174
MOUNTMGR_AUTO_MOUNT_STATE NewState
Definition: mountmgr.h:187
_In_ BOOL bEnable
Definition: winddi.h:3426

Referenced by automount_main().