📄 udfdata.c
字号:
/*++
Copyright (c) 1989 Microsoft Corporation
Module Name:
UdfData.c
Abstract:
This module declares the global data used by the Udfs file system.
This module also handles the dispath routines in the Fsd threads as well as
handling the IrpContext and Irp through the exception path.
Author:
Dan Lovinger [DanLo] 24-May-1996
Revision History:
--*/
#include "UdfProcs.h"
//
// The Bug check file id for this module
//
#define BugCheckFileId (UDFS_BUG_CHECK_UDFDATA)
//
// The local debug trace level
//
#define Dbg (UDFS_DEBUG_LEVEL_UDFDATA)
//
// Global data structures
//
UDF_DATA UdfData;
FAST_IO_DISPATCH UdfFastIoDispatch;
//
// Debug trace levels
//
#ifdef UDF_SANITY
//
// For UdfDebugTrace (only live in checked builds) to be able to swing
// variable argument lists and varargs printfs.
//
#include <stdarg.h>
#include <stdio.h>
BOOLEAN UdfTestTopLevel = TRUE;
BOOLEAN UdfTestRaisedStatus = TRUE;
LONG UdfDebugTraceLevel = 0;
LONG UdfDebugTraceIndent = 0;
//
// Control whether UdfVerifyDescriptor will only emit info on failure (FALSE) or
// all of the time (TRUE).
//
BOOLEAN UdfNoisyVerifyDescriptor = FALSE;
#endif
//
// Reserved directory strings.
//
WCHAR UdfUnicodeSelfArray[] = { L'.' };
WCHAR UdfUnicodeParentArray[] = { L'.', L'.' };
UNICODE_STRING UdfUnicodeDirectoryNames[] = {
{ sizeof(UdfUnicodeSelfArray), sizeof(UdfUnicodeSelfArray), UdfUnicodeSelfArray},
{ sizeof(UdfUnicodeParentArray), sizeof(UdfUnicodeParentArray), UdfUnicodeParentArray}
};
//
// Identifier strings defined by UDF.
//
CHAR UdfCS0IdentifierArray[] = { 'O', 'S', 'T', 'A', ' ',
'C', 'o', 'm', 'p', 'r', 'e', 's', 's', 'e', 'd', ' ',
'U', 'n', 'i', 'c', 'o', 'd', 'e' };
STRING UdfCS0Identifier = {
sizeof(UdfCS0IdentifierArray),
sizeof(UdfCS0IdentifierArray),
UdfCS0IdentifierArray
};
CHAR UdfDomainIdentifierArray[] = { '*', 'O', 'S', 'T', 'A', ' ',
'U', 'D', 'F', ' ',
'C', 'o', 'm', 'p', 'l', 'i', 'a', 'n', 't' };
STRING UdfDomainIdentifier = {
sizeof(UdfDomainIdentifierArray),
sizeof(UdfDomainIdentifierArray),
UdfDomainIdentifierArray
};
CHAR UdfVirtualPartitionDomainIdentifierArray[] = { '*', 'U', 'D', 'F', ' ',
'V', 'i', 'r', 't', 'u', 'a', 'l', ' ',
'P', 'a', 'r', 't', 'i', 't', 'i', 'o', 'n' };
STRING UdfVirtualPartitionDomainIdentifier = {
sizeof(UdfVirtualPartitionDomainIdentifierArray),
sizeof(UdfVirtualPartitionDomainIdentifierArray),
UdfVirtualPartitionDomainIdentifierArray
};
CHAR UdfVatTableIdentifierArray[] = { '*', 'U', 'D', 'F', ' ',
'V', 'i', 'r', 't', 'u', 'a', 'l', ' ',
'A', 'l', 'l', 'o', 'c', ' ',
'T', 'b', 'l' };
STRING UdfVatTableIdentifier = {
sizeof(UdfVatTableIdentifierArray),
sizeof(UdfVatTableIdentifierArray),
UdfVatTableIdentifierArray
};
CHAR UdfSparablePartitionDomainIdentifierArray[] = { '*', 'U', 'D', 'F', ' ',
'S', 'p', 'a', 'r', 'a', 'b', 'l', 'e', ' ',
'P', 'a', 'r', 't', 'i', 't', 'i', 'o', 'n' };
STRING UdfSparablePartitionDomainIdentifier = {
sizeof(UdfSparablePartitionDomainIdentifierArray),
sizeof(UdfSparablePartitionDomainIdentifierArray),
UdfSparablePartitionDomainIdentifierArray
};
CHAR UdfSparingTableIdentifierArray[] = { '*', 'U', 'D', 'F', ' ',
'S', 'p', 'a', 'r', 'i', 'n', 'g', ' ',
'T', 'a', 'b', 'l', 'e' };
STRING UdfSparingTableIdentifier = {
sizeof(UdfSparingTableIdentifierArray),
sizeof(UdfSparingTableIdentifierArray),
UdfSparingTableIdentifierArray
};
CHAR UdfNSR02IdentifierArray[] = NSR_PART_CONTID_NSR02;
STRING UdfNSR02Identifier = {
sizeof(UdfNSR02IdentifierArray),
sizeof(UdfNSR02IdentifierArray),
UdfNSR02IdentifierArray
};
//
// Tables of tokens we have to parse up from mount-time on-disk structures
//
PARSE_KEYVALUE VsdIdentParseTable[] = {
{ VSD_IDENT_BEA01, VsdIdentBEA01 },
{ VSD_IDENT_TEA01, VsdIdentTEA01 },
{ VSD_IDENT_CDROM, VsdIdentCDROM },
{ VSD_IDENT_CD001, VsdIdentCD001 },
{ VSD_IDENT_CDW01, VsdIdentCDW01 },
{ VSD_IDENT_CDW02, VsdIdentCDW02 },
{ VSD_IDENT_NSR01, VsdIdentNSR01 },
{ VSD_IDENT_NSR02, VsdIdentNSR02 },
{ VSD_IDENT_BOOT2, VsdIdentBOOT2 },
{ NULL, VsdIdentBad }
};
PARSE_KEYVALUE NsrPartContIdParseTable[] = {
{ NSR_PART_CONTID_FDC01, NsrPartContIdFDC01 },
{ NSR_PART_CONTID_CD001, NsrPartContIdCD001 },
{ NSR_PART_CONTID_CDW01, NsrPartContIdCDW01 },
{ NSR_PART_CONTID_CDW02, NsrPartContIdCDW02 },
{ NSR_PART_CONTID_NSR01, NsrPartContIdNSR01 },
{ NSR_PART_CONTID_NSR02, NsrPartContIdNSR02 },
{ NULL, NsrPartContIdBad }
};
//
// Lookaside allocation lists for various volatile structures
//
NPAGED_LOOKASIDE_LIST UdfFcbNonPagedLookasideList;
NPAGED_LOOKASIDE_LIST UdfIrpContextLookasideList;
PAGED_LOOKASIDE_LIST UdfCcbLookasideList;
PAGED_LOOKASIDE_LIST UdfFcbIndexLookasideList;
PAGED_LOOKASIDE_LIST UdfFcbDataLookasideList;
PAGED_LOOKASIDE_LIST UdfLcbLookasideList;
//
// 16bit CRC table
//
PUSHORT UdfCrcTable;
#ifdef ALLOC_PRAGMA
#pragma alloc_text(PAGE, UdfComputeCrc16)
#pragma alloc_text(PAGE, UdfComputeCrc16Uni)
#ifdef UDF_SANITY
#pragma alloc_text(PAGE, UdfDebugTrace)
#endif
#pragma alloc_text(PAGE, UdfFastIoCheckIfPossible)
#pragma alloc_text(PAGE, UdfHighBit)
#pragma alloc_text(PAGE, UdfInitializeCrc16)
#pragma alloc_text(PAGE, UdfSerial32)
#endif
NTSTATUS
UdfFsdDispatch (
IN PVOLUME_DEVICE_OBJECT VolumeDeviceObject,
IN PIRP Irp
)
/*++
Routine Description:
This is the driver entry to all of the Fsd dispatch points.
Conceptually the Io routine will call this routine on all requests
to the file system. We case on the type of request and invoke the
correct handler for this type of request. There is an exception filter
to catch any exceptions in the UDFS code as well as the UDFS process
exception routine.
This routine allocates and initializes the IrpContext for this request as
well as updating the top-level thread context as necessary. We may loop
in this routine if we need to retry the request for any reason. The
status code STATUS_CANT_WAIT is used to indicate this. Suppose the disk
in the drive has changed. An Fsd request will proceed normally until it
recognizes this condition. STATUS_VERIFY_REQUIRED is raised at that point
and the exception code will handle the verify and either return
STATUS_CANT_WAIT or STATUS_PENDING depending on whether the request was
posted.
Arguments:
VolumeDeviceObject - Supplies the volume device object for this request
Irp - Supplies the Irp being processed
Return Value:
NTSTATUS - The FSD status for the IRP
--*/
{
THREAD_CONTEXT ThreadContext;
PIRP_CONTEXT IrpContext = NULL;
BOOLEAN Wait;
#ifdef UDF_SANITY
PVOID PreviousTopLevel;
#endif
NTSTATUS Status;
KIRQL SaveIrql = KeGetCurrentIrql();
ASSERT_OPTIONAL_IRP( Irp );
FsRtlEnterFileSystem();
#ifdef UDF_SANITY
PreviousTopLevel = IoGetTopLevelIrp();
#endif
//
// Loop until this request has been completed or posted.
//
do {
//
// Use a try-except to handle the exception cases.
//
try {
//
// If the IrpContext is NULL then this is the first pass through
// this loop.
//
if (IrpContext == NULL) {
//
// Decide if this request is waitable an allocate the IrpContext.
// If the file object in the stack location is NULL then this
// is a mount which is always waitable. Otherwise we look at
// the file object flags.
//
if (IoGetCurrentIrpStackLocation( Irp )->FileObject == NULL) {
Wait = TRUE;
} else {
Wait = CanFsdWait( Irp );
}
IrpContext = UdfCreateIrpContext( Irp, Wait );
//
// Update the thread context information.
//
UdfSetThreadContext( IrpContext, &ThreadContext );
#ifdef UDF_SANITY
ASSERT( !UdfTestTopLevel ||
SafeNodeType( IrpContext->TopLevel ) == UDFS_NTC_IRP_CONTEXT );
#endif
//
// Otherwise cleanup the IrpContext for the retry.
//
} else {
//
// Set the MORE_PROCESSING flag to make sure the IrpContext
// isn't inadvertently deleted here. Then cleanup the
// IrpContext to perform the retry.
//
SetFlag( IrpContext->Flags, IRP_CONTEXT_FLAG_MORE_PROCESSING );
UdfCleanupIrpContext( IrpContext, FALSE );
}
//
// Case on the major irp code.
//
switch (IrpContext->MajorFunction) {
case IRP_MJ_CLEANUP :
Status = UdfCommonCleanup( IrpContext, Irp );
break;
case IRP_MJ_CLOSE :
Status = UdfCommonClose( IrpContext, Irp );
break;
case IRP_MJ_CREATE :
Status = UdfCommonCreate( IrpContext, Irp );
break;
case IRP_MJ_DEVICE_CONTROL :
Status = UdfCommonDevControl( IrpContext, Irp );
break;
case IRP_MJ_DIRECTORY_CONTROL :
Status = UdfCommonDirControl( IrpContext, Irp );
break;
case IRP_MJ_FILE_SYSTEM_CONTROL :
Status = UdfCommonFsControl( IrpContext, Irp );
break;
case IRP_MJ_LOCK_CONTROL :
Status = UdfCommonLockControl( IrpContext, Irp );
break;
case IRP_MJ_PNP :
Status = UdfCommonPnp( IrpContext, Irp );
break;
case IRP_MJ_QUERY_INFORMATION :
Status = UdfCommonQueryInfo( IrpContext, Irp );
break;
case IRP_MJ_QUERY_VOLUME_INFORMATION :
Status = UdfCommonQueryVolInfo( IrpContext, Irp );
break;
case IRP_MJ_READ :
//
// If this is an Mdl complete request, don't go through
// common read.
//
if (FlagOn( IrpContext->MinorFunction, IRP_MN_COMPLETE )) {
Status = UdfCompleteMdl( IrpContext, Irp );
} else {
Status = UdfCommonRead( IrpContext, Irp );
}
break;
case IRP_MJ_SET_INFORMATION :
Status = UdfCommonSetInfo( IrpContext, Irp );
break;
default :
Status = STATUS_INVALID_DEVICE_REQUEST;
UdfCompleteRequest( IrpContext, Irp, Status );
}
} except( UdfExceptionFilter( IrpContext, GetExceptionInformation() )) {
Status = UdfProcessException( IrpContext, Irp, GetExceptionCode() );
}
} while (Status == STATUS_CANT_WAIT);
#ifdef UDF_SANITY
ASSERT( !UdfTestTopLevel ||
(PreviousTopLevel == IoGetTopLevelIrp()) );
#endif
FsRtlExitFileSystem();
ASSERT( SaveIrql == KeGetCurrentIrql( ));
return Status;
}
LONG
UdfExceptionFilter (
IN PIRP_CONTEXT IrpContext,
IN PEXCEPTION_POINTERS ExceptionPointer
)
/*++
Routine Description:
This routine is used to decide whether we will handle a raised exception
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -