[MOUNTMGR]
[reactos.git] / reactos / drivers / filters / mountmgr / mntmgr.h
1 #ifndef _MNTMGR_H_
2 #define _MNTMGR_H_
3
4 #include <ntifs.h>
5 #include <mountdev.h>
6 #include <ntddvol.h>
7 #include <wdmguid.h>
8 #include <ndk/psfuncs.h>
9 #include <ntdddisk.h>
10
11 #ifdef __GNUC__
12 #define INIT_SECTION __attribute__((section ("INIT")))
13 #else
14 #define INIT_SECTION /* Done via alloc_text for MSC */
15 #endif
16
17 /* Enter FIXME */
18 #ifdef IsEqualGUID
19 #undef IsEqualGUID
20 #endif
21
22 #define IsEqualGUID(rguid1, rguid2) (RtlCompareMemory(rguid1, rguid2, sizeof(GUID)) == sizeof(GUID))
23
24 #define FILE_READ_PROPERTIES 0x00000008
25 #define FILE_WRITE_PROPERTIES 0x00000010
26
27 #define GPT_BASIC_DATA_ATTRIBUTE_NO_DRIVE_LETTER 0x80000000
28 /* Leave FIXME */
29
30 typedef struct _DEVICE_EXTENSION
31 {
32 PDEVICE_OBJECT DeviceObject; // 0x0
33 PDRIVER_OBJECT DriverObject; // 0x4
34 LIST_ENTRY DeviceListHead; // 0x8
35 LIST_ENTRY OfflineDeviceListHead; // 0x10
36 PVOID NotificationEntry; // 0x18
37 KSEMAPHORE DeviceLock; // 0x1C
38 KSEMAPHORE RemoteDatabaseLock; // 0x30
39 ULONG AutomaticDriveLetter; // 0x44
40 LIST_ENTRY IrpListHead; // 0x48
41 ULONG EpicNumber; // 0x50
42 LIST_ENTRY SavedLinksListHead; // 0x54
43 BOOLEAN ProcessedSuggestions; // 0x5C
44 BOOLEAN NoAutoMount; // 0x5D
45 LIST_ENTRY WorkerQueueListHead; // 0x60
46 KSEMAPHORE WorkerSemaphore; // 0x68
47 LONG WorkerReferences; // 0x7C
48 KSPIN_LOCK WorkerLock; // 0x80
49 LIST_ENTRY UniqueIdWorkerItemListHead; // 0x84
50 PMOUNTDEV_UNIQUE_ID DriveLetterData; // 0x8C
51 UNICODE_STRING RegistryPath; // 0x90
52 LONG WorkerThreadStatus; // 0x98
53 LIST_ENTRY OnlineNotificationListHead; // 0x9C
54 ULONG OnlineNotificationWorkerActive; // 0xA4
55 ULONG OnlineNotificationCount; // 0xA8
56 KEVENT OnlineNotificationEvent; // 0xAC
57 } DEVICE_EXTENSION, *PDEVICE_EXTENSION; // 0xBC
58
59 typedef struct _DEVICE_INFORMATION
60 {
61 LIST_ENTRY DeviceListEntry; // 0x00
62 LIST_ENTRY SymbolicLinksListHead; // 0x08
63 LIST_ENTRY ReplicatedUniqueIdsListHead; // 0x10
64 LIST_ENTRY AssociatedDevicesHead; // 0x18
65 UNICODE_STRING SymbolicName; // 0x20
66 PMOUNTDEV_UNIQUE_ID UniqueId; // 0x28
67 UNICODE_STRING DeviceName; // 0x2C
68 BOOLEAN KeepLinks; // 0x34
69 UCHAR SuggestedDriveLetter; // 0x35
70 BOOLEAN Volume; // 0x36
71 BOOLEAN Removable; // 0x37
72 BOOLEAN LetterAssigned; // 0x38
73 BOOLEAN NeedsReconcile; // 0x39
74 BOOLEAN NoDatabase; // 0x3A
75 BOOLEAN SkipNotifications; // 0x3B
76 ULONG Migrated; // 0x3C
77 LONG MountState; // 0x40
78 PVOID TargetDeviceNotificationEntry; // 0x44
79 PDEVICE_EXTENSION DeviceExtension; // 0x48
80 } DEVICE_INFORMATION, *PDEVICE_INFORMATION; // 0x4C
81
82 typedef struct _SYMLINK_INFORMATION
83 {
84 LIST_ENTRY SymbolicLinksListEntry; // 0x00
85 UNICODE_STRING Name; // 0x08
86 BOOLEAN Online; // 0x10
87 } SYMLINK_INFORMATION, *PSYMLINK_INFORMATION; // 0x14
88
89 typedef struct _SAVED_LINK_INFORMATION
90 {
91 LIST_ENTRY SavedLinksListEntry; // 0x0
92 LIST_ENTRY SymbolicLinksListHead; // 0x8
93 PMOUNTDEV_UNIQUE_ID UniqueId; // 0x10
94 } SAVED_LINK_INFORMATION, *PSAVED_LINK_INFORMATION; // 0x14
95
96 typedef struct _UNIQUE_ID_REPLICATE
97 {
98 LIST_ENTRY ReplicatedUniqueIdsListEntry; // 0x0
99 PMOUNTDEV_UNIQUE_ID UniqueId; // 0x8
100 } UNIQUE_ID_REPLICATE, *PUNIQUE_ID_REPLICATE; // 0xC
101
102 typedef struct _DATABASE_ENTRY
103 {
104 ULONG EntrySize; // 0x00
105 ULONG DatabaseOffset; // 0x04
106 USHORT SymbolicNameOffset; // 0x08
107 USHORT SymbolicNameLength; // 0x0A
108 USHORT UniqueIdOffset; // 0x0C
109 USHORT UniqueIdLength; // 0x0E
110 } DATABASE_ENTRY, *PDATABASE_ENTRY; // 0x10
111
112 typedef struct _ASSOCIATED_DEVICE_ENTRY
113 {
114 LIST_ENTRY AssociatedDevicesEntry; // 0x00
115 PDEVICE_INFORMATION DeviceInformation; // 0x08
116 UNICODE_STRING String; // 0x0C
117 } ASSOCIATED_DEVICE_ENTRY, *PASSOCIATED_DEVICE_ENTRY; // 0x14
118
119 typedef struct _ONLINE_NOTIFICATION_WORK_ITEM
120 {
121 WORK_QUEUE_ITEM; // 0x00
122 PDEVICE_EXTENSION DeviceExtension; // 0x10
123 UNICODE_STRING SymbolicName; // 0x14
124 } ONLINE_NOTIFICATION_WORK_ITEM, *PONLINE_NOTIFICATION_WORK_ITEM; // 0x1C
125
126 typedef struct _RECONCILE_WORK_ITEM
127 {
128 LIST_ENTRY WorkerQueueListEntry; // 0x00
129 PIO_WORKITEM WorkItem; // 0x08
130 PWORKER_THREAD_ROUTINE WorkerRoutine; // 0x0C
131 PVOID Context; // 0x10
132 PDEVICE_EXTENSION DeviceExtension; // 0x14
133 PDEVICE_INFORMATION DeviceInformation; // 0x18
134 } RECONCILE_WORK_ITEM, *PRECONCILE_WORK_ITEM; // 0x1C
135
136 typedef struct _MIGRATE_WORK_ITEM
137 {
138 PIO_WORKITEM WorkItem; // 0x0
139 PDEVICE_INFORMATION DeviceInformation; // 0x4
140 PKEVENT Event; // 0x8
141 NTSTATUS Status; // 0x0C
142 HANDLE Database; // 0x10
143 } MIGRATE_WORK_ITEM, *PMIGRATE_WORK_ITEM; // 0x14
144
145 typedef struct _UNIQUE_ID_WORK_ITEM
146 {
147 LIST_ENTRY UniqueIdWorkerItemListEntry; // 0x0
148 PIO_WORKITEM WorkItem; // 0x8
149 PDEVICE_EXTENSION DeviceExtension; // 0xC
150 PIRP Irp; // 0x10
151 PVOID IrpBuffer; // 0x14
152 PKEVENT Event; // 0x1C
153 UNICODE_STRING DeviceName; // 0x20
154 ULONG IrpBufferLength; // 0x28
155 ULONG StackSize; // 0x2C
156 } UNIQUE_ID_WORK_ITEM, *PUNIQUE_ID_WORK_ITEM; // 0x30
157
158 /* Memory allocation helpers */
159 #define AllocatePool(Size) ExAllocatePoolWithTag(PagedPool, Size, 'AtnM')
160 #define FreePool(P) ExFreePoolWithTag(P, 'AtnM')
161
162 /* Misc macros */
163 #define MAX(a, b) ((a > b) ? a : b)
164
165 #define LETTER_POSITION 0xC
166 #define COLON_POSITION 0xD
167 #define DRIVE_LETTER_LENGTH 0x1C
168
169 /* mountmgr.c */
170
171 extern UNICODE_STRING DosDevicesMount;
172 extern PDEVICE_OBJECT gdeviceObject;
173 extern UNICODE_STRING ReparseIndex;
174 extern UNICODE_STRING DeviceFloppy;
175 extern UNICODE_STRING DeviceMount;
176 extern UNICODE_STRING DeviceCdRom;
177 extern UNICODE_STRING SafeVolumes;
178 extern UNICODE_STRING DosDevices;
179 extern UNICODE_STRING DosGlobal;
180 extern UNICODE_STRING Global;
181 extern UNICODE_STRING Volume;
182 extern KEVENT UnloadEvent;
183 extern LONG Unloading;
184
185 DRIVER_INITIALIZE DriverEntry;
186
187 VOID
188 NTAPI
189 MountMgrCancel(
190 IN PDEVICE_OBJECT DeviceObject,
191 IN PIRP Irp
192 );
193
194 NTSTATUS
195 MountMgrMountedDeviceArrival(
196 IN PDEVICE_EXTENSION Extension,
197 IN PUNICODE_STRING SymbolicName,
198 IN BOOLEAN FromVolume
199 );
200
201 VOID
202 MountMgrMountedDeviceRemoval(
203 IN PDEVICE_EXTENSION Extension,
204 IN PUNICODE_STRING DeviceName
205 );
206
207 NTSTATUS
208 FindDeviceInfo(
209 IN PDEVICE_EXTENSION DeviceExtension,
210 IN PUNICODE_STRING SymbolicName,
211 IN BOOLEAN DeviceNameGiven,
212 OUT PDEVICE_INFORMATION * DeviceInformation
213 );
214
215 VOID
216 MountMgrFreeDeadDeviceInfo(
217 IN PDEVICE_INFORMATION DeviceInformation
218 );
219
220 NTSTATUS
221 QueryDeviceInformation(
222 IN PUNICODE_STRING SymbolicName,
223 OUT PUNICODE_STRING DeviceName OPTIONAL,
224 OUT PMOUNTDEV_UNIQUE_ID * UniqueId OPTIONAL,
225 OUT PBOOLEAN Removable OPTIONAL,
226 OUT PBOOLEAN GptDriveLetter OPTIONAL,
227 OUT PBOOLEAN HasGuid OPTIONAL,
228 IN OUT LPGUID StableGuid OPTIONAL,
229 OUT PBOOLEAN Valid OPTIONAL
230 );
231
232 BOOLEAN
233 HasDriveLetter(
234 IN PDEVICE_INFORMATION DeviceInformation
235 );
236
237 /* database.c */
238
239 extern PWSTR DatabasePath;
240 extern PWSTR OfflinePath;
241
242 VOID
243 ReconcileThisDatabaseWithMaster(
244 IN PDEVICE_EXTENSION DeviceExtension,
245 IN PDEVICE_INFORMATION DeviceInformation
246 );
247
248 NTSTATUS
249 WaitForRemoteDatabaseSemaphore(
250 IN PDEVICE_EXTENSION DeviceExtension
251 );
252
253 VOID
254 ReleaseRemoteDatabaseSemaphore(
255 IN PDEVICE_EXTENSION DeviceExtension
256 );
257
258 VOID
259 ChangeRemoteDatabaseUniqueId(
260 IN PDEVICE_INFORMATION DeviceInformation,
261 IN PMOUNTDEV_UNIQUE_ID OldUniqueId,
262 IN PMOUNTDEV_UNIQUE_ID NewUniqueId
263 );
264
265 VOID
266 ReconcileAllDatabasesWithMaster(
267 IN PDEVICE_EXTENSION DeviceExtension
268 );
269
270 VOID
271 DeleteFromLocalDatabase(
272 IN PUNICODE_STRING SymbolicLink,
273 IN PMOUNTDEV_UNIQUE_ID UniqueId
274 );
275
276 VOID
277 DeleteRegistryDriveLetter(
278 IN PMOUNTDEV_UNIQUE_ID UniqueId
279 );
280
281 VOID
282 DeleteNoDriveLetterEntry(
283 IN PMOUNTDEV_UNIQUE_ID UniqueId
284 );
285
286 NTSTATUS
287 QueryVolumeName(
288 IN HANDLE RootDirectory,
289 IN PFILE_REPARSE_POINT_INFORMATION ReparsePointInformation,
290 IN PUNICODE_STRING FileName OPTIONAL,
291 OUT PUNICODE_STRING SymbolicName,
292 OUT PUNICODE_STRING VolumeName
293 );
294
295 /* device.c */
296
297 DRIVER_DISPATCH MountMgrDeviceControl;
298
299 /* notify.c */
300 VOID
301 IssueUniqueIdChangeNotifyWorker(
302 IN PUNIQUE_ID_WORK_ITEM WorkItem,
303 IN PMOUNTDEV_UNIQUE_ID UniqueId
304 );
305
306 VOID
307 WaitForOnlinesToComplete(
308 IN PDEVICE_EXTENSION DeviceExtension
309 );
310
311 VOID
312 RegisterForTargetDeviceNotification(
313 IN PDEVICE_EXTENSION DeviceExtension,
314 IN PDEVICE_INFORMATION DeviceInformation
315 );
316
317 VOID
318 SendOnlineNotification(
319 IN PUNICODE_STRING SymbolicName
320 );
321
322 VOID
323 IssueUniqueIdChangeNotify(
324 IN PDEVICE_EXTENSION DeviceExtension,
325 IN PUNICODE_STRING DeviceName,
326 IN PMOUNTDEV_UNIQUE_ID UniqueId
327 );
328
329 VOID
330 PostOnlineNotification(
331 IN PDEVICE_EXTENSION DeviceExtension,
332 IN PUNICODE_STRING SymbolicName
333 );
334
335 VOID
336 MountMgrNotify(
337 IN PDEVICE_EXTENSION DeviceExtension
338 );
339
340 VOID
341 MountMgrNotifyNameChange(
342 IN PDEVICE_EXTENSION DeviceExtension,
343 IN PUNICODE_STRING DeviceName,
344 IN BOOLEAN ValidateVolume
345 );
346
347 /* uniqueid.c */
348 VOID
349 MountMgrUniqueIdChangeRoutine(
350 IN PDEVICE_EXTENSION DeviceExtension,
351 IN PMOUNTDEV_UNIQUE_ID OldUniqueId,
352 IN PMOUNTDEV_UNIQUE_ID NewUniqueId
353 );
354
355 VOID
356 CreateNoDriveLetterEntry(
357 IN PMOUNTDEV_UNIQUE_ID UniqueId
358 );
359
360 BOOLEAN
361 HasNoDriveLetterEntry(
362 IN PMOUNTDEV_UNIQUE_ID UniqueId
363 );
364
365 /* point.c */
366 NTSTATUS
367 MountMgrCreatePointWorker(
368 IN PDEVICE_EXTENSION DeviceExtension,
369 IN PUNICODE_STRING SymbolicLinkName,
370 IN PUNICODE_STRING DeviceName
371 );
372
373 NTSTATUS
374 QueryPointsFromSymbolicLinkName(
375 IN PDEVICE_EXTENSION DeviceExtension,
376 IN PUNICODE_STRING SymbolicName,
377 IN PIRP Irp
378 );
379
380 NTSTATUS
381 QueryPointsFromMemory(
382 IN PDEVICE_EXTENSION DeviceExtension,
383 IN PIRP Irp,
384 IN PMOUNTDEV_UNIQUE_ID UniqueId OPTIONAL,
385 IN PUNICODE_STRING SymbolicName OPTIONAL
386 );
387
388 /* symlink.c */
389 NTSTATUS
390 GlobalCreateSymbolicLink(
391 IN PUNICODE_STRING DosName,
392 IN PUNICODE_STRING DeviceName
393 );
394
395 NTSTATUS
396 GlobalDeleteSymbolicLink(
397 IN PUNICODE_STRING DosName
398 );
399
400 NTSTATUS
401 QuerySuggestedLinkName(
402 IN PUNICODE_STRING SymbolicName,
403 OUT PUNICODE_STRING SuggestedLinkName,
404 OUT PBOOLEAN UseOnlyIfThereAreNoOtherLinks
405 );
406
407 NTSTATUS
408 QuerySymbolicLinkNamesFromStorage(
409 IN PDEVICE_EXTENSION DeviceExtension,
410 IN PDEVICE_INFORMATION DeviceInformation,
411 IN PUNICODE_STRING SuggestedLinkName,
412 IN BOOLEAN UseOnlyIfThereAreNoOtherLinks,
413 OUT PUNICODE_STRING * SymLinks,
414 OUT PULONG SymLinkCount,
415 IN BOOLEAN HasGuid,
416 IN LPGUID Guid
417 );
418
419 PSAVED_LINK_INFORMATION
420 RemoveSavedLinks(
421 IN PDEVICE_EXTENSION DeviceExtension,
422 IN PMOUNTDEV_UNIQUE_ID UniqueId
423 );
424
425 BOOLEAN
426 RedirectSavedLink(
427 IN PSAVED_LINK_INFORMATION SavedLinkInformation,
428 IN PUNICODE_STRING DosName,
429 IN PUNICODE_STRING NewLink
430 );
431
432 VOID
433 SendLinkCreated(
434 IN PUNICODE_STRING SymbolicName
435 );
436
437 NTSTATUS
438 CreateNewVolumeName(
439 OUT PUNICODE_STRING VolumeName,
440 IN PGUID VolumeGuid OPTIONAL
441 );
442
443 BOOLEAN
444 IsDriveLetter(
445 PUNICODE_STRING SymbolicName
446 );
447
448 VOID
449 DeleteSymbolicLinkNameFromMemory(
450 IN PDEVICE_EXTENSION DeviceExtension,
451 IN PUNICODE_STRING SymbolicLink,
452 IN BOOLEAN MarkOffline
453 );
454
455 #endif /* _MNTMGR_H_ */