[ros-diffs] [sir_richard] 46334: [CMBATT]: CmBattIoctl: Batteries are very hot-pluggable, so we need to do all the work under our remove lock. Add the logic for it. [CMBATT]: CmBattIoctl: If the request was for the AC adapter, pass it down to ACPI.

sir_richard at svn.reactos.org sir_richard at svn.reactos.org
Mon Mar 22 02:56:20 CET 2010


Author: sir_richard
Date: Mon Mar 22 02:56:20 2010
New Revision: 46334

URL: http://svn.reactos.org/svn/reactos?rev=46334&view=rev
Log:
[CMBATT]: CmBattIoctl: Batteries are very hot-pluggable, so we need to do all the work under our remove lock. Add the logic for it.
[CMBATT]: CmBattIoctl: If the request was for the AC adapter, pass it down to ACPI.

Modified:
    trunk/reactos/drivers/bus/acpi/cmbatt/cmbatt.c

Modified: trunk/reactos/drivers/bus/acpi/cmbatt/cmbatt.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/bus/acpi/cmbatt/cmbatt.c?rev=46334&r1=46333&r2=46334&view=diff
==============================================================================
--- trunk/reactos/drivers/bus/acpi/cmbatt/cmbatt.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/bus/acpi/cmbatt/cmbatt.c [iso-8859-1] Mon Mar 22 02:56:20 2010
@@ -348,23 +348,47 @@
 
 NTSTATUS
 NTAPI
-CmBattIoctl(PDEVICE_OBJECT DeviceObject,
-            PIRP Irp)
+CmBattIoctl(IN PDEVICE_OBJECT DeviceObject,
+            IN PIRP Irp)
 {
     PCMBATT_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
     NTSTATUS Status;
-
-    Status = BatteryClassIoctl(DeviceExtension->ClassData,
-                               Irp);
-
+    PAGED_CODE();
+    if (CmBattDebug & 2) DbgPrint("CmBattIoctl\n");
+
+    /* Acquire the remove lock */
+    Status = IoAcquireRemoveLock(&DeviceExtension->RemoveLock, 0);
+    if (!NT_SUCCESS(Status))
+    {
+        /* It's too late, fail */
+        Irp->IoStatus.Status = STATUS_DEVICE_REMOVED;
+        IofCompleteRequest(Irp, IO_NO_INCREMENT);
+        return STATUS_DEVICE_REMOVED;
+    }
+    
+    /* There's nothing to do for an AC adapter */
+    if (DeviceExtension->FdoType == CmBattAcAdapter)
+    {
+        /* Pass it down, and release the remove lock */
+        IoSkipCurrentIrpStackLocation(Irp);
+        Status = IoCallDriver(DeviceExtension->AttachedDevice, Irp);
+        IoReleaseRemoveLock(&DeviceExtension->RemoveLock, Irp);
+        return Status;
+    }
+    
+    /* Send to class driver */
+    Status = BatteryClassIoctl(DeviceExtension->ClassData, Irp);
     if (Status == STATUS_NOT_SUPPORTED)
     {
+        /* FIXME: Should handle custom codes here */
         Irp->IoStatus.Status = Status;
         Irp->IoStatus.Information = 0;
 
         IoCompleteRequest(Irp, IO_NO_INCREMENT);
     }
 
+    /* Release the remove lock and return status */
+    IoReleaseRemoveLock(&DeviceExtension->RemoveLock, Irp);
     return Status;
 }
 




More information about the Ros-diffs mailing list