Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygencontroller.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Kernel 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: ntoskrnl/io/controller.c 00005 * PURPOSE: I/O Wrappers (called Controllers) for Kernel Device Queues 00006 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org) 00007 */ 00008 00009 /* INCLUDES *****************************************************************/ 00010 00011 #include <ntoskrnl.h> 00012 #include <debug.h> 00013 00014 /* GLOBALS *******************************************************************/ 00015 00016 POBJECT_TYPE IoControllerObjectType; 00017 00018 /* FUNCTIONS *****************************************************************/ 00019 00020 /* 00021 * @implemented 00022 */ 00023 VOID 00024 NTAPI 00025 IoAllocateController(IN PCONTROLLER_OBJECT ControllerObject, 00026 IN PDEVICE_OBJECT DeviceObject, 00027 IN PDRIVER_CONTROL ExecutionRoutine, 00028 IN PVOID Context) 00029 { 00030 IO_ALLOCATION_ACTION Result; 00031 ASSERT_IRQL_EQUAL(DISPATCH_LEVEL); 00032 00033 /* Initialize the Wait Context Block */ 00034 DeviceObject->Queue.Wcb.DeviceContext = Context; 00035 DeviceObject->Queue.Wcb.DeviceRoutine = ExecutionRoutine; 00036 00037 /* Insert the Device Queue */ 00038 if (!KeInsertDeviceQueue(&ControllerObject->DeviceWaitQueue, 00039 &DeviceObject->Queue.Wcb.WaitQueueEntry)) 00040 { 00041 /* Call the execution routine */ 00042 Result = ExecutionRoutine(DeviceObject, 00043 DeviceObject->CurrentIrp, 00044 NULL, 00045 Context); 00046 00047 /* Free the controller if this was requested */ 00048 if (Result == DeallocateObject) IoFreeController(ControllerObject); 00049 } 00050 } 00051 00052 /* 00053 * @implemented 00054 */ 00055 PCONTROLLER_OBJECT 00056 NTAPI 00057 IoCreateController(IN ULONG Size) 00058 { 00059 PCONTROLLER_OBJECT Controller; 00060 OBJECT_ATTRIBUTES ObjectAttributes; 00061 HANDLE Handle; 00062 NTSTATUS Status; 00063 PAGED_CODE(); 00064 00065 /* Initialize an empty OBA */ 00066 InitializeObjectAttributes(&ObjectAttributes, 00067 NULL, 00068 OBJ_KERNEL_HANDLE, 00069 NULL, 00070 NULL); 00071 00072 /* Create the Object */ 00073 Status = ObCreateObject(KernelMode, 00074 IoControllerObjectType, 00075 &ObjectAttributes, 00076 KernelMode, 00077 NULL, 00078 sizeof(CONTROLLER_OBJECT) + Size, 00079 0, 00080 0, 00081 (PVOID*)&Controller); 00082 if (!NT_SUCCESS(Status)) return NULL; 00083 00084 /* Insert it */ 00085 Status = ObInsertObject(Controller, 00086 NULL, 00087 FILE_READ_DATA | FILE_WRITE_DATA, 00088 1, 00089 (PVOID*)&Controller, 00090 &Handle); 00091 if (!NT_SUCCESS(Status)) return NULL; 00092 00093 /* Close the dummy handle */ 00094 ObCloseHandle(Handle, KernelMode); 00095 00096 /* Zero the Object and set its data */ 00097 RtlZeroMemory(Controller, sizeof(CONTROLLER_OBJECT) + Size); 00098 Controller->Type = IO_TYPE_CONTROLLER; 00099 Controller->Size = sizeof(CONTROLLER_OBJECT) + (CSHORT)Size; 00100 Controller->ControllerExtension = (Controller + 1); 00101 00102 /* Initialize its Queue */ 00103 KeInitializeDeviceQueue(&Controller->DeviceWaitQueue); 00104 00105 /* Return Controller */ 00106 return Controller; 00107 } 00108 00109 /* 00110 * @implemented 00111 */ 00112 VOID 00113 NTAPI 00114 IoDeleteController(IN PCONTROLLER_OBJECT ControllerObject) 00115 { 00116 /* Just Dereference it */ 00117 ObDereferenceObject(ControllerObject); 00118 } 00119 00120 /* 00121 * @implemented 00122 */ 00123 VOID 00124 NTAPI 00125 IoFreeController(IN PCONTROLLER_OBJECT ControllerObject) 00126 { 00127 PKDEVICE_QUEUE_ENTRY QueueEntry; 00128 PDEVICE_OBJECT DeviceObject; 00129 IO_ALLOCATION_ACTION Result; 00130 00131 /* Remove the Queue */ 00132 QueueEntry = KeRemoveDeviceQueue(&ControllerObject->DeviceWaitQueue); 00133 if (QueueEntry) 00134 { 00135 /* Get the Device Object */ 00136 DeviceObject = CONTAINING_RECORD(QueueEntry, 00137 DEVICE_OBJECT, 00138 Queue.Wcb.WaitQueueEntry); 00139 00140 /* Call the routine */ 00141 Result = DeviceObject->Queue.Wcb.DeviceRoutine(DeviceObject, 00142 DeviceObject->CurrentIrp, 00143 NULL, 00144 DeviceObject-> 00145 Queue.Wcb.DeviceContext); 00146 /* Free the controller if this was requested */ 00147 if (Result == DeallocateObject) IoFreeController(ControllerObject); 00148 } 00149 } 00150 00151 /* EOF */ Generated on Fri May 25 2012 04:35:45 for ReactOS by
1.7.6.1
|