{
PIO_STACK_LOCATION Stack;
PREQUEST_POWER_ITEM RequestPowerItem;
-
+
Stack = IoGetNextIrpStackLocation(Irp);
RequestPowerItem = (PREQUEST_POWER_ITEM)Context;
-
+
RequestPowerItem->CompletionRoutine(DeviceObject,
Stack->MinorFunction,
RequestPowerItem->PowerState,
{
PPOWER_STATE_TRAVERSE_CONTEXT PowerStateContext = Context;
NTSTATUS Status;
-
+
DPRINT("PopQuerySystemPowerStateTraverse(%p, %p)\n", DeviceNode, Context);
-
+
if (DeviceNode == IopRootDeviceNode)
return STATUS_SUCCESS;
-
+
if (DeviceNode->Flags & DNF_LEGACY_DRIVER)
return STATUS_SUCCESS;
{
DPRINT1("Device '%wZ' failed IRP_MN_QUERY_POWER\n", &DeviceNode->InstancePath);
}
-
+
#if 0
return Status;
#else
{
PPOWER_STATE_TRAVERSE_CONTEXT PowerStateContext = Context;
NTSTATUS Status;
-
+
DPRINT("PopSetSystemPowerStateTraverse(%p, %p)\n", DeviceNode, Context);
-
+
if (DeviceNode == IopRootDeviceNode)
return STATUS_SUCCESS;
-
+
if (DeviceNode->PhysicalDeviceObject == PowerStateContext->PowerDevice)
return STATUS_SUCCESS;
-
+
if (DeviceNode->Flags & DNF_LEGACY_DRIVER)
return STATUS_SUCCESS;
{
DPRINT1("Device '%wZ' failed IRP_MN_SET_POWER\n", &DeviceNode->InstancePath);
}
-
+
#if 0
return Status;
#else
NTSTATUS Status;
DEVICETREE_TRAVERSE_CONTEXT Context;
POWER_STATE_TRAVERSE_CONTEXT PowerContext;
-
+
Status = IopGetSystemPowerDeviceObject(&DeviceObject);
if (!NT_SUCCESS(Status))
{
return STATUS_UNSUCCESSFUL;
}
}
-
+
/* Set up context */
PowerContext.PowerAction = PowerAction;
PowerContext.SystemPowerState = PowerState;
PowerContext.PowerDevice = Fdo;
-
+
/* Query for system power change */
IopInitDeviceTreeTraverseContext(&Context,
IopRootDeviceNode,
PopQuerySystemPowerStateTraverse,
&PowerContext);
-
+
Status = IopTraverseDeviceTree(&Context);
if (!NT_SUCCESS(Status))
{
DPRINT1("Query system power state failed; changing state anyway\n");
}
-
+
/* Set system power change */
IopInitDeviceTreeTraverseContext(&Context,
IopRootDeviceNode,
PopSetSystemPowerStateTraverse,
&PowerContext);
-
+
IopTraverseDeviceTree(&Context);
if (!PopAcpiPresent) return STATUS_NOT_IMPLEMENTED;
-
+
if (Fdo != NULL)
{
if (PowerAction != PowerActionShutdownReset)
PopAddRemoveSysCapsCallback,
NULL,
&NotificationEntry);
-
+
/* Register lid notification */
IoRegisterPlugPlayNotification(EventCategoryDeviceInterfaceChange,
PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES,
PopAcpiPresent = KeLoaderBlock->Extension->AcpiTable != NULL ? TRUE : FALSE;
}
-
+
/* Initialize volume support */
InitializeListHead(&PopVolumeDevices);
KeInitializeGuardedMutex(&PopVolumeLock);
-
+
/* Initialize support for dope */
KeInitializeSpinLock(&PopDopeGlobalLock);
PIO_STACK_LOCATION Stack;
PIRP Irp;
PREQUEST_POWER_ITEM RequestPowerItem;
-
+
if (MinorFunction != IRP_MN_QUERY_POWER
&& MinorFunction != IRP_MN_SET_POWER
&& MinorFunction != IRP_MN_WAIT_WAKE)
return STATUS_INVALID_PARAMETER_2;
-
+
RequestPowerItem = ExAllocatePool(NonPagedPool, sizeof(REQUEST_POWER_ITEM));
if (!RequestPowerItem)
return STATUS_INSUFFICIENT_RESOURCES;
-
+
/* Always call the top of the device stack */
TopDeviceObject = IoGetAttachedDeviceReference(DeviceObject);
-
+
Irp = IoBuildAsynchronousFsdRequest(IRP_MJ_POWER,
TopDeviceObject,
NULL,
ExFreePool(RequestPowerItem);
return STATUS_INSUFFICIENT_RESOURCES;
}
-
+
/* POWER IRPs are always initialized with a status code of
STATUS_NOT_IMPLEMENTED */
Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
Irp->IoStatus.Information = 0;
-
+
Stack = IoGetNextIrpStackLocation(Irp);
Stack->MinorFunction = MinorFunction;
if (MinorFunction == IRP_MN_WAIT_WAKE)
Stack->Parameters.Power.Type = DevicePowerState;
Stack->Parameters.Power.State = PowerState;
}
-
+
RequestPowerItem->CompletionRoutine = CompletionFunction;
RequestPowerItem->PowerState = PowerState;
RequestPowerItem->Context = Context;
RequestPowerItem->TopDeviceObject = TopDeviceObject;
-
+
if (pIrp != NULL)
*pIrp = Irp;
-
+
IoSetCompletionRoutine(Irp, PopRequestPowerIrpCompletion, RequestPowerItem, TRUE, TRUE, TRUE);
PoCallDriver(TopDeviceObject, Irp);
-
+
/* Always return STATUS_PENDING. The completion routine
* will call CompletionFunction and complete the Irp.
*/
PowerInformationLevel,
InputBuffer, InputBufferLength,
OutputBuffer, OutputBufferLength);
-
+
switch (PowerInformationLevel)
{
case SystemBatteryState:
{
/* Not granted */
DPRINT1("ERROR: Privilege not held for shutdown\n");
- //return STATUS_PRIVILEGE_NOT_HELD; HACK!
+ return STATUS_PRIVILEGE_NOT_HELD;
}
/* Do it as a kernel-mode caller for consistency with system state */
if (SystemAction == PowerActionShutdown) PopReadShutdownPolicy();
/* Disable lazy flushing of registry */
- DPRINT1("Stopping lazy flush\n");
+ DPRINT("Stopping lazy flush\n");
CmSetLazyFlushState(FALSE);
/* Setup the power action */
Action.Flags = Flags;
/* Notify callbacks */
- DPRINT1("Notifying callbacks\n");
+ DPRINT("Notifying callbacks\n");
ExNotifyCallback(PowerStateCallback, (PVOID)3, NULL);
-
+
/* Swap in any worker thread stacks */
- DPRINT1("Swapping worker threads\n");
+ DPRINT("Swapping worker threads\n");
ExSwapinWorkerThreads(FALSE);
-
+
/* Make our action global */
PopAction = Action;
/* Check if we're still in an invalid status */
if (!NT_SUCCESS(Status)) break;
-
+
#ifndef NEWCC
/* Flush dirty cache pages */
CcRosFlushDirtyPages(-1, &Dummy, FALSE); //HACK: We really should wait here!
#endif
/* Flush all volumes and the registry */
- DPRINT1("Flushing volumes, cache flushed %lu pages\n", Dummy);
+ DPRINT("Flushing volumes, cache flushed %lu pages\n", Dummy);
PopFlushVolumes(PopAction.Shutdown);
/* Set IRP for drivers */
PopAction.IrpMinor = IRP_MN_SET_POWER;
if (PopAction.Shutdown)
{
- DPRINT1("Queueing shutdown thread\n");
+ DPRINT("Queueing shutdown thread\n");
/* Check if we are running in the system context */
if (PsGetCurrentProcess() != PsInitialSystemProcess)
{
NULL);
ExQueueWorkItem(&PopShutdownWorkItem, CriticalWorkQueue);
-
+
/* Spend us -- when we wake up, the system is good to go down */
KeSuspendThread(KeGetCurrentThread());
Status = STATUS_SYSTEM_SHUTDOWN;
PopGracefulShutdown(NULL);
}
}
-
+
/* You should not have made it this far */
- ASSERT(FALSE && "System is still up and running?!");
+ ASSERTMSG("System is still up and running?!", FALSE);
break;
}