* Bring back rbuild build to be used until bug 6372 is fixed.
[reactos.git] / drivers / bus / acpi / compbatt / compmisc.c
1 /*
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
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #include "compbatt.h"
12
13 /* FUNCTIONS ******************************************************************/
14
15 NTSTATUS
16 NTAPI
17 BatteryIoctl(IN ULONG IoControlCode,
18 IN PDEVICE_OBJECT DeviceObject,
19 IN PVOID InputBuffer,
20 IN ULONG InputBufferLength,
21 IN PVOID OutputBuffer,
22 IN ULONG OutputBufferLength,
23 IN BOOLEAN InternalDeviceIoControl)
24 {
25 IO_STATUS_BLOCK IoStatusBlock;
26 KEVENT Event;
27 NTSTATUS Status;
28 PIRP Irp;
29 PAGED_CODE();
30 if (CompBattDebug & 0x100) DbgPrint("CompBatt: ENTERING BatteryIoctl\n");
31
32 /* Initialize the event and IRP */
33 KeInitializeEvent(&Event, SynchronizationEvent, 0);
34 Irp = IoBuildDeviceIoControlRequest(IoControlCode,
35 DeviceObject,
36 InputBuffer,
37 InputBufferLength,
38 OutputBuffer,
39 OutputBufferLength,
40 InternalDeviceIoControl,
41 &Event,
42 &IoStatusBlock);
43 if (Irp)
44 {
45 /* Call the class driver miniport */
46 Status = IofCallDriver(DeviceObject, Irp);
47 if (Status == STATUS_PENDING)
48 {
49 /* Wait for result */
50 KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
51 Status = IoStatusBlock.Status;
52 }
53
54 /* Print failure */
55 if (!(NT_SUCCESS(Status)) && (CompBattDebug & 8))
56 DbgPrint("BatteryIoctl: Irp failed - %x\n", Status);
57
58 /* Done */
59 if (CompBattDebug & 0x100) DbgPrint("CompBatt: EXITING BatteryIoctl\n");
60 }
61 else
62 {
63 /* Out of memory */
64 if (CompBattDebug & 8) DbgPrint("BatteryIoctl: couldn't create Irp\n");
65 Status = STATUS_INSUFFICIENT_RESOURCES;
66 }
67
68 /* Return status */
69 return Status;
70 }
71
72 NTSTATUS
73 NTAPI
74 CompBattGetDeviceObjectPointer(IN PUNICODE_STRING DeviceName,
75 IN ACCESS_MASK DesiredAccess,
76 OUT PFILE_OBJECT *FileObject,
77 OUT PDEVICE_OBJECT *DeviceObject)
78 {
79 NTSTATUS Status;
80 OBJECT_ATTRIBUTES ObjectAttributes;
81 IO_STATUS_BLOCK IoStatusBlock;
82 PFILE_OBJECT LocalFileObject;
83 HANDLE DeviceHandle;
84 PAGED_CODE();
85
86 /* Open a file object handle to the device */
87 InitializeObjectAttributes(&ObjectAttributes, DeviceName, 0, NULL, NULL);
88 Status = ZwCreateFile(&DeviceHandle,
89 DesiredAccess,
90 &ObjectAttributes,
91 &IoStatusBlock,
92 NULL,
93 0,
94 FILE_SHARE_READ | FILE_SHARE_WRITE,
95 FILE_OPEN,
96 0,
97 NULL,
98 0);
99 if (NT_SUCCESS(Status))
100 {
101 /* Reference the file object */
102 Status = ObReferenceObjectByHandle(DeviceHandle,
103 0,
104 IoFileObjectType,
105 KernelMode,
106 (PVOID)&LocalFileObject,
107 NULL);
108 if (NT_SUCCESS(Status))
109 {
110 /* Return the FO and the associated DO */
111 *FileObject = LocalFileObject;
112 *DeviceObject = IoGetRelatedDeviceObject(LocalFileObject);
113 }
114
115 /* Close the handle */
116 ZwClose(DeviceHandle);
117 }
118
119 /* Return status */
120 return Status;
121 }
122
123 /* EOF */