ReactOS  0.4.15-dev-994-ga9f6032
notify.c File Reference
#include "mntmgr.h"
#include <ioevent.h>
#include <debug.h>
Include dependency graph for notify.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID SendOnlineNotification (IN PUNICODE_STRING SymbolicName)
 
VOID NTAPI SendOnlineNotificationWorker (IN PVOID Parameter)
 
VOID PostOnlineNotification (IN PDEVICE_EXTENSION DeviceExtension, IN PUNICODE_STRING SymbolicName)
 
VOID WaitForOnlinesToComplete (IN PDEVICE_EXTENSION DeviceExtension)
 
NTSTATUS NTAPI MountMgrTargetDeviceNotification (IN PVOID NotificationStructure, IN PVOID Context)
 
VOID RegisterForTargetDeviceNotification (IN PDEVICE_EXTENSION DeviceExtension, IN PDEVICE_INFORMATION DeviceInformation)
 
VOID MountMgrNotify (IN PDEVICE_EXTENSION DeviceExtension)
 
VOID MountMgrNotifyNameChange (IN PDEVICE_EXTENSION DeviceExtension, IN PUNICODE_STRING DeviceName, IN BOOLEAN ValidateVolume)
 
VOID RemoveWorkItem (IN PUNIQUE_ID_WORK_ITEM WorkItem)
 
VOID NTAPI UniqueIdChangeNotifyWorker (IN PDEVICE_OBJECT DeviceObject, IN PVOID Context)
 
NTSTATUS NTAPI UniqueIdChangeNotifyCompletion (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
 
VOID IssueUniqueIdChangeNotifyWorker (IN PUNIQUE_ID_WORK_ITEM WorkItem, IN PMOUNTDEV_UNIQUE_ID UniqueId)
 
VOID IssueUniqueIdChangeNotify (IN PDEVICE_EXTENSION DeviceExtension, IN PUNICODE_STRING DeviceName, IN PMOUNTDEV_UNIQUE_ID UniqueId)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 31 of file notify.c.

Function Documentation

◆ IssueUniqueIdChangeNotify()

VOID IssueUniqueIdChangeNotify ( IN PDEVICE_EXTENSION  DeviceExtension,
IN PUNICODE_STRING  DeviceName,
IN PMOUNTDEV_UNIQUE_ID  UniqueId 
)

Definition at line 662 of file notify.c.

665 {
667  PVOID IrpBuffer = NULL;
670  PUNIQUE_ID_WORK_ITEM WorkItem = NULL;
671 
672  /* Get the associated device object */
675  &FileObject,
676  &DeviceObject);
677  if (!NT_SUCCESS(Status))
678  {
679  return;
680  }
681 
682  /* And then, get attached device */
684 
686 
687  /* Allocate a work item */
688  WorkItem = AllocatePool(sizeof(UNIQUE_ID_WORK_ITEM));
689  if (!WorkItem)
690  {
692  return;
693  }
694 
695  WorkItem->Event = NULL;
696  WorkItem->WorkItem = IoAllocateWorkItem(DeviceExtension->DeviceObject);
697  if (!WorkItem->WorkItem)
698  {
700  goto Cleanup;
701  }
702 
703  WorkItem->DeviceExtension = DeviceExtension;
704  WorkItem->StackSize = DeviceObject->StackSize;
705  /* Already provide the IRP */
707 
709 
710  if (!WorkItem->Irp)
711  {
712  goto Cleanup;
713  }
714 
715  /* Ensure it has enough space */
716  IrpBuffer = AllocatePool(sizeof(MOUNTDEV_UNIQUE_ID_CHANGE_NOTIFY_OUTPUT) + 1024);
717  if (!IrpBuffer)
718  {
719  goto Cleanup;
720  }
721 
722  WorkItem->DeviceName.Length = DeviceName->Length;
723  WorkItem->DeviceName.MaximumLength = DeviceName->Length + sizeof(WCHAR);
724  WorkItem->DeviceName.Buffer = AllocatePool(WorkItem->DeviceName.MaximumLength);
725  if (!WorkItem->DeviceName.Buffer)
726  {
727  goto Cleanup;
728  }
729 
730  RtlCopyMemory(WorkItem->DeviceName.Buffer, DeviceName->Buffer, DeviceName->Length);
731  WorkItem->DeviceName.Buffer[DeviceName->Length / sizeof(WCHAR)] = UNICODE_NULL;
732 
733  WorkItem->IrpBuffer = IrpBuffer;
734  WorkItem->IrpBufferLength = sizeof(MOUNTDEV_UNIQUE_ID_CHANGE_NOTIFY_OUTPUT) + 1024;
735 
736  /* Add the worker in the list */
737  KeWaitForSingleObject(&(DeviceExtension->DeviceLock), Executive, KernelMode, FALSE, NULL);
738  InsertHeadList(&(DeviceExtension->UniqueIdWorkerItemListHead), &(WorkItem->UniqueIdWorkerItemListEntry));
739  KeReleaseSemaphore(&(DeviceExtension->DeviceLock), IO_NO_INCREMENT, 1, FALSE);
740 
741  /* And call the worker */
742  IssueUniqueIdChangeNotifyWorker(WorkItem, UniqueId);
743 
744  return;
745 
746 Cleanup:
747  if (IrpBuffer)
748  {
749  FreePool(IrpBuffer);
750  }
751 
752  if (WorkItem->Irp)
753  {
754  IoFreeIrp(WorkItem->Irp);
755  }
756 
757  if (WorkItem->WorkItem)
758  {
759  IoFreeWorkItem(WorkItem->WorkItem);
760  }
761 
762  if (WorkItem)
763  {
764  FreePool(WorkItem);
765  }
766 }
UNICODE_STRING DeviceName
Definition: mntmgr.h:147
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
USHORT MaximumLength
Definition: env_spec_w32.h:370
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1435
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
WCHAR DeviceName[]
Definition: adapter.cpp:21
PDEVICE_EXTENSION DeviceExtension
Definition: mntmgr.h:143
PIO_WORKITEM NTAPI IoAllocateWorkItem(IN PDEVICE_OBJECT DeviceObject)
Definition: iowork.c:75
#define FreePool(P)
Definition: mntmgr.h:154
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
VOID NTAPI IoFreeWorkItem(IN PIO_WORKITEM IoWorkItem)
Definition: iowork.c:64
PIO_WORKITEM WorkItem
Definition: mntmgr.h:142
VOID IssueUniqueIdChangeNotifyWorker(IN PUNIQUE_ID_WORK_ITEM WorkItem, IN PMOUNTDEV_UNIQUE_ID UniqueId)
Definition: notify.c:592
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
smooth NULL
Definition: ftsmooth.c:416
ULONG IrpBufferLength
Definition: mntmgr.h:148
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:588
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
struct _MOUNTDEV_UNIQUE_ID_CHANGE_NOTIFY_OUTPUT MOUNTDEV_UNIQUE_ID_CHANGE_NOTIFY_OUTPUT
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
* PFILE_OBJECT
Definition: iotypes.h:1962
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
LIST_ENTRY UniqueIdWorkerItemListEntry
Definition: mntmgr.h:141
Status
Definition: gdiplustypes.h:24
static const WCHAR Cleanup[]
Definition: register.c:80
#define AllocatePool(Size)
Definition: mntmgr.h:153
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
LONG NTAPI KeReleaseSemaphore(IN PKSEMAPHORE Semaphore, IN KPRIORITY Increment, IN LONG Adjustment, IN BOOLEAN Wait)
Definition: semphobj.c:54
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
#define IO_NO_INCREMENT
Definition: iotypes.h:570
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615

