2 * PROJECT: ReactOS Composite Battery Driver
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: boot/drivers/bus/acpi/compbatt/compmisc.c
5 * PURPOSE: Miscellaneous Support Routines
6 * PROGRAMMERS: ReactOS Portable Systems Group
9 /* INCLUDES *******************************************************************/
13 /* FUNCTIONS ******************************************************************/
17 BatteryIoctl(IN ULONG IoControlCode
,
18 IN PDEVICE_OBJECT DeviceObject
,
20 IN ULONG InputBufferLength
,
21 IN PVOID OutputBuffer
,
22 IN ULONG OutputBufferLength
,
23 IN BOOLEAN InternalDeviceIoControl
)
25 IO_STATUS_BLOCK IoStatusBlock
;
30 if (CompBattDebug
& 0x100) DbgPrint("CompBatt: ENTERING BatteryIoctl\n");
32 /* Initialize the event and IRP */
33 KeInitializeEvent(&Event
, SynchronizationEvent
, 0);
34 Irp
= IoBuildDeviceIoControlRequest(IoControlCode
,
40 InternalDeviceIoControl
,
45 /* Call the class driver miniport */
46 Status
= IofCallDriver(DeviceObject
, Irp
);
47 if (Status
== STATUS_PENDING
)
50 KeWaitForSingleObject(&Event
, Executive
, KernelMode
, FALSE
, NULL
);
51 Status
= IoStatusBlock
.Status
;
55 if (!(NT_SUCCESS(Status
)) && (CompBattDebug
& 8))
56 DbgPrint("BatteryIoctl: Irp failed - %x\n", Status
);
59 if (CompBattDebug
& 0x100) DbgPrint("CompBatt: EXITING BatteryIoctl\n");
64 if (CompBattDebug
& 8) DbgPrint("BatteryIoctl: couldn't create Irp\n");
65 Status
= STATUS_INSUFFICIENT_RESOURCES
;
74 CompBattGetDeviceObjectPointer(IN PUNICODE_STRING DeviceName
,
75 IN ACCESS_MASK DesiredAccess
,
76 OUT PFILE_OBJECT
*FileObject
,
77 OUT PDEVICE_OBJECT
*DeviceObject
)
80 OBJECT_ATTRIBUTES ObjectAttributes
;
81 IO_STATUS_BLOCK IoStatusBlock
;
82 PFILE_OBJECT LocalFileObject
;
86 /* Open a file object handle to the device */
87 InitializeObjectAttributes(&ObjectAttributes
, DeviceName
, 0, NULL
, NULL
);
88 Status
= ZwCreateFile(&DeviceHandle
,
94 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
99 if (NT_SUCCESS(Status
))
101 /* Reference the file object */
102 Status
= ObReferenceObjectByHandle(DeviceHandle
,
106 (PVOID
)&LocalFileObject
,
108 if (NT_SUCCESS(Status
))
110 /* Return the FO and the associated DO */
111 *FileObject
= LocalFileObject
;
112 *DeviceObject
= IoGetRelatedDeviceObject(LocalFileObject
);
115 /* Close the handle */
116 ZwClose(DeviceHandle
);