[FREELDR]
[reactos.git] / ntoskrnl / po / power.c
index e8d37b8..a163b98 100644 (file)
@@ -52,7 +52,7 @@ PopRequestPowerIrpCompletion(IN PDEVICE_OBJECT DeviceObject,
 
     IoFreeIrp(Irp);
 
-    return STATUS_SUCCESS;
+    return STATUS_MORE_PROCESSING_REQUIRED;
 }
 
 VOID
@@ -136,7 +136,7 @@ PoInitSystem(IN ULONG BootPhase)
     /* Check if this is phase 1 init */
     if (BootPhase == 1)
     {
-        /* Registry power button notification */
+        /* Register power button notification */
         IoRegisterPlugPlayNotification(EventCategoryDeviceInterfaceChange,
                                        PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES,
                                        (PVOID)&GUID_DEVICE_SYS_BUTTON,
@@ -145,6 +145,16 @@ PoInitSystem(IN ULONG BootPhase)
                                        PopAddRemoveSysCapsCallback,
                                        NULL,
                                        &NotificationEntry);
+        
+        /* Register lid notification */
+        IoRegisterPlugPlayNotification(EventCategoryDeviceInterfaceChange,
+                                       PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES,
+                                       (PVOID)&GUID_DEVICE_LID,
+                                       IopRootDeviceNode->
+                                       PhysicalDeviceObject->DriverObject,
+                                       PopAddRemoveSysCapsCallback,
+                                       NULL,
+                                       &NotificationEntry);
         return TRUE;
     }
 
@@ -360,7 +370,6 @@ PoRequestPowerIrp(IN PDEVICE_OBJECT DeviceObject,
     PIO_STACK_LOCATION Stack;
     PIRP Irp;
     PREQUEST_POWER_ITEM RequestPowerItem;
-    NTSTATUS Status;
   
     if (MinorFunction != IRP_MN_QUERY_POWER
         && MinorFunction != IRP_MN_SET_POWER
@@ -409,7 +418,7 @@ PoRequestPowerIrp(IN PDEVICE_OBJECT DeviceObject,
         *pIrp = Irp;
   
     IoSetCompletionRoutine(Irp, PopRequestPowerIrpCompletion, RequestPowerItem, TRUE, TRUE, TRUE);
-    Status = IoCallDriver(TopDeviceObject, Irp);
+    IoCallDriver(TopDeviceObject, Irp);
   
     /* Always return STATUS_PENDING. The completion routine
      * will call CompletionFunction and complete the Irp.
@@ -650,6 +659,7 @@ NtSetSystemPowerState(IN POWER_ACTION SystemAction,
     KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
     POP_POWER_ACTION Action = {0};
     NTSTATUS Status;
+    ULONG Dummy;
 
     /* Check for invalid parameter combinations */
     if ((MinSystemState >= PowerSystemMaximum) ||
@@ -733,9 +743,12 @@ NtSetSystemPowerState(IN POWER_ACTION SystemAction,
 
         /* Check if we're still in an invalid status */
         if (!NT_SUCCESS(Status)) break;
+        
+        /* Flush dirty cache pages */
+        CcRosFlushDirtyPages(-1, &Dummy);
 
         /* Flush all volumes and the registry */
-        DPRINT1("Flushing volumes\n");
+        DPRINT1("Flushing volumes, cache flushed %d pages\n", Dummy);
         PopFlushVolumes(PopAction.Shutdown);
 
         /* Set IRP for drivers */