📄 cdooperations.c
字号:
//
// The CDO is already open - fail this open
//
status = STATUS_DEVICE_ALREADY_ATTACHED;
DebugTrace( DEBUG_TRACE_CDO_SUPPORTED_OPERATIONS | DEBUG_TRACE_ERROR,
("[Cdo]: CdoHandlePrivateOpen -> Device open failure. Device already opened. ( Irp = %p, Flags = 0x%x, status = 0x%x )\n",
Irp,
Globals.Flags,
status) );
} else {
//
// Flag that the CDO is opened so that we will fail future creates
// until the CDO is closed by the current caller
//
//
// If we suceed the create we are guaranteed to get a Cleanup (where we
// will reset GLOBAL_DATA_F_CDO_OPEN_HANDLE) and Close (where we will
// reset GLOBAL_DATA_F_CDO_OPEN_REF)
//
SetFlag( Globals.Flags, GLOBAL_DATA_F_CDO_OPEN_REF );
SetFlag( Globals.Flags, GLOBAL_DATA_F_CDO_OPEN_HANDLE );
status = STATUS_SUCCESS;
DebugTrace( DEBUG_TRACE_CDO_SUPPORTED_OPERATIONS | DEBUG_TRACE_ERROR,
("[Cdo]: CdoHandlePrivateOpen -> Device open successful. ( Irp = %p, Flags = 0x%x, status = 0x%x )\n",
Irp,
Globals.Flags,
status) );
}
//
// The filter may want to do additional processing here to set up the structures it
// needs to service this create request.
//
CdoReleaseResource( &Globals.Resource );
DebugTrace( DEBUG_TRACE_CDO_SUPPORTED_OPERATIONS,
("[Cdo]: CdoHandlePrivateOpen exit ( Irp = %p, status = 0x%x )\n",
Irp,
status) );
return status;
}
NTSTATUS
CdoHandlePrivateCleanup(
IN PIRP Irp
)
/*++
Routine Description:
This routine handles cleanup IRPs that are directed to the control
device object.
Arguments:
Irp - the current Irp to process
Return Value:
Returns STATUS_SUCCESS
--*/
{
NTSTATUS status;
UNREFERENCED_PARAMETER( Irp );
PAGED_CODE();
DebugTrace( DEBUG_TRACE_CDO_SUPPORTED_OPERATIONS,
("[Cdo]: CdoHandlePrivateCleanup entry ( Irp = %p )\n",
Irp) );
CdoAcquireResourceExclusive( &Globals.Resource );
//
// Sanity - the CDO must have a handle and a reference for us to get a cleanup on it
//
ASSERT( FlagOn( Globals.Flags, GLOBAL_DATA_F_CDO_OPEN_REF ) &&
FlagOn( Globals.Flags, GLOBAL_DATA_F_CDO_OPEN_HANDLE) );
//
// Reset the flag that indicates the CDO has a open handle
//
ClearFlag( Globals.Flags, GLOBAL_DATA_F_CDO_OPEN_HANDLE);
status = STATUS_SUCCESS;
//
// The filter may want to do additional processing here to cleanup up the structures it
// needed to service the handle that is being closed.
//
DebugTrace( DEBUG_TRACE_CDO_SUPPORTED_OPERATIONS | DEBUG_TRACE_ERROR,
("[Cdo]: CdoHandlePrivateCleanup -> Device cleanup successful. ( Irp = %p, Flags = 0x%x, status = 0x%x )\n",
Irp,
Globals.Flags,
status) );
CdoReleaseResource( &Globals.Resource );
DebugTrace( DEBUG_TRACE_CDO_SUPPORTED_OPERATIONS,
("[Cdo]: CdoHandlePrivateCleanup exit ( Irp = %p, status = 0x%x )\n",
Irp,
status) );
return status;
}
NTSTATUS
CdoHandlePrivateClose(
IN PIRP Irp
)
/*++
Routine Description:
This routine handles close IRPs that are directed to the control
device object.
Arguments:
Irp - the current Irp to process
Return Value:
Returns STATUS_SUCCESS
--*/
{
NTSTATUS status;
UNREFERENCED_PARAMETER( Irp );
PAGED_CODE();
DebugTrace( DEBUG_TRACE_CDO_SUPPORTED_OPERATIONS,
("[Cdo]: CdoHandlePrivateClose entry ( Irp = %p )\n",
Irp) );
CdoAcquireResourceExclusive( &Globals.Resource );
//
// Sanity - the connection must have a reference but have no handle open,
// for us to get a close on it
//
ASSERT( FlagOn( Globals.Flags, GLOBAL_DATA_F_CDO_OPEN_REF ) &&
!FlagOn( Globals.Flags, GLOBAL_DATA_F_CDO_OPEN_HANDLE ));
//
// Reset the flag that indicates the CDO is opened so that we will suceed
// future creates
//
ClearFlag( Globals.Flags, GLOBAL_DATA_F_CDO_OPEN_REF );
//
// The filter may want to do additional processing here to cleanup up the structures it
// needed to service the user mode attachment that is being closed.
//
status = STATUS_SUCCESS;
DebugTrace( DEBUG_TRACE_CDO_SUPPORTED_OPERATIONS | DEBUG_TRACE_ERROR,
("[Cdo]: CdoHandlePrivateClose -> Device close successful. ( Irp = %p, Flags = 0x%x, status = 0x%x )\n",
Irp,
Globals.Flags,
status) );
CdoReleaseResource( &Globals.Resource );
DebugTrace( DEBUG_TRACE_CDO_SUPPORTED_OPERATIONS,
("[Cdo]: CdoHandlePrivateClose exit ( Irp = %p, status = 0x%x )\n",
Irp,
status) );
return status;
}
NTSTATUS
CdoHandlePrivateFsControl (
IN PDEVICE_OBJECT DeviceObject,
IN ULONG IoControlCode,
IN PVOID InputBuffer OPTIONAL,
IN ULONG InputBufferLength,
OUT PVOID OutputBuffer OPTIONAL,
IN ULONG OutputBufferLength,
OUT PIO_STATUS_BLOCK IoStatus,
IN PIRP Irp
)
/*++
Routine Description:
This routine is invoked whenever an I/O Request Packet (IRP) w/a major
function code of IRP_MJ_FILE_SYSTEM_CONTROL is encountered for the CDO.
Arguments:
DeviceObject - Pointer to the device object for this driver.
IoControlCode - Control code for this IOCTL
InputBuffer - Input buffer
InputBufferLength - Input buffer length
OutputBuffer - Output buffer
OutputBufferLength - Output buffer length
IoStatus - IO status block for this request
Irp - Pointer to the request packet representing the I/O request.
Return Value:
The function value is the status of the operation.
--*/
{
NTSTATUS status = STATUS_SUCCESS;
UNREFERENCED_PARAMETER( DeviceObject );
UNREFERENCED_PARAMETER( IoControlCode );
UNREFERENCED_PARAMETER( InputBuffer );
UNREFERENCED_PARAMETER( InputBufferLength );
UNREFERENCED_PARAMETER( OutputBuffer );
UNREFERENCED_PARAMETER( OutputBufferLength );
UNREFERENCED_PARAMETER( Irp );
PAGED_CODE();
DebugTrace( DEBUG_TRACE_CDO_SUPPORTED_OPERATIONS,
("[Cdo]: CdoHandlePrivateFsControl entry ( Irp = %p )\n"
"\tIoControlCode = 0x%x\n"
"\tInputBuffer = %p\n"
"\tInputBufferLength = 0x%x\n"
"\tOutputBuffer = %p\n"
"\tOutputBufferLength = 0x%x\n",
Irp,
IoControlCode,
InputBuffer,
InputBufferLength,
OutputBuffer,
OutputBufferLength) );
CdoAcquireResourceShared( &Globals.Resource );
//
// Sanity - there must atleast be a reference open for us to get a IOCTL on the CDO
//
ASSERT( FlagOn( Globals.Flags, GLOBAL_DATA_F_CDO_OPEN_REF ) );
if (!FlagOn( Globals.Flags, GLOBAL_DATA_F_CDO_OPEN_HANDLE)) {
//
// If there is no handle open to the CDO fail the operation
//
DebugTrace( DEBUG_TRACE_CDO_SUPPORTED_OPERATIONS | DEBUG_TRACE_ERROR,
("[Cdo]: CdoHandlePrivateFsControl -> Failing IOCTL since no handle to CDO is open. ( Irp = %p, IoControlCode = 0x%x, Flags = 0x%x )\n",
Irp,
IoControlCode,
Globals.Flags) );
status = STATUS_INVALID_DEVICE_STATE;
CdoReleaseResource( &Globals.Resource );
goto CdoHandlePrivateFsControlCleanup;
}
//
// Here the filter may perform any action that requires that
// the handle to the CDO still be open
DebugTrace( DEBUG_TRACE_CDO_SUPPORTED_OPERATIONS,
("[Cdo]: CdoHandlePrivateFsControl -> Processing IOCTL while handle to CDO is definitely open. ( Irp = %p, IoControlCode = 0x%x )\n",
Irp,
IoControlCode) );
CdoReleaseResource( &Globals.Resource );
//
// Since the resource has been released the CDO may complete a cleanup before we
// do any of the following.
//
//
// Here the filter may perform any action that does not require that
// the handle to the CDO still be open. For example, the IOCTL may have
// been used to trigger off an asynchronous background task that will
// continue executing even after the handle has been closed
//
// Note that the system will still maintain a reference to the CDO. So,
// the filter will not see a Close on the CDO until it finishes servicing
// IRP_MJ_FILE_SYSTEM_CONTROL
//
DebugTrace( DEBUG_TRACE_CDO_SUPPORTED_OPERATIONS,
("[Cdo]: CdoHandlePrivateFsControl -> Processing IOCTL while handle to CDO may not be open. ( Irp = %p, IoControlCode = 0x%x )\n",
Irp,
IoControlCode) );
status = STATUS_SUCCESS;
CdoHandlePrivateFsControlCleanup:
IoStatus->Status = status;
IoStatus->Information = 0;
DebugTrace( DEBUG_TRACE_CDO_SUPPORTED_OPERATIONS,
("[Cdo]: CdoHandlePrivateFsControl exit ( Irp = %p, IoControlCode = 0x%x, status = 0x%x )\n",
Irp,
IoControlCode,
status) );
return status;
}
/////////////////////////////////////////////////////////////////////////////
//
// FastIO Handling routines
//
/////////////////////////////////////////////////////////////////////////////
BOOLEAN
CdoFastIoCheckIfPossible (
IN PFILE_OBJECT FileObject,
IN PLARGE_INTEGER FileOffset,
IN ULONG Length,
IN BOOLEAN Wait,
IN ULONG LockKey,
IN BOOLEAN CheckForReadOperation,
OUT PIO_STATUS_BLOCK IoStatus,
IN PDEVICE_OBJECT DeviceObject )
/*++
Routine Description:
This routine is the fast I/O "pass through" routine for checking to see
whether fast I/O is possible for this file.
This function simply invokes the file system's corresponding routine, or
returns FALSE if the file system does not implement the function.
Arguments:
FileObject - Pointer to the file object to be operated on.
FileOffset - Byte offset in the file for the operation.
Length - Length of the operation to be performed.
Wait - Indicates whether or not the caller is willing to wait if the
appropriate locks, etc. cannot be acquired
LockKey - Provides the caller's key for file locks.
CheckForReadOperation - Indicates whether the caller is checking for a
read (TRUE) or a write operation.
IoStatus - Pointer to a variable to receive the I/O status of the
operation.
DeviceObject - Pointer to this driver's device object, the device on
which the operation is to occur.
Return Value:
The function value is TRUE or FALSE based on whether or not fast I/O
is possible for this file.
--*/
{
PAGED_CODE();
ASSERT(IS_MY_CONTROL_DEVICE_OBJECT(DeviceObject));
UNREFERENCED_PARAMETER(FileObject);
UNREFERENCED_PARAMETER(FileOffset);
UNREFERENCED_PARAMETER(Length);
UNREFERENCED_PARAMETER(Wait);
UNREFERENCED_PARAMETER(LockKey);
UNREFERENCED_PARAMETER(CheckForReadOperation);
UNREFERENCED_PARAMETER(DeviceObject);
//
// This is our CDO, fail the operation
//
DebugTrace( DEBUG_TRACE_CDO_ALL_OPERATIONS | DEBUG_TRACE_CDO_FASTIO_OPERATIONS | DEBUG_TRACE_ERROR,
("[Cdo]: CdoFastIoCheckIfPossible -> Unsupported FastIO call ( FileObject = %p, DeviceObject = %p )\n",
FileObject,
DeviceObject) );
IoStatus->Status = STATUS_INVALID_DEVICE_REQUEST;
IoStatus->Information = 0;
return TRUE;
}
BOOLEAN
CdoFastIoRead (
IN PFILE_OBJECT FileObject,
IN PLARGE_INTEGER FileOffset,
IN ULONG Length,
IN BOOLEAN Wait,
IN ULONG LockKey,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -