📄 udfdata.c
字号:
status. If UDFS explicitly raised an error then this status is already
in the IrpContext. We choose which is the correct status code and
either indicate that we will handle the exception or bug-check the system.
Arguments:
ExceptionCode - Supplies the exception code to being checked.
Return Value:
ULONG - returns EXCEPTION_EXECUTE_HANDLER or bugchecks
--*/
{
NTSTATUS ExceptionCode;
BOOLEAN TestStatus = TRUE;
ASSERT_OPTIONAL_IRP_CONTEXT( IrpContext );
ExceptionCode = ExceptionPointer->ExceptionRecord->ExceptionCode;
DebugTrace(( 0, Dbg,
"UdfExceptionFilter: %08x (exr %08x cxr %08x)\n",
ExceptionCode,
ExceptionPointer->ExceptionRecord,
ExceptionPointer->ContextRecord ));
//
// If the exception is STATUS_IN_PAGE_ERROR, get the I/O error code
// from the exception record.
//
if ((ExceptionCode == STATUS_IN_PAGE_ERROR) &&
(ExceptionPointer->ExceptionRecord->NumberParameters >= 3)) {
ExceptionCode = (NTSTATUS) ExceptionPointer->ExceptionRecord->ExceptionInformation[2];
}
//
// If there is an Irp context then check which status code to use.
//
if (ARGUMENT_PRESENT( IrpContext )) {
if (IrpContext->ExceptionStatus == STATUS_SUCCESS) {
//
// Store the real status into the IrpContext.
//
IrpContext->ExceptionStatus = ExceptionCode;
} else {
//
// No need to test the status code if we raised it ourselves.
//
TestStatus = FALSE;
}
}
//
// Bug check if this status is not supported.
//
if (TestStatus && !FsRtlIsNtstatusExpected( ExceptionCode )) {
UdfBugCheck( (ULONG_PTR) ExceptionPointer->ExceptionRecord,
(ULONG_PTR) ExceptionPointer->ContextRecord,
(ULONG_PTR) ExceptionPointer->ExceptionRecord->ExceptionAddress );
}
return EXCEPTION_EXECUTE_HANDLER;
}
NTSTATUS
UdfProcessException (
IN PIRP_CONTEXT IrpContext OPTIONAL,
IN PIRP Irp,
IN NTSTATUS ExceptionCode
)
/*++
Routine Description:
This routine processes an exception. It either completes the request
with the exception status in the IrpContext, sends this off to the Fsp
workque or causes it to be retried in the current thread if a verification
is needed.
If the volume needs to be verified (STATUS_VERIFY_REQUIRED) and we can
do the work in the current thread we will translate the status code
to STATUS_CANT_WAIT to indicate that we need to retry the request.
Arguments:
Irp - Supplies the Irp being processed
ExceptionCode - Supplies the normalized exception status being handled
Return Value:
NTSTATUS - Returns the results of either posting the Irp or the
saved completion status.
--*/
{
PDEVICE_OBJECT Device;
PVPB Vpb;
PETHREAD Thread;
ASSERT_OPTIONAL_IRP_CONTEXT( IrpContext );
ASSERT_IRP( Irp );
//
// If there is not an irp context, then complete the request with the
// current status code.
//
if (!ARGUMENT_PRESENT( IrpContext )) {
UdfCompleteRequest( NULL, Irp, ExceptionCode );
return ExceptionCode;
}
//
// Get the real exception status from the IrpContext.
//
ExceptionCode = IrpContext->ExceptionStatus;
//
// If we are not a top level request then we just complete the request
// with the current status code.
//
if (!FlagOn( IrpContext->Flags, IRP_CONTEXT_FLAG_TOP_LEVEL )) {
UdfCompleteRequest( IrpContext, Irp, ExceptionCode );
return ExceptionCode;
}
//
// Check if we are posting this request. One of the following must be true
// if we are to post a request.
//
// - Status code is STATUS_CANT_WAIT and the request is asynchronous
// or we are forcing this to be posted.
//
// - Status code is STATUS_VERIFY_REQUIRED and we are at APC level
// or higher. Can't wait for IO in the verify path in this case.
//
// Set the MORE_PROCESSING flag in the IrpContext to keep if from being
// deleted if this is a retryable condition.
//
// Note: Children of UdfFsdPostRequest() can raise.
//
try {
if (ExceptionCode == STATUS_CANT_WAIT) {
if (FlagOn( IrpContext->Flags, IRP_CONTEXT_FLAG_FORCE_POST )) {
ExceptionCode = UdfFsdPostRequest( IrpContext, Irp );
}
} else if (ExceptionCode == STATUS_VERIFY_REQUIRED) {
if (KeGetCurrentIrql() >= APC_LEVEL) {
ExceptionCode = UdfFsdPostRequest( IrpContext, Irp );
}
}
}
except (UdfExceptionFilter( IrpContext, GetExceptionInformation())) {
ExceptionCode = GetExceptionCode();
}
//
// If we posted the request or our caller will retry then just return here.
//
if ((ExceptionCode == STATUS_PENDING) ||
(ExceptionCode == STATUS_CANT_WAIT)) {
return ExceptionCode;
}
ClearFlag( IrpContext->Flags, IRP_CONTEXT_FLAG_MORE_PROCESSING );
//
// Store this error into the Irp for posting back to the Io system.
//
Irp->IoStatus.Status = ExceptionCode;
if (IoIsErrorUserInduced( ExceptionCode )) {
//
// Check for the various error conditions that can be caused by,
// and possibly resolved my the user.
//
if (ExceptionCode == STATUS_VERIFY_REQUIRED) {
//
// Now we are at the top level file system entry point.
//
// If we have already posted this request then the device to
// verify is in the original thread. Find this via the Irp.
//
Device = IoGetDeviceToVerify( Irp->Tail.Overlay.Thread );
IoSetDeviceToVerify( Irp->Tail.Overlay.Thread, NULL );
//
// If there is no device in that location then check in the
// current thread.
//
if (Device == NULL) {
Device = IoGetDeviceToVerify( PsGetCurrentThread() );
IoSetDeviceToVerify( PsGetCurrentThread(), NULL );
ASSERT( Device != NULL );
//
// Let's not BugCheck just because the driver screwed up.
//
if (Device == NULL) {
ExceptionCode = STATUS_DRIVER_INTERNAL_ERROR;
UdfCompleteRequest( IrpContext, Irp, ExceptionCode );
return ExceptionCode;
}
}
//
// CdPerformVerify() will do the right thing with the Irp.
// If we return STATUS_CANT_WAIT then the current thread
// can retry the request.
//
return UdfPerformVerify( IrpContext, Irp, Device );
}
//
// The other user induced conditions generate an error unless
// they have been disabled for this request.
//
if (FlagOn( IrpContext->Flags, IRP_CONTEXT_FLAG_DISABLE_POPUPS )) {
UdfCompleteRequest( IrpContext, Irp, ExceptionCode );
return ExceptionCode;
} else {
//
// Generate a pop-up
//
if (IoGetCurrentIrpStackLocation( Irp )->FileObject != NULL) {
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 screwed up.
//
if (Device == NULL) {
UdfCompleteRequest( 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.
//
UdfCompleteRequest( IrpContext, NULL, STATUS_SUCCESS );
return STATUS_PENDING;
}
}
//
// This is just a run of the mill error.
//
UdfCompleteRequest( IrpContext, Irp, ExceptionCode );
return ExceptionCode;
}
VOID
UdfCompleteRequest (
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 )) {
UdfCleanupIrpContext( 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;
IoCompleteRequest( Irp, IO_CD_ROM_INCREMENT );
}
return;
}
VOID
UdfSetThreadContext (
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 Udfs 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.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -