1 /*************************************************************************
5 * Module: Ext2 File System Driver (Kernel mode execution only)
8 * Contains code to handle the "Device IOCTL" dispatch entry point.
10 * Author: Manoj Paul Joseph
13 *************************************************************************/
17 // define the file specific bug-check id
18 #define EXT2_BUG_CHECK_ID EXT2_FILE_DEVICE_CONTROL
19 #define DEBUG_LEVEL DEBUG_TRACE_DEVCTRL
22 #if(_WIN32_WINNT < 0x0400)
23 #define IOCTL_REDIR_QUERY_PATH CTL_CODE(FILE_DEVICE_NETWORK_FILE_SYSTEM, 99, METHOD_NEITHER, FILE_ANY_ACCESS)
25 typedef struct _QUERY_PATH_REQUEST
28 PIO_SECURITY_CONTEXT SecurityContext
;
29 WCHAR FilePathName
[1];
30 } QUERY_PATH_REQUEST
, *PQUERY_PATH_REQUEST
;
32 typedef struct _QUERY_PATH_RESPONSE
35 } QUERY_PATH_RESPONSE
, *PQUERY_PATH_RESPONSE
;
39 /*************************************************************************
41 * Function: Ext2DeviceControl()
44 * The I/O Manager will invoke this routine to handle a Device IOCTL
47 * Expected Interrupt Level (for execution) :
49 * IRQL_PASSIVE_LEVEL (invocation at higher IRQL will cause execution
50 * to be deferred to a worker thread context)
52 * Return Value: STATUS_SUCCESS/Error
54 *************************************************************************/
55 NTSTATUS NTAPI
Ext2DeviceControl(
56 PDEVICE_OBJECT DeviceObject
, // the logical volume device object
57 PIRP Irp
) // I/O Request Packet
59 NTSTATUS RC
= STATUS_SUCCESS
;
60 PtrExt2IrpContext PtrIrpContext
= NULL
;
61 BOOLEAN AreWeTopLevel
= FALSE
;
65 DebugTrace(DEBUG_TRACE_IRP_ENTRY
, "Device Control IRP Received...", 0);
67 FsRtlEnterFileSystem();
71 // set the top level context
72 AreWeTopLevel
= Ext2IsIrpTopLevel(Irp
);
76 // get an IRP context structure and issue the request
77 PtrIrpContext
= Ext2AllocateIrpContext(Irp
, DeviceObject
);
78 ASSERT(PtrIrpContext
);
80 RC
= Ext2CommonDeviceControl(PtrIrpContext
, Irp
);
82 } except (Ext2ExceptionFilter(PtrIrpContext
, GetExceptionInformation())) {
84 RC
= Ext2ExceptionHandler(PtrIrpContext
, Irp
);
86 Ext2LogEvent(EXT2_ERROR_INTERNAL_ERROR
, RC
);
90 IoSetTopLevelIrp(NULL
);
93 FsRtlExitFileSystem();
99 /*************************************************************************
101 * Function: Ext2CommonDeviceControl()
104 * The actual work is performed here. This routine may be invoked in one'
105 * of the two possible contexts:
106 * (a) in the context of a system worker thread
107 * (b) in the context of the original caller
109 * Expected Interrupt Level (for execution) :
113 * Return Value: STATUS_SUCCESS/Error
115 *************************************************************************/
116 NTSTATUS NTAPI
Ext2CommonDeviceControl(
117 PtrExt2IrpContext PtrIrpContext
,
120 NTSTATUS RC
= STATUS_SUCCESS
;
121 PIO_STACK_LOCATION PtrIoStackLocation
= NULL
;
122 PIO_STACK_LOCATION PtrNextIoStackLocation
= NULL
;
123 PFILE_OBJECT PtrFileObject
= NULL
;
124 PtrExt2FCB PtrFCB
= NULL
;
125 PtrExt2CCB PtrCCB
= NULL
;
126 PtrExt2VCB PtrVCB
= NULL
;
127 ULONG IoControlCode
= 0;
131 // First, get a pointer to the current I/O stack location
132 PtrIoStackLocation
= IoGetCurrentIrpStackLocation(PtrIrp
);
133 ASSERT(PtrIoStackLocation
);
135 PtrFileObject
= PtrIoStackLocation
->FileObject
;
136 ASSERT(PtrFileObject
);
138 PtrCCB
= (PtrExt2CCB
)(PtrFileObject
->FsContext2
);
140 PtrFCB
= PtrCCB
->PtrFCB
;
144 if( PtrFCB
->NodeIdentifier
.NodeType
== EXT2_NODE_TYPE_VCB
)
146 PtrVCB
= (PtrExt2VCB
)(PtrFCB
);
151 ASSERT(PtrFCB
->NodeIdentifier
.NodeType
== EXT2_NODE_TYPE_FCB
);
152 PtrVCB
= PtrFCB
->PtrVCB
;
155 // Get the IoControlCode value
156 IoControlCode
= PtrIoStackLocation
->Parameters
.DeviceIoControl
.IoControlCode
;
158 // You may wish to allow only volume open operations.
160 // Invoke the lower level driver in the chain.
161 PtrNextIoStackLocation
= IoGetNextIrpStackLocation(PtrIrp
);
162 *PtrNextIoStackLocation
= *PtrIoStackLocation
;
163 // Set a completion routine.
164 IoSetCompletionRoutine(PtrIrp
, Ext2DevIoctlCompletion
, NULL
, TRUE
, TRUE
, TRUE
);
166 RC
= IoCallDriver(PtrVCB
->TargetDeviceObject
, PtrIrp
);
170 // Release the IRP context
171 if (!(PtrIrpContext
->IrpContextFlags
& EXT2_IRP_CONTEXT_EXCEPTION
))
173 // Free up the Irp Context
174 Ext2ReleaseIrpContext(PtrIrpContext
);
182 /*************************************************************************
184 * Function: Ext2DevIoctlCompletion()
187 * Completion routine.
189 * Expected Interrupt Level (for execution) :
193 * Return Value: STATUS_SUCCESS
195 *************************************************************************/
196 NTSTATUS NTAPI
Ext2DevIoctlCompletion(
197 PDEVICE_OBJECT PtrDeviceObject
,
201 if (PtrIrp
->PendingReturned
) {
202 IoMarkIrpPending(PtrIrp
);
205 return(STATUS_SUCCESS
);