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