📄 cddata.c
字号:
Vpb = IoGetCurrentIrpStackLocation( Irp )->FileObject->Vpb;
} else {
Vpb = NULL;
}
//
// The device to verify is either in my thread local storage
// or that of the thread that owns the Irp.
//
Thread = Irp->Tail.Overlay.Thread;
Device = IoGetDeviceToVerify( Thread );
if (Device == NULL) {
Thread = PsGetCurrentThread();
Device = IoGetDeviceToVerify( Thread );
ASSERT( Device != NULL );
//
// Let's not BugCheck just because the driver messes up.
//
if (Device == NULL) {
CdCompleteRequest( IrpContext, Irp, ExceptionCode );
return ExceptionCode;
}
}
//
// This routine actually causes the pop-up. It usually
// does this by queuing an APC to the callers thread,
// but in some cases it will complete the request immediately,
// so it is very important to IoMarkIrpPending() first.
//
IoMarkIrpPending( Irp );
IoRaiseHardError( Irp, Vpb, Device );
//
// We will be handing control back to the caller here, so
// reset the saved device object.
//
IoSetDeviceToVerify( Thread, NULL );
//
// The Irp will be completed by Io or resubmitted. In either
// case we must clean up the IrpContext here.
//
CdCompleteRequest( IrpContext, NULL, STATUS_SUCCESS );
return STATUS_PENDING;
}
}
//
// This is just a run of the mill error.
//
CdCompleteRequest( IrpContext, Irp, ExceptionCode );
return ExceptionCode;
}
VOID
CdCompleteRequest (
IN PIRP_CONTEXT IrpContext OPTIONAL,
IN PIRP Irp OPTIONAL,
IN NTSTATUS Status
)
/*++
Routine Description:
This routine completes a Irp and cleans up the IrpContext. Either or
both of these may not be specified.
Arguments:
Irp - Supplies the Irp being processed.
Status - Supplies the status to complete the Irp with
Return Value:
None.
--*/
{
ASSERT_OPTIONAL_IRP_CONTEXT( IrpContext );
ASSERT_OPTIONAL_IRP( Irp );
//
// Cleanup the IrpContext if passed in here.
//
if (ARGUMENT_PRESENT( IrpContext )) {
CdCleanupIrpContext( IrpContext, FALSE );
}
//
// If we have an Irp then complete the irp.
//
if (ARGUMENT_PRESENT( Irp )) {
//
// Clear the information field in case we have used this Irp
// internally.
//
if (NT_ERROR( Status ) &&
FlagOn( Irp->Flags, IRP_INPUT_OPERATION )) {
Irp->IoStatus.Information = 0;
}
Irp->IoStatus.Status = Status;
AssertVerifyDeviceIrp( Irp );
IoCompleteRequest( Irp, IO_CD_ROM_INCREMENT );
}
return;
}
VOID
CdSetThreadContext (
IN PIRP_CONTEXT IrpContext,
IN PTHREAD_CONTEXT ThreadContext
)
/*++
Routine Description:
This routine is called at each Fsd/Fsp entry point set up the IrpContext
and thread local storage to track top level requests. If there is
not a Cdfs context in the thread local storage then we use the input one.
Otherwise we use the one already there. This routine also updates the
IrpContext based on the state of the top-level context.
If the TOP_LEVEL flag in the IrpContext is already set when we are called
then we force this request to appear top level.
Arguments:
ThreadContext - Address on stack for local storage if not already present.
ForceTopLevel - We force this request to appear top level regardless of
any previous stack value.
Return Value:
None
--*/
{
PTHREAD_CONTEXT CurrentThreadContext;
ULONG_PTR StackTop;
ULONG_PTR StackBottom;
PAGED_CODE();
ASSERT_IRP_CONTEXT( IrpContext );
//
// Get the current top-level irp out of the thread storage.
// If NULL then this is the top-level request.
//
CurrentThreadContext = (PTHREAD_CONTEXT) IoGetTopLevelIrp();
if (CurrentThreadContext == NULL) {
SetFlag( IrpContext->Flags, IRP_CONTEXT_FLAG_TOP_LEVEL );
}
//
// Initialize the input context unless we are using the current
// thread context block. We use the new block if our caller
// specified this or the existing block is invalid.
//
// The following must be true for the current to be a valid Cdfs context.
//
// Structure must lie within current stack.
// Address must be ULONG aligned.
// Cdfs signature must be present.
//
// If this is not a valid Cdfs context then use the input thread
// context and store it in the top level context.
//
IoGetStackLimits( &StackTop, &StackBottom);
if (FlagOn( IrpContext->Flags, IRP_CONTEXT_FLAG_TOP_LEVEL ) ||
(((ULONG_PTR) CurrentThreadContext > StackBottom - sizeof( THREAD_CONTEXT )) ||
((ULONG_PTR) CurrentThreadContext <= StackTop) ||
FlagOn( (ULONG_PTR) CurrentThreadContext, 0x3 ) ||
(CurrentThreadContext->Cdfs != 0x53464443))) {
ThreadContext->Cdfs = 0x53464443;
ThreadContext->SavedTopLevelIrp = (PIRP) CurrentThreadContext;
ThreadContext->TopLevelIrpContext = IrpContext;
IoSetTopLevelIrp( (PIRP) ThreadContext );
IrpContext->TopLevel = IrpContext;
IrpContext->ThreadContext = ThreadContext;
SetFlag( IrpContext->Flags, IRP_CONTEXT_FLAG_TOP_LEVEL_CDFS );
//
// Otherwise use the IrpContext in the thread context.
//
} else {
IrpContext->TopLevel = CurrentThreadContext->TopLevelIrpContext;
}
return;
}
BOOLEAN
CdFastIoCheckIfPossible (
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 checks if fast i/o is possible for a read/write operation
Arguments:
FileObject - Supplies the file object used in the query
FileOffset - Supplies the starting byte offset for the read/write operation
Length - Supplies the length, in bytes, of the read/write operation
Wait - Indicates if we can wait
LockKey - Supplies the lock key
CheckForReadOperation - Indicates if this is a check for a read or write
operation
IoStatus - Receives the status of the operation if our return value is
FastIoReturnError
Return Value:
BOOLEAN - TRUE if fast I/O is possible and FALSE if the caller needs
to take the long route.
--*/
{
PFCB Fcb;
TYPE_OF_OPEN TypeOfOpen;
LARGE_INTEGER LargeLength;
PAGED_CODE();
//
// Decode the type of file object we're being asked to process and
// make sure that is is only a user file open.
//
TypeOfOpen = CdFastDecodeFileObject( FileObject, &Fcb );
if ((TypeOfOpen != UserFileOpen) || !CheckForReadOperation) {
IoStatus->Status = STATUS_INVALID_PARAMETER;
return TRUE;
}
LargeLength.QuadPart = Length;
//
// Check whether the file locks will allow for fast io.
//
if ((Fcb->FileLock == NULL) ||
FsRtlFastCheckLockForRead( Fcb->FileLock,
FileOffset,
&LargeLength,
LockKey,
FileObject,
PsGetCurrentProcess() )) {
return TRUE;
}
return FALSE;
}
ULONG
CdSerial32 (
IN PCHAR Buffer,
IN ULONG ByteCount
)
/*++
Routine Description:
This routine is called to generate a 32 bit serial number. This is
done by doing four separate checksums into an array of bytes and
then treating the bytes as a ULONG.
Arguments:
Buffer - Pointer to the buffer to generate the ID for.
ByteCount - Number of bytes in the buffer.
Return Value:
ULONG - The 32 bit serial number.
--*/
{
union {
UCHAR Bytes[4];
ULONG SerialId;
} Checksum;
PAGED_CODE();
//
// Initialize the serial number.
//
Checksum.SerialId = 0;
//
// Continue while there are more bytes to use.
//
while (ByteCount--) {
//
// Increment this sub-checksum.
//
Checksum.Bytes[ByteCount & 0x3] += *(Buffer++);
}
//
// Return the checksums as a ULONG.
//
return Checksum.SerialId;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -