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