Referenced by MountMgrMountedDeviceArrival().

◆ IssueUniqueIdChangeNotifyWorker()

VOID IssueUniqueIdChangeNotifyWorker ( IN PUNIQUE_ID_WORK_ITEM  WorkItem,
IN PMOUNTDEV_UNIQUE_ID  UniqueId 
)

Definition at line 592 of file notify.c.

594 {
595  PIRP Irp;
598  PIO_STACK_LOCATION Stack;
600 
601  /* Get the device object */
602  Status = IoGetDeviceObjectPointer(&(WorkItem->DeviceName),
604  &FileObject,
605  &DeviceObject);
606  if (!NT_SUCCESS(Status))
607  {
608  RemoveWorkItem(WorkItem);
609  return;
610  }
611 
612  /* And then, the attached device */
614 
615  /* Initialize the IRP */
616  Irp = WorkItem->Irp;
617  IoInitializeIrp(Irp, IoSizeOfIrp(WorkItem->StackSize), (CCHAR)WorkItem->StackSize);
618 
619  if (InterlockedExchange((PLONG)&(WorkItem->Event), 0) != 0)
620  {
623  RemoveWorkItem(WorkItem);
624  return;
625  }
626 
627  Irp->AssociatedIrp.SystemBuffer = WorkItem->IrpBuffer;
628  Irp->Tail.Overlay.Thread = PsGetCurrentThread();
629  RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, UniqueId, UniqueId->UniqueIdLength + sizeof(USHORT));
630 
632 
633  Stack->Parameters.DeviceIoControl.InputBufferLength = UniqueId->UniqueIdLength + sizeof(USHORT);
634  Stack->Parameters.DeviceIoControl.OutputBufferLength = WorkItem->IrpBufferLength;
635  Stack->Parameters.DeviceIoControl.Type3InputBuffer = 0;
636  Stack->Parameters.DeviceIoControl.IoControlCode = IOCTL_MOUNTDEV_UNIQUE_ID_CHANGE_NOTIFY;
638 
639  Status = IoSetCompletionRoutineEx(WorkItem->DeviceExtension->DeviceObject,
640  Irp,
642  WorkItem,
643  TRUE, TRUE, TRUE);
644  if (!NT_SUCCESS(Status))
645  {
648  RemoveWorkItem(WorkItem);
649  return;
650  }
651 
652  /* Call the driver */
656 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define IOCTL_MOUNTDEV_UNIQUE_ID_CHANGE_NOTIFY
Definition: imports.h:86
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
_In_ PIRP Irp
Definition: csq.h:116
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1435
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
VOID NTAPI IoInitializeIrp(IN PIRP Irp, IN USHORT PacketSize, IN CCHAR StackSize)
Definition: irp.c:1854
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:588
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
char CCHAR
Definition: typedefs.h:51
NTSTATUS NTAPI IoSetCompletionRoutineEx(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PIO_COMPLETION_ROUTINE CompletionRoutine, IN PVOID Context, IN BOOLEAN InvokeOnSuccess, IN BOOLEAN InvokeOnError, IN BOOLEAN InvokeOnCancel)
Definition: iocomp.c:220
* PFILE_OBJECT
Definition: iotypes.h:1962
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2691
#define InterlockedExchange
Definition: armddk.h:54
NTSTATUS NTAPI UniqueIdChangeNotifyCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: notify.c:570
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
unsigned short USHORT
Definition: pedump.c:61
#define IoSizeOfIrp(_StackSize)
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
VOID RemoveWorkItem(IN PUNIQUE_ID_WORK_ITEM WorkItem)
Definition: notify.c:482
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2779
signed int * PLONG
Definition: retypes.h:5
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52

Referenced by IssueUniqueIdChangeNotify(), and UniqueIdChangeNotifyWorker().

◆ MountMgrNotify()

VOID MountMgrNotify ( IN PDEVICE_EXTENSION  DeviceExtension)

Definition at line 313 of file notify.c.

314 {
315  PIRP Irp;
316  KIRQL OldIrql;
317  LIST_ENTRY CopyList;
318  PLIST_ENTRY NextEntry;
319 
320  /* Increase the epic number */
321  DeviceExtension->EpicNumber++;
322 
323  InitializeListHead(&CopyList);
324 
325  /* Copy all the pending IRPs for notification */
327  while (!IsListEmpty(&(DeviceExtension->IrpListHead)))
328  {
329  NextEntry = RemoveHeadList(&(DeviceExtension->IrpListHead));
330  Irp = CONTAINING_RECORD(NextEntry, IRP, Tail.Overlay.ListEntry);
332  InsertTailList(&CopyList, &(Irp->Tail.Overlay.ListEntry));
333  }
335 
336  /* Then, notify them one by one */
337  while (!IsListEmpty(&CopyList))
338  {
339  NextEntry = RemoveHeadList(&CopyList);
340  Irp = CONTAINING_RECORD(NextEntry, IRP, Tail.Overlay.ListEntry);
341 
342  *((PULONG)Irp->AssociatedIrp.SystemBuffer) = DeviceExtension->EpicNumber;
343  Irp->IoStatus.Information = sizeof(DeviceExtension->EpicNumber);
344 
346  }
347 }
_In_ PIRP Irp
Definition: csq.h:116
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
#define InsertTailList(ListHead, Entry)
IoSetCancelRoutine(Irp, CancelRoutine)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
UCHAR KIRQL
Definition: env_spec_w32.h:591
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
Definition: typedefs.h:119
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
unsigned int * PULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:570

Referenced by MountMgrCreatePointWorker(), MountMgrDeletePoints(), and MountMgrVolumeMountPointChanged().

◆ MountMgrNotifyNameChange()

VOID MountMgrNotifyNameChange ( IN PDEVICE_EXTENSION  DeviceExtension,
IN PUNICODE_STRING  DeviceName,
IN BOOLEAN  ValidateVolume 
)

Definition at line 353 of file notify.c.

