Author: sir_richard
Date: Mon Mar 29 02:10:56 2010
New Revision: 46541
URL:
http://svn.reactos.org/svn/reactos?rev=46541&view=rev
Log:
[COMPBATT]: Helper code, CompBattGetDeviceObjectPointer and BatteryIoctl.
Modified:
trunk/reactos/drivers/bus/acpi/compbatt/compbatt.h
trunk/reactos/drivers/bus/acpi/compbatt/compmisc.c
trunk/reactos/drivers/bus/acpi/compbatt/comppnp.c
Modified: trunk/reactos/drivers/bus/acpi/compbatt/compbatt.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/bus/acpi/compbatt/…
==============================================================================
--- trunk/reactos/drivers/bus/acpi/compbatt/compbatt.h [iso-8859-1] (original)
+++ trunk/reactos/drivers/bus/acpi/compbatt/compbatt.h [iso-8859-1] Mon Mar 29 02:10:56
2010
@@ -132,7 +132,7 @@
NTSTATUS
NTAPI
CompBattGetDeviceObjectPointer(
- IN PCUNICODE_STRING DeviceName,
+ IN PUNICODE_STRING DeviceName,
IN ACCESS_MASK DesiredAccess,
OUT PFILE_OBJECT *FileObject,
OUT PDEVICE_OBJECT *DeviceObject
Modified: trunk/reactos/drivers/bus/acpi/compbatt/compmisc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/bus/acpi/compbatt/…
==============================================================================
--- trunk/reactos/drivers/bus/acpi/compbatt/compmisc.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/bus/acpi/compbatt/compmisc.c [iso-8859-1] Mon Mar 29 02:10:56
2010
@@ -22,19 +22,102 @@
IN ULONG OutputBufferLength,
IN BOOLEAN InternalDeviceIoControl)
{
- UNIMPLEMENTED;
- return STATUS_NOT_IMPLEMENTED;
+ IO_STATUS_BLOCK IoStatusBlock;
+ KEVENT Event;
+ NTSTATUS Status;
+ PIRP Irp;
+ PAGED_CODE();
+ if (CompBattDebug & 0x100) DbgPrint("CompBatt: ENTERING
BatteryIoctl\n");
+
+ /* Initialize the event and IRP */
+ KeInitializeEvent(&Event, SynchronizationEvent, 0);
+ Irp = IoBuildDeviceIoControlRequest(IoControlCode,
+ DeviceObject,
+ InputBuffer,
+ InputBufferLength,
+ OutputBuffer,
+ OutputBufferLength,
+ InternalDeviceIoControl,
+ &Event,
+ &IoStatusBlock);
+ if (Irp)
+ {
+ /* Call the class driver miniport */
+ Status = IofCallDriver(DeviceObject, Irp);
+ if (Status == STATUS_PENDING)
+ {
+ /* Wait for result */
+ KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
+ Status = IoStatusBlock.Status;
+ }
+
+ /* Print failure */
+ if (!(NT_SUCCESS(Status)) && (CompBattDebug & 8))
+ DbgPrint("BatteryIoctl: Irp failed - %x\n", Status);
+
+ /* Done */
+ if (CompBattDebug & 0x100) DbgPrint("CompBatt: EXITING
BatteryIoctl\n");
+ }
+ else
+ {
+ /* Out of memory */
+ if (CompBattDebug & 8) DbgPrint("BatteryIoctl: couldn't create
Irp\n");
+ Status = STATUS_INSUFFICIENT_RESOURCES;
+ }
+
+ /* Return status */
+ return Status;
}
NTSTATUS
NTAPI
-CompBattGetDeviceObjectPointer(IN PCUNICODE_STRING DeviceName,
+CompBattGetDeviceObjectPointer(IN PUNICODE_STRING DeviceName,
IN ACCESS_MASK DesiredAccess,
OUT PFILE_OBJECT *FileObject,
OUT PDEVICE_OBJECT *DeviceObject)
{
- UNIMPLEMENTED;
- return STATUS_NOT_IMPLEMENTED;
+ NTSTATUS Status;
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ IO_STATUS_BLOCK IoStatusBlock;
+ PFILE_OBJECT LocalFileObject;
+ HANDLE DeviceHandle;
+ PAGED_CODE();
+
+ /* Open a file object handle to the device */
+ InitializeObjectAttributes(&ObjectAttributes, DeviceName, 0, NULL, NULL);
+ Status = ZwCreateFile(&DeviceHandle,
+ DesiredAccess,
+ &ObjectAttributes,
+ &IoStatusBlock,
+ NULL,
+ 0,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ FILE_OPEN,
+ 0,
+ NULL,
+ 0);
+ if (NT_SUCCESS(Status))
+ {
+ /* Reference the file object */
+ Status = ObReferenceObjectByHandle(DeviceHandle,
+ 0,
+ IoFileObjectType,
+ KernelMode,
+ (PVOID)&LocalFileObject,
+ NULL);
+ if (NT_SUCCESS(Status))
+ {
+ /* Return the FO and the associated DO */
+ *FileObject = LocalFileObject;
+ *DeviceObject = IoGetRelatedDeviceObject(LocalFileObject);
+ }
+
+ /* Close the handle */
+ ZwClose(DeviceHandle);
+ }
+
+ /* Return status */
+ return Status;
}
/* EOF */
Modified: trunk/reactos/drivers/bus/acpi/compbatt/comppnp.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/bus/acpi/compbatt/…
==============================================================================
--- trunk/reactos/drivers/bus/acpi/compbatt/comppnp.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/bus/acpi/compbatt/comppnp.c [iso-8859-1] Mon Mar 29 02:10:56
2010
@@ -102,7 +102,7 @@
NTSTATUS
NTAPI
-CompBattAddNewBattery(IN PCUNICODE_STRING BatteryName,
+CompBattAddNewBattery(IN PUNICODE_STRING BatteryName,
IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
{
NTSTATUS Status = STATUS_SUCCESS;