Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygendevcntrl.c
Go to the documentation of this file.
00001 /************************************************************************* 00002 * 00003 * File: devcntrl.c 00004 * 00005 * Module: Ext2 File System Driver (Kernel mode execution only) 00006 * 00007 * Description: 00008 * Contains code to handle the "Device IOCTL" dispatch entry point. 00009 * 00010 * Author: Manoj Paul Joseph 00011 * 00012 * 00013 *************************************************************************/ 00014 00015 #include "ext2fsd.h" 00016 00017 // define the file specific bug-check id 00018 #define EXT2_BUG_CHECK_ID EXT2_FILE_DEVICE_CONTROL 00019 #define DEBUG_LEVEL DEBUG_TRACE_DEVCTRL 00020 00021 00022 #if(_WIN32_WINNT < 0x0400) 00023 #define IOCTL_REDIR_QUERY_PATH CTL_CODE(FILE_DEVICE_NETWORK_FILE_SYSTEM, 99, METHOD_NEITHER, FILE_ANY_ACCESS) 00024 00025 typedef struct _QUERY_PATH_REQUEST 00026 { 00027 ULONG PathNameLength; 00028 PIO_SECURITY_CONTEXT SecurityContext; 00029 WCHAR FilePathName[1]; 00030 } QUERY_PATH_REQUEST, *PQUERY_PATH_REQUEST; 00031 00032 typedef struct _QUERY_PATH_RESPONSE 00033 { 00034 ULONG LengthAccepted; 00035 } QUERY_PATH_RESPONSE, *PQUERY_PATH_RESPONSE; 00036 #endif 00037 00038 00039 /************************************************************************* 00040 * 00041 * Function: Ext2DeviceControl() 00042 * 00043 * Description: 00044 * The I/O Manager will invoke this routine to handle a Device IOCTL 00045 * request 00046 * 00047 * Expected Interrupt Level (for execution) : 00048 * 00049 * IRQL_PASSIVE_LEVEL (invocation at higher IRQL will cause execution 00050 * to be deferred to a worker thread context) 00051 * 00052 * Return Value: STATUS_SUCCESS/Error 00053 * 00054 *************************************************************************/ 00055 NTSTATUS NTAPI Ext2DeviceControl( 00056 PDEVICE_OBJECT DeviceObject, // the logical volume device object 00057 PIRP Irp) // I/O Request Packet 00058 { 00059 NTSTATUS RC = STATUS_SUCCESS; 00060 PtrExt2IrpContext PtrIrpContext = NULL; 00061 BOOLEAN AreWeTopLevel = FALSE; 00062 00063 // Ext2BreakPoint(); 00064 00065 DebugTrace(DEBUG_TRACE_IRP_ENTRY, "Device Control IRP Received...", 0); 00066 00067 FsRtlEnterFileSystem(); 00068 ASSERT(DeviceObject); 00069 ASSERT(Irp); 00070 00071 // set the top level context 00072 AreWeTopLevel = Ext2IsIrpTopLevel(Irp); 00073 00074 try { 00075 00076 // get an IRP context structure and issue the request 00077 PtrIrpContext = Ext2AllocateIrpContext(Irp, DeviceObject); 00078 ASSERT(PtrIrpContext); 00079 00080 RC = Ext2CommonDeviceControl(PtrIrpContext, Irp); 00081 00082 } except (Ext2ExceptionFilter(PtrIrpContext, GetExceptionInformation())) { 00083 00084 RC = Ext2ExceptionHandler(PtrIrpContext, Irp); 00085 00086 Ext2LogEvent(EXT2_ERROR_INTERNAL_ERROR, RC); 00087 } 00088 00089 if (AreWeTopLevel) { 00090 IoSetTopLevelIrp(NULL); 00091 } 00092 00093 FsRtlExitFileSystem(); 00094 00095 return(RC); 00096 } 00097 00098 00099 /************************************************************************* 00100 * 00101 * Function: Ext2CommonDeviceControl() 00102 * 00103 * Description: 00104 * The actual work is performed here. This routine may be invoked in one' 00105 * of the two possible contexts: 00106 * (a) in the context of a system worker thread 00107 * (b) in the context of the original caller 00108 * 00109 * Expected Interrupt Level (for execution) : 00110 * 00111 * IRQL_PASSIVE_LEVEL 00112 * 00113 * Return Value: STATUS_SUCCESS/Error 00114 * 00115 *************************************************************************/ 00116 NTSTATUS NTAPI Ext2CommonDeviceControl( 00117 PtrExt2IrpContext PtrIrpContext, 00118 PIRP PtrIrp) 00119 { 00120 NTSTATUS RC = STATUS_SUCCESS; 00121 PIO_STACK_LOCATION PtrIoStackLocation = NULL; 00122 PIO_STACK_LOCATION PtrNextIoStackLocation = NULL; 00123 PFILE_OBJECT PtrFileObject = NULL; 00124 PtrExt2FCB PtrFCB = NULL; 00125 PtrExt2CCB PtrCCB = NULL; 00126 PtrExt2VCB PtrVCB = NULL; 00127 ULONG IoControlCode = 0; 00128 00129 try 00130 { 00131 // First, get a pointer to the current I/O stack location 00132 PtrIoStackLocation = IoGetCurrentIrpStackLocation(PtrIrp); 00133 ASSERT(PtrIoStackLocation); 00134 00135 PtrFileObject = PtrIoStackLocation->FileObject; 00136 ASSERT(PtrFileObject); 00137 00138 PtrCCB = (PtrExt2CCB)(PtrFileObject->FsContext2); 00139 ASSERT(PtrCCB); 00140 PtrFCB = PtrCCB->PtrFCB; 00141 ASSERT(PtrFCB); 00142 00143 00144 if( PtrFCB->NodeIdentifier.NodeType == EXT2_NODE_TYPE_VCB ) 00145 { 00146 PtrVCB = (PtrExt2VCB)(PtrFCB); 00147 } 00148 else 00149 { 00150 AssertFCB( PtrFCB ); 00151 ASSERT(PtrFCB->NodeIdentifier.NodeType == EXT2_NODE_TYPE_FCB); 00152 PtrVCB = PtrFCB->PtrVCB; 00153 } 00154 00155 // Get the IoControlCode value 00156 IoControlCode = PtrIoStackLocation->Parameters.DeviceIoControl.IoControlCode; 00157 00158 // You may wish to allow only volume open operations. 00159 00160 // Invoke the lower level driver in the chain. 00161 PtrNextIoStackLocation = IoGetNextIrpStackLocation(PtrIrp); 00162 *PtrNextIoStackLocation = *PtrIoStackLocation; 00163 // Set a completion routine. 00164 IoSetCompletionRoutine(PtrIrp, Ext2DevIoctlCompletion, NULL, TRUE, TRUE, TRUE); 00165 // Send the request. 00166 RC = IoCallDriver(PtrVCB->TargetDeviceObject, PtrIrp); 00167 } 00168 finally 00169 { 00170 // Release the IRP context 00171 if (!(PtrIrpContext->IrpContextFlags & EXT2_IRP_CONTEXT_EXCEPTION)) 00172 { 00173 // Free up the Irp Context 00174 Ext2ReleaseIrpContext(PtrIrpContext); 00175 } 00176 } 00177 00178 return(RC); 00179 } 00180 00181 00182 /************************************************************************* 00183 * 00184 * Function: Ext2DevIoctlCompletion() 00185 * 00186 * Description: 00187 * Completion routine. 00188 * 00189 * Expected Interrupt Level (for execution) : 00190 * 00191 * IRQL_PASSIVE_LEVEL 00192 * 00193 * Return Value: STATUS_SUCCESS 00194 * 00195 *************************************************************************/ 00196 NTSTATUS NTAPI Ext2DevIoctlCompletion( 00197 PDEVICE_OBJECT PtrDeviceObject, 00198 PIRP PtrIrp, 00199 void *Context) 00200 { 00201 if (PtrIrp->PendingReturned) { 00202 IoMarkIrpPending(PtrIrp); 00203 } 00204 00205 return(STATUS_SUCCESS); 00206 } Generated on Sun May 27 2012 04:27:38 for ReactOS by
1.7.6.1
|