356 {
357  PIRP Irp;
358  KEVENT Event;
360  PLIST_ENTRY NextEntry;
362  PIO_STACK_LOCATION Stack;
365  PDEVICE_RELATIONS DeviceRelations;
366  PDEVICE_INFORMATION DeviceInformation;
367  TARGET_DEVICE_CUSTOM_NOTIFICATION DeviceNotification;
368 
369  /* If we have to validate volume */
370  if (ValidateVolume)
371  {
372  /* Then, ensure we can find the device */
373  for (NextEntry = DeviceExtension->DeviceListHead.Flink;
374  NextEntry != &DeviceExtension->DeviceListHead;
375  NextEntry = NextEntry->Flink)
376  {
377  DeviceInformation = CONTAINING_RECORD(NextEntry, DEVICE_INFORMATION, DeviceListEntry);
378  if (RtlCompareUnicodeString(DeviceName, &(DeviceInformation->DeviceName), TRUE) == 0)
379  {
380  break;
381  }
382  }
383 
384  /* No need to notify for a PnP device or if we didn't find the device */
385  if (NextEntry == &(DeviceExtension->DeviceListHead) ||
386  !DeviceInformation->ManuallyRegistered)
387  {
388  return;
389  }
390  }
391 
392  /* Then, get device object */
395  &FileObject,
396  &DeviceObject);
397  if (!NT_SUCCESS(Status))
398  {
399  return;
400  }
401 
403 
405 
406  /* Set up empty IRP (yes, yes!) */
408  DeviceObject,
409  NULL,
410  0,
411  NULL,
412  0,
413  FALSE,
414  &Event,
415  &IoStatusBlock);
416  if (!Irp)
417  {
420  return;
421  }
422 
424 
425  Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
426  Irp->IoStatus.Information = 0;
427 
428  /* Properly set it, we want to query device relations */
429  Stack->MajorFunction = IRP_MJ_PNP;
431  Stack->Parameters.QueryDeviceRelations.Type = TargetDeviceRelation;
432  Stack->FileObject = FileObject;
433 
434  /* And call driver */
436  if (Status == STATUS_PENDING)
437  {
440  }
441 
444 
445  if (!NT_SUCCESS(Status))
446  {
447  return;
448  }
449 
450  /* Validate device return */
451  DeviceRelations = (PDEVICE_RELATIONS)IoStatusBlock.Information;
452  if (DeviceRelations->Count < 1)
453  {
454  ExFreePool(DeviceRelations);
455  return;
456  }
457 
458  DeviceObject = DeviceRelations->Objects[0];
459  ExFreePool(DeviceRelations);
460 
461  /* Set up real notification */
462  DeviceNotification.Version = 1;
463  DeviceNotification.Size = sizeof(TARGET_DEVICE_CUSTOM_NOTIFICATION);
464  DeviceNotification.Event = GUID_IO_VOLUME_NAME_CHANGE;
465  DeviceNotification.FileObject = NULL;
466  DeviceNotification.NameBufferOffset = -1;
467 
468  /* And report */
470  &DeviceNotification,
471  NULL, NULL);
472 
474 
475  return;
476 }
struct _TARGET_DEVICE_CUSTOM_NOTIFICATION TARGET_DEVICE_CUSTOM_NOTIFICATION
_In_ PIRP Irp
Definition: csq.h:116
#define TRUE
Definition: types.h:120
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2062
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1435
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
WCHAR DeviceName[]
Definition: adapter.cpp:21
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define FALSE
Definition: types.h:117
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:439
struct _DEVICE_RELATIONS * PDEVICE_RELATIONS
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:588
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
* PFILE_OBJECT
Definition: iotypes.h:1962
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
Status
Definition: gdiplustypes.h:24
ULONG RtlCompareUnicodeString(PUNICODE_STRING s1, PUNICODE_STRING s2, BOOLEAN UpCase)
Definition: string_lib.cpp:31
Definition: typedefs.h:119
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2691
BOOLEAN ManuallyRegistered
Definition: mntmgr.h:53
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
PFILE_OBJECT FileObject
Definition: iotypes.h:2820
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IRP_MN_QUERY_DEVICE_RELATIONS
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
UNICODE_STRING DeviceName
Definition: mntmgr.h:50
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
struct _FILE_OBJECT * FileObject
Definition: iotypes.h:979
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2779
NTSTATUS NTAPI IoReportTargetDeviceChangeAsynchronous(IN PDEVICE_OBJECT PhysicalDeviceObject, IN PVOID NotificationStructure, IN PDEVICE_CHANGE_COMPLETE_CALLBACK Callback OPTIONAL, IN PVOID Context OPTIONAL)
Definition: pnpreport.c:515
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by MountMgrCreatePointWorker(), MountMgrDeletePoints(), MountMgrQueryDosVolumePaths(), and MountMgrVolumeMountPointChanged().

◆ MountMgrTargetDeviceNotification()

NTSTATUS NTAPI MountMgrTargetDeviceNotification ( IN PVOID  NotificationStructure,
IN PVOID  Context 
)

Definition at line 229 of file notify.c.

