VOID DokanUnmount(__in PDokanDCB Dcb) { ULONG eventLength; PEVENT_CONTEXT eventContext; PDRIVER_EVENT_CONTEXT driverEventContext; PKEVENT completedEvent; LARGE_INTEGER timeout; PDokanVCB vcb = Dcb->Vcb; ULONG deviceNamePos; DDbgPrint("==> DokanUnmount\n"); eventLength = sizeof(EVENT_CONTEXT); eventContext = AllocateEventContextRaw(eventLength); if (eventContext == NULL) { ; // STATUS_INSUFFICIENT_RESOURCES; DDbgPrint(" Not able to allocate eventContext.\n"); if (vcb) { DokanEventRelease(vcb->DeviceObject); } return; } driverEventContext = CONTAINING_RECORD(eventContext, DRIVER_EVENT_CONTEXT, EventContext); completedEvent = ExAllocatePool(sizeof(KEVENT)); if (completedEvent) { KeInitializeEvent(completedEvent, NotificationEvent, FALSE); driverEventContext->Completed = completedEvent; } deviceNamePos = Dcb->SymbolicLinkName->Length / sizeof(WCHAR) - 1; for (; Dcb->SymbolicLinkName->Buffer[deviceNamePos] != L'\\'; --deviceNamePos) ; RtlStringCchCopyW(eventContext->Operation.Unmount.DeviceName, sizeof(eventContext->Operation.Unmount.DeviceName) / sizeof(WCHAR), &(Dcb->SymbolicLinkName->Buffer[deviceNamePos])); DDbgPrint(" Send Unmount to Service : %ws\n", eventContext->Operation.Unmount.DeviceName); DokanEventNotification(&Dcb->Global->NotifyService, eventContext); if (completedEvent) { timeout.QuadPart = -1 * 10 * 1000 * 10; // 10 sec KeWaitForSingleObject(completedEvent, Executive, KernelMode, FALSE, &timeout); } if (vcb) { DokanEventRelease(vcb->DeviceObject); } if (completedEvent) { ExFreePool(completedEvent); } DDbgPrint("<== DokanUnmount\n"); }
PEVENT_CONTEXT AllocateEventContext(__in PDokanDCB Dcb, __in PIRP Irp, __in ULONG EventContextLength, __in_opt PDokanCCB Ccb) { PEVENT_CONTEXT eventContext; eventContext = AllocateEventContextRaw(EventContextLength); if (eventContext == NULL) { return NULL; } SetCommonEventContext(Dcb, eventContext, Irp, Ccb); eventContext->SerialNumber = InterlockedIncrement((LONG *)&Dcb->SerialNumber); return eventContext; }