[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 EntryReferences; // 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 INIT_SECTION
238 BOOLEAN
239 MountmgrReadNoAutoMount(
240 IN PUNICODE_STRING RegistryPath
241 );
242
243 /* database.c */
244
245 extern PWSTR DatabasePath;
246 extern PWSTR OfflinePath;
247
248 VOID
249 ReconcileThisDatabaseWithMaster(
250 IN PDEVICE_EXTENSION DeviceExtension,
251 IN PDEVICE_INFORMATION DeviceInformation
252 );
253
254 NTSTATUS
255 WaitForRemoteDatabaseSemaphore(
256 IN PDEVICE_EXTENSION DeviceExtension
257 );
258
259 VOID
260 ReleaseRemoteDatabaseSemaphore(
261 IN PDEVICE_EXTENSION DeviceExtension
262 );
263
264 VOID
265 ChangeRemoteDatabaseUniqueId(
266 IN PDEVICE_INFORMATION DeviceInformation,
267 IN PMOUNTDEV_UNIQUE_ID OldUniqueId,
268 IN PMOUNTDEV_UNIQUE_ID NewUniqueId
269 );
270
271 VOID
272 ReconcileAllDatabasesWithMaster(
273 IN PDEVICE_EXTENSION DeviceExtension
274 );
275
276 VOID
277 DeleteFromLocalDatabase(
278 IN PUNICODE_STRING SymbolicLink,
279 IN PMOUNTDEV_UNIQUE_ID UniqueId
280 );
281
282 VOID
283 DeleteRegistryDriveLetter(
284 IN PMOUNTDEV_UNIQUE_ID UniqueId
285 );
286
287 VOID
288 DeleteNoDriveLetterEntry(
289 IN PMOUNTDEV_UNIQUE_ID UniqueId
290 );
291
292 NTSTATUS
293 QueryVolumeName(
294 IN HANDLE RootDirectory,
295 IN PFILE_REPARSE_POINT_INFORMATION ReparsePointInformation,
296 IN PUNICODE_STRING FileName OPTIONAL,
297 OUT PUNICODE_STRING SymbolicName,
298 OUT PUNICODE_STRING VolumeName
299 );
300
301 HANDLE
302 OpenRemoteDatabase(
303 IN PDEVICE_INFORMATION DeviceInformation,
304 IN BOOLEAN MigrateDatabase
305 );
306
307 PDATABASE_ENTRY
308 GetRemoteDatabaseEntry(
309 IN HANDLE Database,
310 IN LONG StartingOffset
311 );
312
313 NTSTATUS
314 WriteRemoteDatabaseEntry(
315 IN HANDLE Database,
316 IN LONG Offset,
317 IN PDATABASE_ENTRY Entry
318 );
319
320 NTSTATUS
321 CloseRemoteDatabase(
322 IN HANDLE Database
323 );
324
325 NTSTATUS
326 AddRemoteDatabaseEntry(
327 IN HANDLE Database,
328 IN PDATABASE_ENTRY Entry
329 );
330
331 NTSTATUS
332 DeleteRemoteDatabaseEntry(
333 IN HANDLE Database,
334 IN LONG StartingOffset
335 );
336
337 /* device.c */
338
339 DRIVER_DISPATCH MountMgrDeviceControl;
340
341 /* notify.c */
342 VOID
343 IssueUniqueIdChangeNotifyWorker(
344 IN PUNIQUE_ID_WORK_ITEM WorkItem,
345 IN PMOUNTDEV_UNIQUE_ID UniqueId
346 );
347
348 VOID
349 WaitForOnlinesToComplete(
350 IN PDEVICE_EXTENSION DeviceExtension
351 );
352
353 VOID
354 RegisterForTargetDeviceNotification(
355 IN PDEVICE_EXTENSION DeviceExtension,
356 IN PDEVICE_INFORMATION DeviceInformation
357 );
358
359 VOID
360 SendOnlineNotification(
361 IN PUNICODE_STRING SymbolicName
362 );
363
364 VOID
365 IssueUniqueIdChangeNotify(
366 IN PDEVICE_EXTENSION DeviceExtension,
367 IN PUNICODE_STRING DeviceName,
368 IN PMOUNTDEV_UNIQUE_ID UniqueId
369 );
370
371 VOID
372 PostOnlineNotification(
373 IN PDEVICE_EXTENSION DeviceExtension,
374 IN PUNICODE_STRING SymbolicName
375 );
376
377 VOID
378 MountMgrNotify(
379 IN PDEVICE_EXTENSION DeviceExtension
380 );
381
382 VOID
383 MountMgrNotifyNameChange(
384 IN PDEVICE_EXTENSION DeviceExtension,
385 IN PUNICODE_STRING DeviceName,
386 IN BOOLEAN ValidateVolume
387 );
388
389 /* uniqueid.c */
390 VOID
391 MountMgrUniqueIdChangeRoutine(
392 IN PDEVICE_EXTENSION DeviceExtension,
393 IN PMOUNTDEV_UNIQUE_ID OldUniqueId,
394 IN PMOUNTDEV_UNIQUE_ID NewUniqueId
395 );
396
397 VOID
398 CreateNoDriveLetterEntry(
399 IN PMOUNTDEV_UNIQUE_ID UniqueId
400 );
401
402 BOOLEAN
403 HasNoDriveLetterEntry(
404 IN PMOUNTDEV_UNIQUE_ID UniqueId
405 );
406
407 /* point.c */
408 NTSTATUS
409 MountMgrCreatePointWorker(
410 IN PDEVICE_EXTENSION DeviceExtension,
411 IN PUNICODE_STRING SymbolicLinkName,
412 IN PUNICODE_STRING DeviceName
413 );
414
415 NTSTATUS
416 QueryPointsFromSymbolicLinkName(
417 IN PDEVICE_EXTENSION DeviceExtension,
418 IN PUNICODE_STRING SymbolicName,
419 IN PIRP Irp
420 );
421
422 NTSTATUS
423 QueryPointsFromMemory(
424 IN PDEVICE_EXTENSION DeviceExtension,
425 IN PIRP Irp,
426 IN PMOUNTDEV_UNIQUE_ID UniqueId OPTIONAL,
427 IN PUNICODE_STRING SymbolicName OPTIONAL
428 );
429
430 /* symlink.c */
431 NTSTATUS
432 GlobalCreateSymbolicLink(
433 IN PUNICODE_STRING DosName,
434 IN PUNICODE_STRING DeviceName
435 );
436
437 NTSTATUS
438 GlobalDeleteSymbolicLink(
439 IN PUNICODE_STRING DosName
440 );
441
442 NTSTATUS
443 QuerySuggestedLinkName(
444 IN PUNICODE_STRING SymbolicName,
445 OUT PUNICODE_STRING SuggestedLinkName,
446 OUT PBOOLEAN UseOnlyIfThereAreNoOtherLinks
447 );
448
449 NTSTATUS
450 QuerySymbolicLinkNamesFromStorage(
451 IN PDEVICE_EXTENSION DeviceExtension,
452 IN PDEVICE_INFORMATION DeviceInformation,
453 IN PUNICODE_STRING SuggestedLinkName,
454 IN BOOLEAN UseOnlyIfThereAreNoOtherLinks,
455 OUT PUNICODE_STRING * SymLinks,
456 OUT PULONG SymLinkCount,
457 IN BOOLEAN HasGuid,
458 IN LPGUID Guid
459 );
460
461 PSAVED_LINK_INFORMATION
462 RemoveSavedLinks(
463 IN PDEVICE_EXTENSION DeviceExtension,
464 IN PMOUNTDEV_UNIQUE_ID UniqueId
465 );
466
467 BOOLEAN
468 RedirectSavedLink(
469 IN PSAVED_LINK_INFORMATION SavedLinkInformation,
470 IN PUNICODE_STRING DosName,
471 IN PUNICODE_STRING NewLink
472 );
473
474 VOID
475 SendLinkCreated(
476 IN PUNICODE_STRING SymbolicName
477 );
478
479 NTSTATUS
480 CreateNewVolumeName(
481 OUT PUNICODE_STRING VolumeName,
482 IN PGUID VolumeGuid OPTIONAL
483 );
484
485 BOOLEAN
486 IsDriveLetter(
487 PUNICODE_STRING SymbolicName
488 );
489
490 VOID
491 DeleteSymbolicLinkNameFromMemory(
492 IN PDEVICE_EXTENSION DeviceExtension,
493 IN PUNICODE_STRING SymbolicLink,
494 IN BOOLEAN MarkOffline
495 );
496
497 NTSTATUS
498 MountMgrQuerySymbolicLink(
499 IN PUNICODE_STRING SymbolicName,
500 IN OUT PUNICODE_STRING LinkTarget
501 );
502
503 #endif /* _MNTMGR_H_ */