231 {
232  PDEVICE_EXTENSION DeviceExtension;
233  PDEVICE_INFORMATION DeviceInformation;
235 
236  DeviceInformation = Context;
237  DeviceExtension = DeviceInformation->DeviceExtension;
238  Notification = NotificationStructure;
239 
240  /* If it's to signal that removal is complete, then, execute the function */
241  if (IsEqualGUID(&(Notification->Event), &GUID_TARGET_DEVICE_REMOVE_COMPLETE))
242  {
243  MountMgrMountedDeviceRemoval(DeviceExtension, Notification->SymbolicLinkName);
244  }
245  /* It it's to signal that a volume has been mounted
246  * Verify if a database sync is required and execute it
247  */
248  else if (IsEqualGUID(&(Notification->Event), &GUID_IO_VOLUME_MOUNT))
249  {
250  /* If we were already mounted, then mark us unmounted */
251  if (InterlockedCompareExchange(&(DeviceInformation->MountState),
252  FALSE,
253  FALSE) == TRUE)
254  {
255  InterlockedDecrement(&(DeviceInformation->MountState));
256  }
257  /* Otherwise, start mounting the device and first, reconcile its DB if required */
258  else
259  {
260  if (DeviceInformation->NeedsReconcile)
261  {
262  DeviceInformation->NeedsReconcile = FALSE;
263  ReconcileThisDatabaseWithMaster(DeviceExtension, DeviceInformation);
264  }
265  }
266  }
267 
268  return STATUS_SUCCESS;
269 }
_In_ PVOID NotificationStructure
Definition: iofuncs.h:1203
#define TRUE
Definition: types.h:120
#define InterlockedCompareExchange
Definition: interlocked.h:104
VOID MountMgrMountedDeviceRemoval(IN PDEVICE_EXTENSION Extension, IN PUNICODE_STRING DeviceName)
Definition: mountmgr.c:1452
VOID ReconcileThisDatabaseWithMaster(IN PDEVICE_EXTENSION DeviceExtension, IN PDEVICE_INFORMATION DeviceInformation)
Definition: database.c:1613
#define FALSE
Definition: types.h:117
BOOLEAN NeedsReconcile
Definition: mntmgr.h:56
PDEVICE_EXTENSION DeviceExtension
Definition: mntmgr.h:62
#define InterlockedDecrement
Definition: armddk.h:52
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
struct tagContext Context
Definition: acpixf.h:1034
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by RegisterForTargetDeviceNotification().

◆ PostOnlineNotification()

VOID PostOnlineNotification ( IN PDEVICE_EXTENSION  DeviceExtension,
IN PUNICODE_STRING  SymbolicName 
)

Definition at line 145 of file notify.c.

147 {
148  KIRQL OldIrql;
150 
151  /* Allocate a notification work item */
152  WorkItem = AllocatePool(sizeof(ONLINE_NOTIFICATION_WORK_ITEM));
153  if (!WorkItem)
154  {
155  return;
156  }
157 
159  WorkItem->DeviceExtension = DeviceExtension;
160  WorkItem->SymbolicName.Length = SymbolicName->Length;
161  WorkItem->SymbolicName.MaximumLength = SymbolicName->Length + sizeof(WCHAR);
163  if (!WorkItem->SymbolicName.Buffer)
164  {
165  FreePool(WorkItem);
166  return;
167  }
168 
170  WorkItem->SymbolicName.Buffer[SymbolicName->Length / sizeof(WCHAR)] = UNICODE_NULL;
171 
172  KeAcquireSpinLock(&(DeviceExtension->WorkerLock), &OldIrql);
173  DeviceExtension->OnlineNotificationCount++;
174 
175  /* If no worker are active */
176  if (DeviceExtension->OnlineNotificationWorkerActive == 0)
177  {
178  /* Queue that one for execution */
179  DeviceExtension->OnlineNotificationWorkerActive = 1;
181  }
182  else
183  {
184  /* Otherwise, just put it in the queue list */
185  InsertTailList(&(DeviceExtension->OnlineNotificationListHead), &(WorkItem->WorkItem.List));
186  }
187 
188  KeReleaseSpinLock(&(DeviceExtension->WorkerLock), OldIrql);
189 
190  return;
191 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:717
LIST_ENTRY List
Definition: extypes.h:203
USHORT MaximumLength
Definition: env_spec_w32.h:370
_In_ PNDIS_STRING _In_ PNDIS_STRING SymbolicName
Definition: ndis.h:4676
#define InsertTailList(ListHead, Entry)
#define FreePool(P)
Definition: mntmgr.h:154
UCHAR KIRQL
Definition: env_spec_w32.h:591
WORK_QUEUE_ITEM WorkItem
Definition: mntmgr.h:110
#define UNICODE_NULL
VOID NTAPI SendOnlineNotificationWorker(IN PVOID Parameter)
Definition: notify.c:96
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
__wchar_t WCHAR
Definition: xmlstorage.h:180
PDEVICE_EXTENSION DeviceExtension
Definition: mntmgr.h:111
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define AllocatePool(Size)
Definition: mntmgr.h:153
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
UNICODE_STRING SymbolicName
Definition: mntmgr.h:112

Referenced by MountMgrCreatePointWorker(), MountMgrVolumeMountPointCreated(), OnlineMountedVolumes(), and ReconcileThisDatabaseWithMasterWorker().

◆ RegisterForTargetDeviceNotification()

VOID RegisterForTargetDeviceNotification ( IN PDEVICE_EXTENSION  DeviceExtension,
IN PDEVICE_INFORMATION  DeviceInformation 
)

Definition at line 275 of file notify.c.

277 {
281 
282  /* Get device object */
283  Status = IoGetDeviceObjectPointer(&(DeviceInformation->DeviceName),
285  &FileObject,
286  &DeviceObject);
287  if (!NT_SUCCESS(Status))
288  {
289  return;
290  }
291 
292  /* And simply register for notifications */
294  0, FileObject,
295  DeviceExtension->DriverObject,
297  DeviceInformation,
298  &(DeviceInformation->TargetDeviceNotificationEntry));
299  if (!NT_SUCCESS(Status))
300  {
301  DeviceInformation->TargetDeviceNotificationEntry = NULL;
302  }
303 
305 
306  return;
307 }
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI MountMgrTargetDeviceNotification(IN PVOID NotificationStructure, IN PVOID Context)
Definition: notify.c:229
NTSTATUS NTAPI IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1435
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:588
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
* PFILE_OBJECT
Definition: iotypes.h:1962
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI IoRegisterPlugPlayNotification(IN IO_NOTIFICATION_EVENT_CATEGORY EventCategory, IN ULONG EventCategoryFlags, IN PVOID EventCategoryData OPTIONAL, IN PDRIVER_OBJECT DriverObject, IN PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine, IN PVOID Context, OUT PVOID *NotificationEntry)
Definition: pnpnotify.c:249
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569

