mirror of
https://github.com/reactos/reactos.git
synced 2024-09-08 11:50:08 +00:00
[COMPBATT]: Helper code, CompBattGetDeviceObjectPointer and BatteryIoctl.
svn path=/trunk/; revision=46541
This commit is contained in:
parent
bf6ce4779e
commit
123bf68a1a
|
@ -132,7 +132,7 @@ CompBattMonitorIrpCompleteWorker(
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
NTAPI
|
NTAPI
|
||||||
CompBattGetDeviceObjectPointer(
|
CompBattGetDeviceObjectPointer(
|
||||||
IN PCUNICODE_STRING DeviceName,
|
IN PUNICODE_STRING DeviceName,
|
||||||
IN ACCESS_MASK DesiredAccess,
|
IN ACCESS_MASK DesiredAccess,
|
||||||
OUT PFILE_OBJECT *FileObject,
|
OUT PFILE_OBJECT *FileObject,
|
||||||
OUT PDEVICE_OBJECT *DeviceObject
|
OUT PDEVICE_OBJECT *DeviceObject
|
||||||
|
|
|
@ -22,19 +22,102 @@ BatteryIoctl(IN ULONG IoControlCode,
|
||||||
IN ULONG OutputBufferLength,
|
IN ULONG OutputBufferLength,
|
||||||
IN BOOLEAN InternalDeviceIoControl)
|
IN BOOLEAN InternalDeviceIoControl)
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED;
|
IO_STATUS_BLOCK IoStatusBlock;
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
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
|
NTSTATUS
|
||||||
NTAPI
|
NTAPI
|
||||||
CompBattGetDeviceObjectPointer(IN PCUNICODE_STRING DeviceName,
|
CompBattGetDeviceObjectPointer(IN PUNICODE_STRING DeviceName,
|
||||||
IN ACCESS_MASK DesiredAccess,
|
IN ACCESS_MASK DesiredAccess,
|
||||||
OUT PFILE_OBJECT *FileObject,
|
OUT PFILE_OBJECT *FileObject,
|
||||||
OUT PDEVICE_OBJECT *DeviceObject)
|
OUT PDEVICE_OBJECT *DeviceObject)
|
||||||
{
|
{
|
||||||
UNIMPLEMENTED;
|
NTSTATUS Status;
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
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 */
|
/* EOF */
|
||||||
|
|
|
@ -102,7 +102,7 @@ IsBatteryAlreadyOnList(IN PCUNICODE_STRING BatteryName,
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
NTAPI
|
NTAPI
|
||||||
CompBattAddNewBattery(IN PCUNICODE_STRING BatteryName,
|
CompBattAddNewBattery(IN PUNICODE_STRING BatteryName,
|
||||||
IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
|
IN PCOMPBATT_DEVICE_EXTENSION DeviceExtension)
|
||||||
{
|
{
|
||||||
NTSTATUS Status = STATUS_SUCCESS;
|
NTSTATUS Status = STATUS_SUCCESS;
|
||||||
|
|
Loading…
Reference in a new issue