ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

compmisc.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:         ReactOS Composite Battery Driver
00003  * LICENSE:         BSD - See COPYING.ARM in the top level directory
00004  * FILE:            boot/drivers/bus/acpi/compbatt/compmisc.c
00005  * PURPOSE:         Miscellaneous Support Routines
00006  * PROGRAMMERS:     ReactOS Portable Systems Group
00007  */
00008 
00009 /* INCLUDES *******************************************************************/
00010 
00011 #include "compbatt.h"
00012 
00013 /* FUNCTIONS ******************************************************************/
00014 
00015 NTSTATUS
00016 NTAPI
00017 BatteryIoctl(IN ULONG IoControlCode, 
00018              IN PDEVICE_OBJECT DeviceObject,
00019              IN PVOID InputBuffer,
00020              IN ULONG InputBufferLength,
00021              IN PVOID OutputBuffer,
00022              IN ULONG OutputBufferLength,
00023              IN BOOLEAN InternalDeviceIoControl)
00024 {
00025     IO_STATUS_BLOCK IoStatusBlock;
00026     KEVENT Event;
00027     NTSTATUS Status;
00028     PIRP Irp;
00029     PAGED_CODE();
00030     if (CompBattDebug & 0x100) DbgPrint("CompBatt: ENTERING BatteryIoctl\n");
00031 
00032     /* Initialize the event and IRP */
00033     KeInitializeEvent(&Event, SynchronizationEvent, 0);
00034     Irp = IoBuildDeviceIoControlRequest(IoControlCode,
00035                                         DeviceObject,
00036                                         InputBuffer,
00037                                         InputBufferLength,
00038                                         OutputBuffer,
00039                                         OutputBufferLength,
00040                                         InternalDeviceIoControl,
00041                                         &Event,
00042                                         &IoStatusBlock);
00043     if (Irp)
00044     {
00045         /* Call the class driver miniport */
00046         Status = IoCallDriver(DeviceObject, Irp);
00047         if (Status == STATUS_PENDING)
00048         {
00049             /* Wait for result */
00050             KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
00051             Status = IoStatusBlock.Status;
00052         }
00053         
00054         /* Print failure */
00055         if (!(NT_SUCCESS(Status)) && (CompBattDebug & 8))
00056             DbgPrint("BatteryIoctl: Irp failed - %x\n", Status);
00057         
00058         /* Done */
00059         if (CompBattDebug & 0x100) DbgPrint("CompBatt: EXITING BatteryIoctl\n");
00060     }
00061     else
00062     {
00063         /* Out of memory */
00064         if (CompBattDebug & 8) DbgPrint("BatteryIoctl: couldn't create Irp\n");
00065         Status = STATUS_INSUFFICIENT_RESOURCES;
00066     }
00067     
00068     /* Return status */
00069     return Status;
00070 }
00071 
00072 NTSTATUS
00073 NTAPI
00074 CompBattGetDeviceObjectPointer(IN PUNICODE_STRING DeviceName,
00075                                IN ACCESS_MASK DesiredAccess,
00076                                OUT PFILE_OBJECT *FileObject,
00077                                OUT PDEVICE_OBJECT *DeviceObject)
00078 {
00079     NTSTATUS Status;
00080     OBJECT_ATTRIBUTES ObjectAttributes;
00081     IO_STATUS_BLOCK IoStatusBlock;
00082     PFILE_OBJECT LocalFileObject;
00083     HANDLE DeviceHandle;
00084     PAGED_CODE();
00085     
00086     /* Open a file object handle to the device */
00087     InitializeObjectAttributes(&ObjectAttributes, DeviceName, 0, NULL, NULL);
00088     Status = ZwCreateFile(&DeviceHandle,
00089                           DesiredAccess,
00090                           &ObjectAttributes,
00091                           &IoStatusBlock,
00092                           NULL,
00093                           0,
00094                           FILE_SHARE_READ | FILE_SHARE_WRITE,
00095                           FILE_OPEN,
00096                           0,
00097                           NULL,
00098                           0);
00099     if (NT_SUCCESS(Status))
00100     {
00101         /* Reference the file object */
00102         Status = ObReferenceObjectByHandle(DeviceHandle,
00103                                            0,
00104                                            IoFileObjectType,
00105                                            KernelMode,
00106                                            (PVOID)&LocalFileObject,
00107                                            NULL);
00108         if (NT_SUCCESS(Status))
00109         {
00110             /* Return the FO and the associated DO */
00111             *FileObject = LocalFileObject;
00112             *DeviceObject = IoGetRelatedDeviceObject(LocalFileObject);
00113         }
00114       
00115         /* Close the handle */
00116         ZwClose(DeviceHandle);
00117     }
00118     
00119     /* Return status */
00120     return Status;
00121 }
00122 
00123 /* EOF */

Generated on Sat May 26 2012 04:25:59 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.