Referenced by MountMgrMountedDeviceArrival().

◆ RemoveWorkItem()

VOID RemoveWorkItem ( IN PUNIQUE_ID_WORK_ITEM  WorkItem)

Definition at line 482 of file notify.c.

483 {
484  PDEVICE_EXTENSION DeviceExtension = WorkItem->DeviceExtension;
485 
486  KeWaitForSingleObject(&(DeviceExtension->DeviceLock), Executive, KernelMode, FALSE, NULL);
487 
488  /* If even if being worked, it's too late */
489  if (WorkItem->Event)
490  {
491  KeReleaseSemaphore(&(DeviceExtension->DeviceLock), IO_NO_INCREMENT, 1, FALSE);
492  KeSetEvent(WorkItem->Event, 0, FALSE);
493  }
494  else
495  {
496  /* Otherwise, remove it from the list, and delete it */
497  RemoveEntryList(&(WorkItem->UniqueIdWorkerItemListEntry));
498  KeReleaseSemaphore(&(DeviceExtension->DeviceLock), IO_NO_INCREMENT, 1, FALSE);
499  IoFreeIrp(WorkItem->Irp);
500  FreePool(WorkItem->DeviceName.Buffer);
501  FreePool(WorkItem->IrpBuffer);
502  FreePool(WorkItem);
503  }
504 }
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define FreePool(P)
Definition: mntmgr.h:154
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
LONG NTAPI KeReleaseSemaphore(IN PKSEMAPHORE Semaphore, IN KPRIORITY Increment, IN LONG Adjustment, IN BOOLEAN Wait)
Definition: semphobj.c:54
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
#define IO_NO_INCREMENT
Definition: iotypes.h:570

Referenced by IssueUniqueIdChangeNotifyWorker(), and UniqueIdChangeNotifyWorker().

◆ SendOnlineNotification()

VOID SendOnlineNotification ( IN PUNICODE_STRING  SymbolicName)

Definition at line 38 of file notify.c.

39 {
40  PIRP Irp;
41  KEVENT Event;
44  PIO_STACK_LOCATION Stack;
47 
48  /* Get device object */
51  &FileObject,
52  &DeviceObject);
53  if (!NT_SUCCESS(Status))
54  {
55  return;
56  }
57 
58  /* And attached device object */
60 
61  /* And send VOLUME_ONLINE */
65  NULL, 0,
66  NULL, 0,
67  FALSE,
68  &Event,
69  &IoStatusBlock);
70  if (!Irp)
71  {
72  goto Cleanup;
73  }
74 
76  Stack->FileObject = FileObject;
77 
79  if (Status == STATUS_PENDING)
80  {
82  }
83 
84 Cleanup:
87 
88  return;
89 }
_In_ PIRP Irp
Definition: csq.h:116
_In_ PNDIS_STRING _In_ PNDIS_STRING SymbolicName
Definition: ndis.h:4676
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1435
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define FALSE
Definition: types.h:117
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:439
smooth NULL
Definition: ftsmooth.c:416
#define IOCTL_VOLUME_ONLINE
Definition: ntddvol.h:62
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:588
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1406
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
* PFILE_OBJECT
Definition: iotypes.h:1962
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
Status
Definition: gdiplustypes.h:24
static const WCHAR Cleanup[]
Definition: register.c:80
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2691
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
PFILE_OBJECT FileObject
Definition: iotypes.h:2820
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881

