/*++
Copyright (c) 1989 Microsoft Corporation
Module Name:
StrucSup.c
Abstract:
This module implements the Udfs in-memory data structure manipulation
routines
Author:
Dan Lovinger [DanLo] 19-Jun-1996
Revision History:
--*/
#include "UdfProcs.h"
//
// The Bug check file id for this module
//
#define BugCheckFileId (UDFS_BUG_CHECK_STRUCSUP)
//
// The local debug trace level
//
#define Dbg (UDFS_DEBUG_LEVEL_STRUCSUP)
//
// Local structures
//
typedef struct _FCB_TABLE_ELEMENT {
FILE_ID FileId;
PFCB Fcb;
} FCB_TABLE_ELEMENT, *PFCB_TABLE_ELEMENT;
//
// Local macros
//
//
// PFCB
// UdfAllocateFcbData (
// IN PIRP_CONTEXT IrpContext
// );
//
// VOID
// UdfDeallocateFcbData (
// IN PIRP_CONTEXT IrpContext,
// IN PFCB Fcb
// );
//
// PFCB
// UdfAllocateFcbIndex (
// IN PIRP_CONTEXT IrpContext
// );
//
// VOID
// UdfDeallocateFcbIndex (
// IN PIRP_CONTEXT IrpContext,
// IN PFCB Fcb
// );
//
// PFCB_NONPAGED
// UdfAllocateFcbNonpaged (
// IN PIRP_CONTEXT IrpContext
// );
//
// VOID
// UdfDeallocateFcbNonpaged (
// IN PIRP_CONTEXT IrpContext,
// IN PFCB_NONPAGED FcbNonpaged
// );
//
// PCCB
// UdfAllocateCcb (
// IN PIRP_CONTEXT IrpContext
// );
//
// VOID
// UdfDeallocateCcb (
// IN PIRP_CONTEXT IrpContext,
// IN PCCB Ccb
// );
//
#define UdfAllocateFcbData(IC) \
ExAllocateFromPagedLookasideList( &UdfFcbDataLookasideList );
#define UdfDeallocateFcbData(IC,F) \
ExFreeToPagedLookasideList( &UdfFcbDataLookasideList, F );
#define UdfAllocateFcbIndex(IC) \
ExAllocateFromPagedLookasideList( &UdfFcbIndexLookasideList );
#define UdfDeallocateFcbIndex(IC,F) \
ExFreeToPagedLookasideList( &UdfFcbIndexLookasideList, F );
#define UdfAllocateFcbNonpaged(IC) \
ExAllocateFromNPagedLookasideList( &UdfFcbNonPagedLookasideList );
#define UdfDeallocateFcbNonpaged(IC,FNP) \
ExFreeToNPagedLookasideList( &UdfFcbNonPagedLookasideList, FNP );
#define UdfAllocateCcb(IC) \
ExAllocateFromPagedLookasideList( &UdfCcbLookasideList );
#define UdfDeallocateCcb(IC,C) \
ExFreeToPagedLookasideList( &UdfCcbLookasideList, C );
//
// VOID
// UdfInsertFcbTable (
// IN PIRP_CONTEXT IrpContext,
// IN PFCB Fcb
// );
//
// VOID
// UdfDeleteFcbTable (
// IN PIRP_CONTEXT IrpContext,
// IN PFCB Fcb
// );
//
#define UdfInsertFcbTable(IC,F) { \
FCB_TABLE_ELEMENT _Key; \
_Key.Fcb = (F); \
_Key.FileId = (F)->FileId; \
RtlInsertElementGenericTable( &(F)->Vcb->FcbTable, \
&_Key, \
sizeof( FCB_TABLE_ELEMENT ), \
NULL ); \
}
#define UdfDeleteFcbTable(IC,F) { \
FCB_TABLE_ELEMENT _Key; \
_Key.FileId = (F)->FileId; \
RtlDeleteElementGenericTable( &(F)->Vcb->FcbTable, &_Key ); \
}
//
// Discovers the partition the current allocation descriptor's referred extent
// is on, either explicitly throuigh the descriptor or implicitly through the
// mapped view.
//
INLINE
USHORT
UdfGetPartitionOfCurrentAllocation (
IN PALLOC_ENUM_CONTEXT AllocContext
)
{
if (AllocContext->AllocType == ICBTAG_F_ALLOC_LONG) {
return ((PLONGAD) AllocContext->Alloc)->Start.Partition;
} else {
return AllocContext->IcbContext->Active.Partition;
}
}
//
// Builds the Mcb in an Fcb. Use this after knowing that an Mcb is required
// for mapping information.
//
INLINE
VOID
UdfInitializeFcbMcb (
IN PFCB Fcb
)
{
//
// In certain rare situations, we may get called more than once.
// Just reset the allocations.
//
if (FlagOn( Fcb->FcbState, FCB_STATE_MCB_INITIALIZED )) {
FsRtlResetLargeMcb( &Fcb->Mcb, TRUE );
} else {
FsRtlInitializeLargeMcb( &Fcb->Mcb, UdfPagedPool );
SetFlag( Fcb->FcbState, FCB_STATE_MCB_INITIALIZED );
}
}
//
// Teardown an Fcb's Mcb as required.
//
INLINE
VOID
UdfUninitializeFcbMcb (
IN PFCB Fcb
)
{
if (FlagOn( Fcb->FcbState, FCB_STATE_MCB_INITIALIZED )) {
FsRtlUninitializeLargeMcb( &Fcb->Mcb );
ClearFlag( Fcb->FcbState, FCB_STATE_MCB_INITIALIZED );
}
}
//
// Local support routines
//
PVOID
UdfAllocateTable (
IN PRTL_GENERIC_TABLE Table,
IN CLONG ByteSize
);
PFCB_NONPAGED
UdfCreateFcbNonPaged (
IN PIRP_CONTEXT IrpContext
);
VOID
UdfDeleteFcbNonpaged (
IN PIRP_CONTEXT IrpContext,
IN PFCB_NONPAGED FcbNonpaged
);
VOID
UdfDeallocateTable (
IN PRTL_GENERIC_TABLE Table,
IN PVOID Buffer
);
RTL_GENERIC_COMPARE_RESULTS
UdfFcbTableCompare (
IN PRTL_GENERIC_TABLE Table,
IN PVOID id1,
IN PVOID id2
);
VOID
UdfInitializeAllocationContext (
IN PIRP_CONTEXT IrpContext,
IN PALLOC_ENUM_CONTEXT AllocContext,
IN PICB_SEARCH_CONTEXT IcbContext
);
BOOLEAN
UdfGetNextAllocation (
IN PIRP_CONTEXT IrpContext,
IN PALLOC_ENUM_CONTEXT AllocContext
);
BOOLEAN
UdfGetNextAllocationPostProcessing (
IN PIRP_CONTEXT IrpContext,
IN PALLOC_ENUM_CONTEXT AllocContext
);
VOID
UdfLookupActiveIcbInExtent (
IN PIRP_CONTEXT IrpContext,
IN PICB_SEARCH_CONTEXT IcbContext,
IN ULONG Recurse
);
VOID
UdfInitializeEaContext (
IN PIRP_CONTEXT IrpContext,
IN PEA_SEARCH_CONTEXT EaContext,
IN PICB_SEARCH_CONTEXT IcbContext,
IN ULONG EAType,
IN UCHAR EASubType
);
BOOLEAN
UdfLookupEa (
IN PIRP_CONTEXT IrpContext,
IN PEA_SEARCH_CONTEXT EaContext
);
#ifdef ALLOC_PRAGMA
#pragma alloc_text(PAGE, UdfAllocateTable)
#pragma alloc_text(PAGE, UdfCleanupIcbContext)
#pragma alloc_text(PAGE, UdfCleanupIrpContext)
#pragma alloc_text(PAGE, UdfCreateCcb)
#pragma alloc_text(PAGE, UdfCreateFcb)
#pragma alloc_text(PAGE, UdfCreateFcbNonPaged)
#pragma alloc_text(PAGE, UdfCreateIrpContext)
#pragma alloc_text(PAGE, UdfDeallocateTable)
#pragma alloc_text(PAGE, UdfDeleteCcb)
#pragma alloc_text(PAGE, UdfDeleteFcb)
#pragma alloc_text(PAGE, UdfDeleteFcbNonpaged)
#pragma alloc_text(PAGE, UdfDeleteVcb)
#pragma alloc_text(PAGE, UdfFcbTableCompare)
#pragma alloc_text(PAGE, UdfFindInParseTable)
#pragma alloc_text(PAGE, UdfGetNextAllocation)
#pragma alloc_text(PAGE, UdfGetNextAllocationPostProcessing)
#pragma alloc_text(PAGE, UdfGetNextFcb)
#pragma alloc_text(PAGE, UdfInitializeAllocationContext)
#pragma alloc_text(PAGE, UdfInitializeAllocations)
#pragma alloc_text(PAGE, UdfInitializeEaContext)
#pragma alloc_text(PAGE, UdfInitializeFcbFromIcbContext)
#pragma alloc_text(PAGE, UdfInitializeIcbContext)
#pragma alloc_text(PAGE, UdfInitializeStackIrpContext)
#pragma alloc_text(PAGE, UdfInitializeVcb)
#pragma alloc_text(PAGE, UdfLookupActiveIcb)
#pragma alloc_text(PAGE, UdfLookupActiveIcbInExtent)
#pragma alloc_text(PAGE, UdfLookupEa)
#pragma alloc_text(PAGE, UdfLookupFcbTable)
#pragma alloc_text(PAGE, UdfTeardownStructures)
#pragma alloc_text(PAGE, UdfUpdateTimestampsFromIcbContext)
#pragma alloc_text(PAGE, UdfUpdateVcbPhase0)
#pragma alloc_text(PAGE, UdfUpdateVcbPhase1)
#pragma alloc_text(PAGE, UdfVerifyDescriptor)
#endif ALLOC_PRAGMA
BOOLEAN
UdfInitializeVcb (
IN PIRP_CONTEXT IrpContext,
IN OUT PVCB Vcb,