ReactOS  0.4.15-dev-2956-g61e7ea5
compmisc.c
Go to the documentation of this file.
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 
16 NTAPI
24 {
26  KEVENT Event;
28  PIRP Irp;
29  PAGED_CODE();
30  if (CompBattDebug & 0x100) DbgPrint("CompBatt: ENTERING BatteryIoctl\n");
31 
32  /* Initialize the event and IRP */
41  &Event,
42  &IoStatusBlock);
43  if (Irp)
44  {
45  /* Call the class driver miniport */
47  if (Status == STATUS_PENDING)
48  {
49  /* Wait for result */
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");
66  }
67 
68  /* Return status */
69  return Status;
70 }
71 
73 NTAPI
78 {
82  PFILE_OBJECT LocalFileObject;
84  PAGED_CODE();
85 
86  /* Open a file object handle to the device */
88  DeviceName,
90  NULL,
91  NULL);
92  Status = ZwCreateFile(&DeviceHandle,
96  NULL,
97  0,
99  FILE_OPEN,
100  0,
101  NULL,
102  0);
103  if (NT_SUCCESS(Status))
104  {
105  /* Reference the file object */
107  0,
109  KernelMode,
110  (PVOID)&LocalFileObject,
111  NULL);
112  if (NT_SUCCESS(Status))
113  {
114  /* Return the FO and the associated DO */
115  *FileObject = LocalFileObject;
116  *DeviceObject = IoGetRelatedDeviceObject(LocalFileObject);
117  }
118 
119  /* Close the handle */
121  }
122 
123  /* Return status */
124  return Status;
125 }
126 
127 /* EOF */
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define IN
Definition: typedefs.h:39
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2654
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
#define DbgPrint
Definition: loader.c:25
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID _In_ ULONG _In_ BOOLEAN InternalDeviceIoControl
Definition: iofuncs.h:715
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
_In_ WDFREQUEST _In_ size_t _In_ size_t InputBufferLength
Definition: wdfio.h:318
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
NTSTATUS NTAPI CompBattGetDeviceObjectPointer(IN PUNICODE_STRING DeviceName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
Definition: compmisc.c:74
#define FILE_SHARE_READ
Definition: compat.h:136
_In_ WDFREQUEST _In_ size_t OutputBufferLength
Definition: wdfio.h:318
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3272
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:494
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:467
unsigned char BOOLEAN
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR OutputBuffer
Definition: wdfiotarget.h:859
Status
Definition: gdiplustypes.h:24
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:949
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
* PFILE_OBJECT
Definition: iotypes.h:1998
_In_ WDFREQUEST _In_ size_t _In_ size_t _In_ ULONG IoControlCode
Definition: wdfio.h:318
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
#define FILE_OPEN
Definition: from_kernel.h:54
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
NTSTATUS NTAPI BatteryIoctl(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl)
Definition: compmisc.c:17
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
#define OUT
Definition: typedefs.h:40
unsigned int ULONG
Definition: retypes.h:1
ULONG CompBattDebug
Definition: compbatt.c:17
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define PAGED_CODE()