Referenced by MountMgrMountedDeviceArrival(), and SendOnlineNotificationWorker().

◆ SendOnlineNotificationWorker()

VOID NTAPI SendOnlineNotificationWorker ( IN PVOID  Parameter)

Definition at line 96 of file notify.c.

97 {
98  KIRQL OldIrql;
99  PLIST_ENTRY Head;
100  PDEVICE_EXTENSION DeviceExtension;
102  PONLINE_NOTIFICATION_WORK_ITEM NewWorkItem;
103 
105  DeviceExtension = WorkItem->DeviceExtension;
106 
107  /* First, send the notification */
108  SendOnlineNotification(&(WorkItem->SymbolicName));
109 
110  KeAcquireSpinLock(&(DeviceExtension->WorkerLock), &OldIrql);
111  /* If there are no notifications running any longer, reset event */
112  if (--DeviceExtension->OnlineNotificationCount == 0)
113  {
114  KeSetEvent(&(DeviceExtension->OnlineNotificationEvent), 0, FALSE);
115  }
116 
117  /* If there are still notifications in queue */
118  if (!IsListEmpty(&(DeviceExtension->OnlineNotificationListHead)))
119  {
120  /* Queue a new one for execution */
121  Head = RemoveHeadList(&(DeviceExtension->OnlineNotificationListHead));
122  NewWorkItem = CONTAINING_RECORD(Head, ONLINE_NOTIFICATION_WORK_ITEM, WorkItem.List);
123  KeReleaseSpinLock(&(DeviceExtension->WorkerLock), OldIrql);
124  NewWorkItem->WorkItem.List.Blink = NULL;
125  NewWorkItem->WorkItem.List.Flink = NULL;
126  ExQueueWorkItem(&NewWorkItem->WorkItem, DelayedWorkQueue);
127  }
128  else
129  {
130  /* Mark it's over */
131  DeviceExtension->OnlineNotificationWorkerActive = 0;
132  KeReleaseSpinLock(&(DeviceExtension->WorkerLock), OldIrql);
133  }
134 
135  FreePool(WorkItem->SymbolicName.Buffer);
136  FreePool(WorkItem);
137 
138  return;
139 }
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:717
LIST_ENTRY List
Definition: extypes.h:203
VOID SendOnlineNotification(IN PUNICODE_STRING SymbolicName)
Definition: notify.c:38
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
_In_ PVOID Parameter
Definition: ldrtypes.h:241
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define FreePool(P)
Definition: mntmgr.h:154
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
UCHAR KIRQL
Definition: env_spec_w32.h:591
WORK_QUEUE_ITEM WorkItem
Definition: mntmgr.h:110
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
PDEVICE_EXTENSION DeviceExtension
Definition: mntmgr.h:111
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
Definition: typedefs.h:119
struct _ONLINE_NOTIFICATION_WORK_ITEM * PONLINE_NOTIFICATION_WORK_ITEM
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
UNICODE_STRING SymbolicName
Definition: mntmgr.h:112

Referenced by PostOnlineNotification().

◆ UniqueIdChangeNotifyCompletion()

NTSTATUS NTAPI UniqueIdChangeNotifyCompletion ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PVOID  Context 
)

Definition at line 570 of file notify.c.

573 {
574  PUNIQUE_ID_WORK_ITEM WorkItem = Context;
575 
578 
579  /* Simply queue the work item */
580  IoQueueWorkItem(WorkItem->WorkItem,
583  WorkItem);
584 
586 }
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
VOID NTAPI UniqueIdChangeNotifyWorker(IN PDEVICE_OBJECT DeviceObject, IN PVOID Context)
Definition: notify.c:511
PIO_WORKITEM WorkItem
Definition: mntmgr.h:142
VOID NTAPI IoQueueWorkItem(IN PIO_WORKITEM IoWorkItem, IN PIO_WORKITEM_ROUTINE WorkerRoutine, IN WORK_QUEUE_TYPE QueueType, IN PVOID Context)
Definition: iowork.c:40
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
struct tagContext Context
Definition: acpixf.h:1034

Referenced by IssueUniqueIdChangeNotifyWorker().

◆ UniqueIdChangeNotifyWorker()

VOID NTAPI UniqueIdChangeNotifyWorker ( IN PDEVICE_OBJECT  DeviceObject,
IN PVOID  Context 
)

Definition at line 511 of file notify.c.

513 {
514  PUNIQUE_ID_WORK_ITEM WorkItem = Context;
515  PMOUNTDEV_UNIQUE_ID OldUniqueId, NewUniqueId;
517 
519 
520  /* Validate worker */
521  if (!NT_SUCCESS(WorkItem->Irp->IoStatus.Status))
522  {
523  RemoveWorkItem(WorkItem);
524  return;
525  }
526 
527  UniqueIdChange = WorkItem->Irp->AssociatedIrp.SystemBuffer;
528  /* Get the old unique ID */
529  OldUniqueId = AllocatePool(UniqueIdChange->OldUniqueIdLength + sizeof(MOUNTDEV_UNIQUE_ID));
530  if (!OldUniqueId)
531  {
532  RemoveWorkItem(WorkItem);
533  return;
534  }
535 
536  OldUniqueId->UniqueIdLength = UniqueIdChange->OldUniqueIdLength;
537  RtlCopyMemory(OldUniqueId->UniqueId,
538  (PVOID)((ULONG_PTR)UniqueIdChange + UniqueIdChange->OldUniqueIdOffset),
539  UniqueIdChange->OldUniqueIdLength);
540 
541  /* Get the new unique ID */
542  NewUniqueId = AllocatePool(UniqueIdChange->NewUniqueIdLength + sizeof(MOUNTDEV_UNIQUE_ID));
543  if (!NewUniqueId)
544  {
545  FreePool(OldUniqueId);
546  RemoveWorkItem(WorkItem);
547  return;
548  }
549 
550  NewUniqueId->UniqueIdLength = UniqueIdChange->NewUniqueIdLength;
551  RtlCopyMemory(NewUniqueId->UniqueId,
552  (PVOID)((ULONG_PTR)UniqueIdChange + UniqueIdChange->NewUniqueIdOffset),
553  UniqueIdChange->NewUniqueIdLength);
554 
555  /* Call the real worker */
556  MountMgrUniqueIdChangeRoutine(WorkItem->DeviceExtension, OldUniqueId, NewUniqueId);
557  IssueUniqueIdChangeNotifyWorker(WorkItem, NewUniqueId);
558 
559  FreePool(NewUniqueId);
560  FreePool(OldUniqueId);
561 
562  return;
563 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
USHORT UniqueIdLength
Definition: imports.h:138
IO_STATUS_BLOCK IoStatus
PDEVICE_EXTENSION DeviceExtension
Definition: mntmgr.h:143
#define FreePool(P)
Definition: mntmgr.h:154
uint32_t ULONG_PTR
Definition: typedefs.h:65
VOID IssueUniqueIdChangeNotifyWorker(IN PUNIQUE_ID_WORK_ITEM WorkItem, IN PMOUNTDEV_UNIQUE_ID UniqueId)
Definition: notify.c:592
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define AllocatePool(Size)
Definition: mntmgr.h:153
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
VOID RemoveWorkItem(IN PUNIQUE_ID_WORK_ITEM WorkItem)
Definition: notify.c:482
struct tagContext Context
Definition: acpixf.h:1034
VOID MountMgrUniqueIdChangeRoutine(IN PDEVICE_EXTENSION DeviceExtension, IN PMOUNTDEV_UNIQUE_ID OldUniqueId, IN PMOUNTDEV_UNIQUE_ID NewUniqueId)
Definition: uniqueid.c:71
UCHAR UniqueId[1]
Definition: imports.h:139

Referenced by UniqueIdChangeNotifyCompletion().

◆ WaitForOnlinesToComplete()

VOID WaitForOnlinesToComplete ( IN PDEVICE_EXTENSION  DeviceExtension)

Definition at line 197 of file notify.c.

198 {
199  KIRQL OldIrql;
200 
201  KeInitializeEvent(&(DeviceExtension->OnlineNotificationEvent), NotificationEvent, FALSE);
202 
203  KeAcquireSpinLock(&(DeviceExtension->WorkerLock), &OldIrql);
204 
205  /* Just wait all the worker are done */
206  if (DeviceExtension->OnlineNotificationCount != 1)
207  {
208  DeviceExtension->OnlineNotificationCount--;
209  KeReleaseSpinLock(&(DeviceExtension->WorkerLock), OldIrql);
210 
211  KeWaitForSingleObject(&(DeviceExtension->OnlineNotificationEvent),
212  Executive,
213  KernelMode,
214  FALSE,
215  NULL);
216 
217  KeAcquireSpinLock(&(DeviceExtension->WorkerLock), &OldIrql);
218  DeviceExtension->OnlineNotificationCount++;
219  }
220 
221  KeReleaseSpinLock(&(DeviceExtension->WorkerLock), OldIrql);
222 }
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627

Referenced by MountMgrDeviceControl().