ReactOS 0.4.16-dev-91-g764881a
strucsup.c File Reference
#include "cdprocs.h"
Include dependency graph for strucsup.c:

Go to the source code of this file.

Classes

struct  _FCB_TABLE_ELEMENT
 

Macros

#define BugCheckFileId   (CDFS_BUG_CHECK_STRUCSUP)
 
#define CdAllocateFcbData(IC)    FsRtlAllocatePoolWithTag( CdPagedPool, SIZEOF_FCB_DATA, TAG_FCB_DATA )
 
#define CdDeallocateFcbData(IC, F)    CdFreePool( &(F) )
 
#define CdAllocateFcbIndex(IC)    FsRtlAllocatePoolWithTag( CdPagedPool, SIZEOF_FCB_INDEX, TAG_FCB_INDEX )
 
#define CdDeallocateFcbIndex(IC, F)    CdFreePool( &(F) )
 
#define CdAllocateFcbNonpaged(IC)    ExAllocatePoolWithTag( CdNonPagedPool, sizeof( FCB_NONPAGED ), TAG_FCB_NONPAGED )
 
#define CdDeallocateFcbNonpaged(IC, FNP)    CdFreePool( &(FNP) )
 
#define CdAllocateCcb(IC)    FsRtlAllocatePoolWithTag( CdPagedPool, sizeof( CCB ), TAG_CCB )
 
#define CdDeallocateCcb(IC, C)    CdFreePool( &(C) )
 
#define CdInsertFcbTable(IC, F)
 
#define CdDeleteFcbTable(IC, F)
 

Typedefs

typedef struct _FCB_TABLE_ELEMENT FCB_TABLE_ELEMENT
 
typedef struct _FCB_TABLE_ELEMENTPFCB_TABLE_ELEMENT
 

Functions

VOID CdDeleteFcb (_In_ PIRP_CONTEXT IrpContext, _In_ PFCB Fcb)
 
PFCB_NONPAGED CdCreateFcbNonpaged (_In_ PIRP_CONTEXT IrpContext)
 
VOID CdDeleteFcbNonpaged (_In_ PIRP_CONTEXT IrpContext, _In_ PFCB_NONPAGED FcbNonpaged)
 
RTL_GENERIC_COMPARE_RESULTS NTAPI CdFcbTableCompare (_In_ PRTL_GENERIC_TABLE FcbTable, _In_ PVOID Fid1, _In_ PVOID Fid2)
 
PVOID NTAPI CdAllocateFcbTable (_In_ PRTL_GENERIC_TABLE FcbTable, _In_ CLONG ByteSize)
 
VOID NTAPI CdDeallocateFcbTable (_In_ PRTL_GENERIC_TABLE FcbTable, _In_ __drv_freesMem(Mem) _Post_invalid_ PVOID Buffer)
 
ULONG CdTocSerial (_In_ PIRP_CONTEXT IrpContext, _In_ PCDROM_TOC_LARGE CdromToc)
 
VOID CdInitializeVcb (_In_ PIRP_CONTEXT IrpContext, _Inout_ PVCB Vcb, _In_ __drv_aliasesMem PDEVICE_OBJECT TargetDeviceObject, _In_ __drv_aliasesMem PVPB Vpb, _In_ __drv_aliasesMem PCDROM_TOC_LARGE CdromToc, _In_ ULONG TocLength, _In_ ULONG TocTrackCount, _In_ ULONG TocDiskFlags, _In_ ULONG BlockFactor, _In_ ULONG MediaChangeCount)
 
VOID CdUpdateVcbFromVolDescriptor (_In_ PIRP_CONTEXT IrpContext, _Inout_ PVCB Vcb, _In_reads_bytes_opt_(SECTOR_SIZE) PCHAR RawIsoVd)
 
VOID CdDeleteVcb (_In_ PIRP_CONTEXT IrpContext, _Inout_ PVCB Vcb)
 
PFCB CdCreateFcb (_In_ PIRP_CONTEXT IrpContext, _In_ FILE_ID FileId, _In_ NODE_TYPE_CODE NodeTypeCode, _Out_opt_ PBOOLEAN FcbExisted)
 
VOID CdInitializeFcbFromPathEntry (_In_ PIRP_CONTEXT IrpContext, _Inout_ PFCB Fcb, _In_opt_ PFCB ParentFcb, _In_ PPATH_ENTRY PathEntry)
 
VOID CdInitializeFcbFromFileContext (_In_ PIRP_CONTEXT IrpContext, _Inout_ PFCB Fcb, _In_ PFCB ParentFcb, _In_ PFILE_ENUM_CONTEXT FileContext)
 
PCCB CdCreateCcb (_In_ PIRP_CONTEXT IrpContext, _In_ PFCB Fcb, _In_ ULONG Flags)
 
VOID CdDeleteCcb (_In_ PIRP_CONTEXT IrpContext, _In_ __drv_freesMem(Pool) PCCB Ccb)
 
 _When_ (RaiseOnError||return, _At_(Fcb->FileLock, _Post_notnull_)) _When_(RaiseOnError
 
 _At_ (BOOLEANCdCreateFileLock(_In_opt_ PIRP_CONTEXT IrpContext, _Pre_notnull_)
 
_Ret_valid_ PIRP_CONTEXT CdCreateIrpContext (_In_ PIRP Irp, _In_ BOOLEAN Wait)
 
VOID CdCleanupIrpContext (_In_ PIRP_CONTEXT IrpContext, _In_ BOOLEAN Post)
 
VOID CdInitializeStackIrpContext (_Out_ PIRP_CONTEXT IrpContext, _In_ PIRP_CONTEXT_LITE IrpContextLite)
 
 _Requires_lock_held_ (_Global_critical_region_)
 
PFCB CdLookupFcbTable (_In_ PIRP_CONTEXT IrpContext, _In_ PVCB Vcb, _In_ FILE_ID FileId)
 
PFCB CdGetNextFcb (_In_ PIRP_CONTEXT IrpContext, _In_ PVCB Vcb, _In_ PVOID *RestartKey)
 
NTSTATUS CdProcessToc (_In_ PIRP_CONTEXT IrpContext, _In_ PDEVICE_OBJECT TargetDeviceObject, _In_ PCDROM_TOC_LARGE CdromToc, _Inout_ PULONG Length, _Out_ PULONG TrackCount, _Inout_ PULONG DiskFlags)
 

Variables

RTL_GENERIC_COMPARE_ROUTINE CdFcbTableCompare
 
RTL_GENERIC_ALLOCATE_ROUTINE CdAllocateFcbTable
 
RTL_GENERIC_FREE_ROUTINE CdDeallocateFcbTable
 
UNICODE_STRING CdInternalStreamNames []
 

Macro Definition Documentation

◆ BugCheckFileId

#define BugCheckFileId   (CDFS_BUG_CHECK_STRUCSUP)

Definition at line 23 of file strucsup.c.

◆ CdAllocateCcb

#define CdAllocateCcb (   IC)     FsRtlAllocatePoolWithTag( CdPagedPool, sizeof( CCB ), TAG_CCB )

Definition at line 93 of file strucsup.c.

◆ CdAllocateFcbData

#define CdAllocateFcbData (   IC)     FsRtlAllocatePoolWithTag( CdPagedPool, SIZEOF_FCB_DATA, TAG_FCB_DATA )

Definition at line 75 of file strucsup.c.

◆ CdAllocateFcbIndex

#define CdAllocateFcbIndex (   IC)     FsRtlAllocatePoolWithTag( CdPagedPool, SIZEOF_FCB_INDEX, TAG_FCB_INDEX )

Definition at line 81 of file strucsup.c.

◆ CdAllocateFcbNonpaged

#define CdAllocateFcbNonpaged (   IC)     ExAllocatePoolWithTag( CdNonPagedPool, sizeof( FCB_NONPAGED ), TAG_FCB_NONPAGED )

Definition at line 87 of file strucsup.c.

◆ CdDeallocateCcb

#define CdDeallocateCcb (   IC,
  C 
)     CdFreePool( &(C) )

Definition at line 96 of file strucsup.c.

◆ CdDeallocateFcbData

#define CdDeallocateFcbData (   IC,
  F 
)     CdFreePool( &(F) )

Definition at line 78 of file strucsup.c.

◆ CdDeallocateFcbIndex

#define CdDeallocateFcbIndex (   IC,
  F 
)     CdFreePool( &(F) )

Definition at line 84 of file strucsup.c.

◆ CdDeallocateFcbNonpaged

#define CdDeallocateFcbNonpaged (   IC,
  FNP 
)     CdFreePool( &(FNP) )

Definition at line 90 of file strucsup.c.

◆ CdDeleteFcbTable

#define CdDeleteFcbTable (   IC,
  F 
)
Value:
{ \
_Key.FileId = (F)->FileId; \
RtlDeleteElementGenericTable( &(F)->Vcb->FcbTable, &_Key ); \
}
#define Vcb
Definition: cdprocs.h:1415
#define F(x, y, z)
Definition: md5.c:51

Definition at line 139 of file strucsup.c.

◆ CdInsertFcbTable

#define CdInsertFcbTable (   IC,
  F 
)
Value:
{ \
_Key.Fcb = (F); \
_Key.FileId = (F)->FileId; \
RtlInsertElementGenericTable( &(F)->Vcb->FcbTable, \
&_Key, \
sizeof( FCB_TABLE_ELEMENT ), \
NULL ); \
}
#define NULL
Definition: types.h:112

Definition at line 129 of file strucsup.c.

Typedef Documentation

◆ FCB_TABLE_ELEMENT

◆ PFCB_TABLE_ELEMENT

Function Documentation

◆ _At_()

_At_ ( BOOLEANCdCreateFileLock ( _In_opt_ PIRP_CONTEXT  IrpContext,
_Pre_notnull_   
)

Definition at line 1498 of file strucsup.c.

1529{
1531 PFILE_LOCK FileLock;
1532
1533 PAGED_CODE();
1534
1535 //
1536 // Lock the Fcb and check if there is really any work to do.
1537 //
1538
1539 CdLockFcb( IrpContext, Fcb );
1540
1541 if (Fcb->FileLock != NULL) {
1542
1543 CdUnlockFcb( IrpContext, Fcb );
1544 return TRUE;
1545 }
1546
1547 Fcb->FileLock = FileLock =
1549
1550 CdUnlockFcb( IrpContext, Fcb );
1551
1552 //
1553 // Return or raise as appropriate.
1554 //
1555
1556 if (FileLock == NULL) {
1557
1558 if (RaiseOnError) {
1559
1560 NT_ASSERT( ARGUMENT_PRESENT( IrpContext ));
1561
1563 }
1564
1565 Result = FALSE;
1566 }
1567
1568 return Result;
1569}
#define PAGED_CODE()
unsigned char BOOLEAN
#define CdLockFcb(IC, F)
Definition: cdprocs.h:1044
_Inout_ PFCB _In_ BOOLEAN RaiseOnError
Definition: cdprocs.h:1211
_In_ PFCB Fcb
Definition: cdprocs.h:159
#define CdUnlockFcb(IC, F)
Definition: cdprocs.h:1060
#define CdRaiseStatus(IC, S)
Definition: cdprocs.h:1859
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
PFILE_LOCK NTAPI FsRtlAllocateFileLock(IN PCOMPLETE_LOCK_IRP_ROUTINE CompleteLockIrpRoutine OPTIONAL, IN PUNLOCK_ROUTINE UnlockRoutine OPTIONAL)
Definition: filelock.c:1318
#define ARGUMENT_PRESENT(ArgumentPointer)
FILE_LOCK FileLock
Definition: fatstruc.h:1071
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
#define NT_ASSERT
Definition: rtlfuncs.h:3324

◆ _Requires_lock_held_()

_Requires_lock_held_ ( _Global_critical_region_  )

Definition at line 1915 of file strucsup.c.

1953{
1956 BOOLEAN AcquiredCurrentFcb = FALSE;
1958
1959 PAGED_CODE();
1960
1962
1963 //
1964 // If this is a recursive call to TearDownStructures we return immediately
1965 // doing no operation.
1966 //
1967
1968 if (FlagOn( IrpContext->TopLevel->Flags, IRP_CONTEXT_FLAG_IN_TEARDOWN )) {
1969
1970 return;
1971 }
1972
1973 SetFlag( IrpContext->TopLevel->Flags, IRP_CONTEXT_FLAG_IN_TEARDOWN );
1974
1975 //
1976 // Use a try-finally to safely clear the top-level field.
1977 //
1978
1979 _SEH2_TRY {
1980
1981 //
1982 // Loop until we find an Fcb we can't remove.
1983 //
1984
1985 do {
1986
1987 //
1988 // See if there is an internal stream we should delete.
1989 // Only do this if it is the last reference on the Fcb.
1990 //
1991
1993 (CurrentFcb->FcbUserReference == 0) &&
1994 (CurrentFcb->FileObject != NULL)) {
1995
1996 //
1997 // Go ahead and delete the stream file object.
1998 //
1999
2000 CdDeleteInternalStream( IrpContext, CurrentFcb );
2001 }
2002
2003 //
2004 // If the reference count is non-zero then break.
2005 //
2006
2007 if (CurrentFcb->FcbReference != 0) {
2008
2009 break;
2010 }
2011
2012 //
2013 // It looks like we have a candidate for removal here. We
2014 // will need to acquire the parent, if present, in order to
2015 // remove this from the parent prefix table.
2016 //
2017
2019
2020 if (ParentFcb != NULL) {
2021
2022 CdAcquireFcbExclusive( IrpContext, ParentFcb, FALSE );
2023 }
2024
2025 //
2026 // Now lock the vcb.
2027 //
2028
2029 CdLockVcb( IrpContext, Vcb );
2030
2031 //
2032 // Final check to see if the reference count is still zero.
2033 //
2034
2035 if (CurrentFcb->FcbReference != 0) {
2036
2037 CdUnlockVcb( IrpContext, Vcb );
2038
2039 if (ParentFcb != NULL) {
2040
2041 CdReleaseFcb( IrpContext, ParentFcb );
2042 }
2043
2044 break;
2045 }
2046
2047 //
2048 // If there is a parent then do the necessary cleanup for the parent.
2049 //
2050
2051 if (ParentFcb != NULL) {
2052
2053 CdRemovePrefix( IrpContext, CurrentFcb );
2055
2056 CdDecrementReferenceCounts( IrpContext, ParentFcb, 1, 1 );
2057 }
2058
2060
2061 CdDeleteFcbTable( IrpContext, CurrentFcb );
2063
2064 }
2065
2066 //
2067 // Unlock the Vcb but hold the parent in order to walk up
2068 // the tree.
2069 //
2070
2071 CdUnlockVcb( IrpContext, Vcb );
2072 CdDeleteFcb( IrpContext, CurrentFcb );
2073
2074 //
2075 // Move to the parent Fcb.
2076 //
2077
2079 AcquiredCurrentFcb = TRUE;
2080
2081 } while (CurrentFcb != NULL);
2082
2083 } _SEH2_FINALLY {
2084
2085 //
2086 // Release the current Fcb if we have acquired it.
2087 //
2088
2089 if (AcquiredCurrentFcb && (CurrentFcb != NULL)) {
2090
2091 CdReleaseFcb( IrpContext, CurrentFcb );
2092 }
2093
2094 //
2095 // Clear the teardown flag.
2096 //
2097
2098 ClearFlag( IrpContext->TopLevel->Flags, IRP_CONTEXT_FLAG_IN_TEARDOWN );
2099 } _SEH2_END;
2100
2102 return;
2103}
VOID CdDeleteInternalStream(_In_ PIRP_CONTEXT IrpContext, _Inout_ PFCB Fcb)
Definition: cachesup.c:333
VOID CdDeleteFcb(_In_ PIRP_CONTEXT IrpContext, _In_ PFCB Fcb)
Definition: strucsup.c:2424
#define CdDeleteFcbTable(IC, F)
Definition: strucsup.c:139
_In_ PFCB ParentFcb
Definition: cdprocs.h:736
#define CdReleaseFcb(IC, F)
Definition: cdprocs.h:1012
#define CdLockVcb(IC, V)
Definition: cdprocs.h:1023
_Inout_ PFCB _Out_ PBOOLEAN RemovedStartingFcb
Definition: cdprocs.h:1261
#define CdUnlockVcb(IC, V)
Definition: cdprocs.h:1028
#define CdAcquireFcbExclusive(IC, F, I)
Definition: cdprocs.h:1006
#define CdDecrementReferenceCounts(IC, F, C, UC)
Definition: cdprocs.h:1325
_Inout_ PFCB * CurrentFcb
Definition: cdprocs.h:801
_Inout_ PFCB StartingFcb
Definition: cdprocs.h:1259
VOID CdRemovePrefix(_In_ PIRP_CONTEXT IrpContext, _Inout_ PFCB Fcb)
Definition: prefxsup.c:207
#define FCB_STATE_IN_FCB_TABLE
Definition: cdstruc.h:1043
#define IRP_CONTEXT_FLAG_IN_TEARDOWN
Definition: cdstruc.h:1220
#define SafeNodeType(Ptr)
Definition: nodetype.h:54
#define CDFS_NTC_FCB_DATA
Definition: nodetype.h:31
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define ClearFlag(_F, _SF)
Definition: ext2fs.h:191
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
#define _SEH2_FINALLY
Definition: filesup.c:21
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
Definition: cdstruc.h:902
struct _FCB * ParentFcb
Definition: cdstruc.h:940
PVCB Vcb
Definition: cdstruc.h:933
LIST_ENTRY FcbLinks
Definition: cdstruc.h:946
ULONG FcbUserReference
Definition: cdstruc.h:965
ULONG FcbState
Definition: cdstruc.h:971
__volatile LONG FcbReference
Definition: cdstruc.h:964
PFILE_OBJECT FileObject
Definition: ntfs.h:520
Definition: cdstruc.h:498

◆ _When_()

_When_ ( RaiseOnError||  return,
_At_(Fcb->FileLock, _Post_notnull_  
)

◆ CdAllocateFcbTable()

PVOID NTAPI CdAllocateFcbTable ( _In_ PRTL_GENERIC_TABLE  FcbTable,
_In_ CLONG  ByteSize 
)

Definition at line 2706 of file strucsup.c.

2729{
2730 PAGED_CODE();
2731
2732 UNREFERENCED_PARAMETER( FcbTable );
2733
2735}
#define TAG_FCB_TABLE
Definition: cdprocs.h:92
#define CdPagedPool
Definition: cdprocs.h:1380
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
PVOID NTAPI FsRtlAllocatePoolWithTag(IN POOL_TYPE PoolType, IN ULONG NumberOfBytes, IN ULONG Tag)
Definition: filter.c:229
_IRQL_requires_same_ _In_ CLONG ByteSize
Definition: rtltypes.h:412

◆ CdCleanupIrpContext()

VOID CdCleanupIrpContext ( _In_ PIRP_CONTEXT  IrpContext,
_In_ BOOLEAN  Post 
)

Definition at line 1733 of file strucsup.c.

1757{
1758 PAGED_CODE();
1759
1760 //
1761 // If we aren't doing more processing then deallocate this as appropriate.
1762 //
1763
1764 if (!FlagOn( IrpContext->Flags, IRP_CONTEXT_FLAG_MORE_PROCESSING)) {
1765
1766 //
1767 // If this context is the top level CDFS context then we need to
1768 // restore the top level thread context.
1769 //
1770
1771 if (IrpContext->ThreadContext != NULL) {
1772
1773 CdRestoreThreadContext( IrpContext );
1774 }
1775
1776 //
1777 // Deallocate the Io context if allocated.
1778 //
1779
1780 if (FlagOn( IrpContext->Flags, IRP_CONTEXT_FLAG_ALLOC_IO )) {
1781
1782 CdFreeIoContext( IrpContext->IoContext );
1783 }
1784
1785 //
1786 // Deallocate the IrpContext if not from the stack.
1787 //
1788
1789 if (!FlagOn( IrpContext->Flags, IRP_CONTEXT_FLAG_ON_STACK )) {
1790
1792
1793 CdLockCdData();
1794
1797
1799
1800 } else {
1801
1802 //
1803 // We couldn't add this to our lookaside list so free it to
1804 // pool.
1805 //
1806
1807 CdFreePool( &IrpContext );
1808 }
1809 }
1810
1811 //
1812 // Clear the appropriate flags.
1813 //
1814
1815 } else if (Post) {
1816
1817 //
1818 // If this context is the top level CDFS context then we need to
1819 // restore the top level thread context.
1820 //
1821
1822 if (IrpContext->ThreadContext != NULL) {
1823
1824 CdRestoreThreadContext( IrpContext );
1825 }
1826
1827 ClearFlag( IrpContext->Flags, IRP_CONTEXT_FLAGS_CLEAR_ON_POST );
1828
1829 } else {
1830
1831 ClearFlag( IrpContext->Flags, IRP_CONTEXT_FLAGS_CLEAR_ON_RETRY );
1832 }
1833
1834 return;
1835}
CD_DATA CdData
Definition: cddata.c:42
#define CdUnlockCdData()
Definition: cdprocs.h:1019
#define CdLockCdData()
Definition: cdprocs.h:1015
#define CdFreePool(x)
Definition: cdprocs.h:2190
#define CdFreeIoContext(IO)
Definition: cdprocs.h:1349
#define CdRestoreThreadContext(IC)
Definition: cdprocs.h:1983
#define IRP_CONTEXT_FLAG_ON_STACK
Definition: cdstruc.h:1213
#define IRP_CONTEXT_FLAG_ALLOC_IO
Definition: cdstruc.h:1221
#define IRP_CONTEXT_FLAGS_CLEAR_ON_RETRY
Definition: cdstruc.h:1251
#define IRP_CONTEXT_FLAGS_CLEAR_ON_POST
Definition: cdstruc.h:1236
#define IRP_CONTEXT_FLAG_MORE_PROCESSING
Definition: cdstruc.h:1214
ULONG IrpContextDepth
Definition: cdstruc.h:342
ULONG IrpContextMaxDepth
Definition: cdstruc.h:343
SINGLE_LIST_ENTRY IrpContextList
Definition: cdstruc.h:344
Definition: ntbasedef.h:628
FORCEINLINE VOID PushEntryList(_Inout_ PSINGLE_LIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PSINGLE_LIST_ENTRY Entry)
Definition: rtlfuncs.h:253

Referenced by _IRQL_requires_max_(), CdCompleteRequest(), CdFspDispatch(), and CdQueueClose().

◆ CdCreateCcb()

PCCB CdCreateCcb ( _In_ PIRP_CONTEXT  IrpContext,
_In_ PFCB  Fcb,
_In_ ULONG  Flags 
)

Definition at line 1405 of file strucsup.c.

1429{
1430 PCCB NewCcb;
1431 PAGED_CODE();
1432
1433 UNREFERENCED_PARAMETER( IrpContext );
1434
1435 //
1436 // Allocate and initialize the structure.
1437 //
1438
1439 NewCcb = CdAllocateCcb( IrpContext );
1440
1441 RtlZeroMemory( NewCcb, sizeof( CCB ));
1442
1443 //
1444 // Set the proper node type code and node byte size
1445 //
1446
1447 NewCcb->NodeTypeCode = CDFS_NTC_CCB;
1448 NewCcb->NodeByteSize = sizeof( CCB );
1449
1450 //
1451 // Set the initial value for the flags and Fcb
1452 //
1453
1454 NewCcb->Flags = Flags;
1455 NewCcb->Fcb = Fcb;
1456
1457 return NewCcb;
1458}
#define CdAllocateCcb(IC)
Definition: strucsup.c:93
struct _CCB CCB
#define CDFS_NTC_CCB
Definition: nodetype.h:33
Definition: cdstruc.h:1067
PFCB Fcb
Definition: cdstruc.h:1086
ULONG Flags
Definition: cdstruc.h:1080
NODE_BYTE_SIZE NodeByteSize
Definition: cdstruc.h:1074
NODE_TYPE_CODE NodeTypeCode
Definition: fatstruc.h:1366
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

◆ CdCreateFcb()

PFCB CdCreateFcb ( _In_ PIRP_CONTEXT  IrpContext,
_In_ FILE_ID  FileId,
_In_ NODE_TYPE_CODE  NodeTypeCode,
_Out_opt_ PBOOLEAN  FcbExisted 
)

Definition at line 986 of file strucsup.c.

1018{
1019 PFCB NewFcb;
1020 BOOLEAN LocalFcbExisted;
1021
1022 PAGED_CODE();
1023
1024 //
1025 // Use the local boolean if one was not passed in.
1026 //
1027
1028 if (!ARGUMENT_PRESENT( FcbExisted )) {
1029
1030 FcbExisted = &LocalFcbExisted;
1031 }
1032
1033 //
1034 // Maybe this is already in the table.
1035 //
1036
1037 NewFcb = CdLookupFcbTable( IrpContext, IrpContext->Vcb, FileId );
1038
1039 //
1040 // If not then create the Fcb is requested by our caller.
1041 //
1042
1043 if (NewFcb == NULL) {
1044
1045 //
1046 // Allocate and initialize the structure depending on the
1047 // type code.
1048 //
1049
1050 switch (NodeTypeCode) {
1051
1053 case CDFS_NTC_FCB_INDEX:
1054
1055 NewFcb = CdAllocateFcbIndex( IrpContext );
1056
1058
1059 NewFcb->NodeByteSize = SIZEOF_FCB_INDEX;
1060
1061 InitializeListHead( &NewFcb->FcbQueue );
1062
1063 break;
1064
1065 case CDFS_NTC_FCB_DATA :
1066
1067 NewFcb = CdAllocateFcbData( IrpContext );
1068
1069 RtlZeroMemory( NewFcb, SIZEOF_FCB_DATA );
1070
1071 NewFcb->NodeByteSize = SIZEOF_FCB_DATA;
1072
1073 break;
1074
1075 default:
1076
1077#ifdef _MSC_VER
1078#pragma prefast( suppress: __WARNING_USE_OTHER_FUNCTION, "This is a bug." )
1079#endif
1080 CdBugCheck( 0, 0, 0 );
1081 }
1082
1083 //
1084 // Now do the common initialization.
1085 //
1086
1087 NewFcb->NodeTypeCode = NodeTypeCode;
1088
1089 NewFcb->Vcb = IrpContext->Vcb;
1090 NewFcb->FileId = FileId;
1091
1092 CdInitializeMcb( IrpContext, NewFcb );
1093
1094 //
1095 // Now create the non-paged section object.
1096 //
1097
1098 NewFcb->FcbNonpaged = CdCreateFcbNonpaged( IrpContext );
1099
1100 //
1101 // Deallocate the Fcb and raise if the allocation failed.
1102 //
1103
1104 if (NewFcb->FcbNonpaged == NULL) {
1105
1106 CdFreePool( &NewFcb );
1107
1109 }
1110
1111 *FcbExisted = FALSE;
1112
1113 //
1114 // Initialize Advanced FCB Header fields
1115 //
1116
1118 FsRtlSetupAdvancedHeader( &NewFcb->Header,
1120
1121 if (NodeTypeCode == CDFS_NTC_FCB_DATA) {
1122
1124 }
1125
1126 } else {
1127
1128 *FcbExisted = TRUE;
1129 }
1130
1131 return NewFcb;
1132}
PFCB_NONPAGED CdCreateFcbNonpaged(_In_ PIRP_CONTEXT IrpContext)
Definition: strucsup.c:2555
PFCB CdLookupFcbTable(_In_ PIRP_CONTEXT IrpContext, _In_ PVCB Vcb, _In_ FILE_ID FileId)
Definition: strucsup.c:2107
#define CdAllocateFcbData(IC)
Definition: strucsup.c:75
#define CdAllocateFcbIndex(IC)
Definition: strucsup.c:81
#define CdGetFcbOplock(F)
Definition: cdprocs.h:1081
#define SIZEOF_FCB_DATA
Definition: cdstruc.h:1056
#define SIZEOF_FCB_INDEX
Definition: cdstruc.h:1059
#define CdBugCheck(A, B, C)
Definition: nodetype.h:103
#define CDFS_NTC_FCB_PATH_TABLE
Definition: nodetype.h:29
#define CDFS_NTC_FCB_INDEX
Definition: nodetype.h:30
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
VOID NTAPI FsRtlInitializeOplock(IN OUT POPLOCK Oplock)
Definition: oplock.c:1400
FAST_MUTEX AdvancedFcbHeaderMutex
Definition: cdstruc.h:892
FSRTL_ADVANCED_FCB_HEADER Header
Definition: cdstruc.h:925
FILE_ID FileId
Definition: cdstruc.h:952
PFCB_NONPAGED FcbNonpaged
Definition: cdstruc.h:1003
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274

Referenced by _Requires_lock_held_(), and CdUpdateVcbFromVolDescriptor().

◆ CdCreateFcbNonpaged()

PFCB_NONPAGED CdCreateFcbNonpaged ( _In_ PIRP_CONTEXT  IrpContext)

Definition at line 2555 of file strucsup.c.

2574{
2575 PFCB_NONPAGED FcbNonpaged;
2576
2577 PAGED_CODE();
2578
2579 UNREFERENCED_PARAMETER( IrpContext );
2580
2581 //
2582 // Allocate the non-paged pool and initialize the various
2583 // synchronization objects.
2584 //
2585
2586 FcbNonpaged = CdAllocateFcbNonpaged( IrpContext );
2587
2588 if (FcbNonpaged != NULL) {
2589
2590 RtlZeroMemory( FcbNonpaged, sizeof( FCB_NONPAGED ));
2591
2592 FcbNonpaged->NodeTypeCode = CDFS_NTC_FCB_NONPAGED;
2593 FcbNonpaged->NodeByteSize = sizeof( FCB_NONPAGED );
2594
2595 ExInitializeResourceLite( &FcbNonpaged->FcbResource );
2596 ExInitializeFastMutex( &FcbNonpaged->FcbMutex );
2597 }
2598
2599 return FcbNonpaged;
2600}
#define CdAllocateFcbNonpaged(IC)
Definition: strucsup.c:87
struct _FCB_NONPAGED FCB_NONPAGED
#define CDFS_NTC_FCB_NONPAGED
Definition: nodetype.h:32
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
ERESOURCE FcbResource
Definition: cdstruc.h:879
FAST_MUTEX FcbMutex
Definition: cdstruc.h:885
NODE_BYTE_SIZE NodeByteSize
Definition: cdstruc.h:863

Referenced by CdCreateFcb().

◆ CdCreateIrpContext()

_Ret_valid_ PIRP_CONTEXT CdCreateIrpContext ( _In_ PIRP  Irp,
_In_ BOOLEAN  Wait 
)

Definition at line 1573 of file strucsup.c.

1598{
1599 PIRP_CONTEXT NewIrpContext = NULL;
1601
1602 PAGED_CODE();
1603
1604 //
1605 // The only operations a filesystem device object should ever receive
1606 // are create/teardown of fsdo handles and operations which do not
1607 // occur in the context of fileobjects (i.e., mount).
1608 //
1609
1610#ifndef __REACTOS__
1612#else
1614 IrpSp->DeviceObject == CdData.HddFileSystemDeviceObject) {
1615#endif
1616
1617 if (IrpSp->FileObject != NULL &&
1621
1623 }
1624
1626
1630
1633
1635 }
1636
1637 //
1638 // Look in our lookaside list for an IrpContext.
1639 //
1640
1641 if (CdData.IrpContextDepth) {
1642
1643 CdLockCdData();
1644 NewIrpContext = (PIRP_CONTEXT) PopEntryList( &CdData.IrpContextList );
1645 if (NewIrpContext != NULL) {
1646
1648 }
1649
1651 }
1652
1653 if (NewIrpContext == NULL) {
1654
1655 //
1656 // We didn't get it from our private list so allocate it from pool.
1657 //
1658
1660 }
1661
1662 RtlZeroMemory( NewIrpContext, sizeof( IRP_CONTEXT ));
1663
1664 //
1665 // Set the proper node type code and node byte size
1666 //
1667
1668 NewIrpContext->NodeTypeCode = CDFS_NTC_IRP_CONTEXT;
1669 NewIrpContext->NodeByteSize = sizeof( IRP_CONTEXT );
1670
1671 //
1672 // Set the originating Irp field
1673 //
1674
1675 NewIrpContext->Irp = Irp;
1676
1677 //
1678 // Copy RealDevice for workque algorithms. We will update this in the Mount or
1679 // Verify since they have no file objects to use here.
1680 //
1681
1682 if (IrpSp->FileObject != NULL) {
1683
1684 NewIrpContext->RealDevice = IrpSp->FileObject->DeviceObject;
1685 }
1686
1687 //
1688 // Locate the volume device object and Vcb that we are trying to access.
1689 // This may be our filesystem device object. In that case don't initialize
1690 // the Vcb field.
1691 //
1692
1693#ifndef __REACTOS__
1695#else
1697 IrpSp->DeviceObject != CdData.HddFileSystemDeviceObject) {
1698#endif
1699
1700 NewIrpContext->Vcb = &((PVOLUME_DEVICE_OBJECT) IrpSp->DeviceObject)->Vcb;
1701
1702 }
1703
1704 //
1705 // Major/Minor Function codes
1706 //
1707
1708 NewIrpContext->MajorFunction = IrpSp->MajorFunction;
1709 NewIrpContext->MinorFunction = IrpSp->MinorFunction;
1710
1711 //
1712 // Set the wait parameter
1713 //
1714
1715 if (Wait) {
1716
1717 SetFlag( NewIrpContext->Flags, IRP_CONTEXT_FLAG_WAIT );
1718
1719 } else {
1720
1721 SetFlag( NewIrpContext->Flags, IRP_CONTEXT_FLAG_FORCE_POST );
1722 }
1723
1724 //
1725 // return and tell the caller
1726 //
1727
1728 return NewIrpContext;
1729}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define CdNonPagedPool
Definition: cdprocs.h:1381
#define TAG_IRP_CONTEXT
Definition: cdprocs.h:97
#define IRP_CONTEXT_FLAG_FORCE_POST
Definition: cdstruc.h:1216
#define IRP_CONTEXT_FLAG_WAIT
Definition: cdstruc.h:1215
VOLUME_DEVICE_OBJECT * PVOLUME_DEVICE_OBJECT
Definition: cdstruc.h:769
IRP_CONTEXT * PIRP_CONTEXT
Definition: cdstruc.h:1211
_In_ PIRP Irp
Definition: csq.h:116
#define CDFS_NTC_IRP_CONTEXT
Definition: nodetype.h:34
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define FSCTL_INVALIDATE_VOLUMES
Definition: nt_native.h:847
#define ExRaiseStatus
Definition: ntoskrnl.h:114
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
PIRP Irp
Definition: usbstor.h:99
PDEVICE_OBJECT FileSystemDeviceObject
Definition: cdstruc.h:350
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
struct _IO_STACK_LOCATION::@3974::@3989 FileSystemControl
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:3223
union _IO_STACK_LOCATION::@1575 Parameters
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
_In_ WDFDPC _In_ BOOLEAN Wait
Definition: wdfdpc.h:170
#define IRP_MJ_FILE_SYSTEM_CONTROL
#define IRP_MN_USER_FS_REQUEST
Definition: iotypes.h:4403
#define IRP_MJ_SHUTDOWN
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4404
#define IRP_MJ_CLEANUP
FORCEINLINE PSINGLE_LIST_ENTRY PopEntryList(_Inout_ PSINGLE_LIST_ENTRY ListHead)
Definition: rtlfuncs.h:240

Referenced by _IRQL_requires_max_().

◆ CdDeallocateFcbTable()

VOID NTAPI CdDeallocateFcbTable ( _In_ PRTL_GENERIC_TABLE  FcbTable,
_In_ __drv_freesMem(Mem) _Post_invalid_ PVOID  Buffer 
)

Definition at line 2743 of file strucsup.c.

2765{
2766 PAGED_CODE();
2767
2768 CdFreePool( &Buffer );
2769
2770 UNREFERENCED_PARAMETER( FcbTable );
2771}
Definition: bufpool.h:45

◆ CdDeleteCcb()

VOID CdDeleteCcb ( _In_ PIRP_CONTEXT  IrpContext,
_In_ __drv_freesMem(Pool) PCCB  Ccb 
)

Definition at line 1462 of file strucsup.c.

1482{
1483 PAGED_CODE();
1484
1485 UNREFERENCED_PARAMETER( IrpContext );
1486
1487 if (Ccb->SearchExpression.FileName.Buffer != NULL) {
1488
1489 CdFreePool( &Ccb->SearchExpression.FileName.Buffer );
1490 }
1491
1492 CdDeallocateCcb( IrpContext, Ccb );
1493 return;
1494}
#define CdDeallocateCcb(IC, C)
Definition: strucsup.c:96
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:592

◆ CdDeleteFcb()

VOID CdDeleteFcb ( _In_ PIRP_CONTEXT  IrpContext,
_In_ PFCB  Fcb 
)

Definition at line 2424 of file strucsup.c.

2447{
2448 PVCB Vcb = NULL;
2449 PAGED_CODE();
2450
2451 //
2452 // Sanity check the counts.
2453 //
2454
2455 NT_ASSERT( Fcb->FcbCleanup == 0 );
2456 NT_ASSERT( Fcb->FcbReference == 0 );
2457
2458 //
2459 // Release any Filter Context structures associated with this FCB
2460 //
2461
2463
2464 //
2465 // Start with the common structures.
2466 //
2467
2468 CdUninitializeMcb( IrpContext, Fcb );
2469
2470 CdDeleteFcbNonpaged( IrpContext, Fcb->FcbNonpaged );
2471
2472 //
2473 // Check if we need to deallocate the prefix name buffer.
2474 //
2475
2478
2480 }
2481
2482 //
2483 // Now look at the short name prefix.
2484 //
2485
2486 if (Fcb->ShortNamePrefix != NULL) {
2487
2489 }
2490
2491 //
2492 // Now do the type specific structures.
2493 //
2494
2495 switch (Fcb->NodeTypeCode) {
2496
2498 case CDFS_NTC_FCB_INDEX:
2499
2501 NT_ASSERT( IsListEmpty( &Fcb->FcbQueue ));
2502
2503 if (Fcb == Fcb->Vcb->RootIndexFcb) {
2504
2505 Vcb = Fcb->Vcb;
2506 Vcb->RootIndexFcb = NULL;
2507
2508 } else if (Fcb == Fcb->Vcb->PathTableFcb) {
2509
2510 Vcb = Fcb->Vcb;
2511 Vcb->PathTableFcb = NULL;
2512 }
2513
2514 CdDeallocateFcbIndex( IrpContext, *(PVOID*)&Fcb );/* ReactOS Change: GCC "passing argument 1 from incompatible pointer type" */
2515 break;
2516
2517 case CDFS_NTC_FCB_DATA :
2518
2519 if (Fcb->FileLock != NULL) {
2520
2522 }
2523
2525
2526 if (Fcb == Fcb->Vcb->VolumeDasdFcb) {
2527
2528 Vcb = Fcb->Vcb;
2529 Vcb->VolumeDasdFcb = NULL;
2530 }
2531
2532 CdDeallocateFcbData( IrpContext, *(PVOID*)&Fcb );/* ReactOS Change: GCC "passing argument 1 from incompatible pointer type" */
2533 }
2534
2535 //
2536 // Decrement the Vcb reference count if this is a system
2537 // Fcb.
2538 //
2539
2540 if (Vcb != NULL) {
2541
2542 InterlockedDecrement( (LONG*)&Vcb->VcbReference );
2543 InterlockedDecrement( (LONG*)&Vcb->VcbUserReference );
2544 }
2545
2546 return;
2547}
#define InterlockedDecrement
Definition: armddk.h:52
#define CdDeallocateFcbIndex(IC, F)
Definition: strucsup.c:84
#define CdDeallocateFcbData(IC, F)
Definition: strucsup.c:78
VOID CdDeleteFcbNonpaged(_In_ PIRP_CONTEXT IrpContext, _In_ PFCB_NONPAGED FcbNonpaged)
Definition: strucsup.c:2608
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
VOID NTAPI FsRtlFreeFileLock(IN PFILE_LOCK FileLock)
Definition: filelock.c:1342
VOID NTAPI FsRtlTeardownPerStreamContexts(IN PFSRTL_ADVANCED_FCB_HEADER AdvFcbHeader)
Definition: filtrctx.c:370
VOID NTAPI FsRtlUninitializeOplock(IN POPLOCK Oplock)
Definition: oplock.c:1600
long LONG
Definition: pedump.c:60
PREFIX_ENTRY FileNamePrefix
Definition: cdstruc.h:1024
PPREFIX_ENTRY ShortNamePrefix
Definition: cdstruc.h:1023
ULONG FcbCleanup
Definition: cdstruc.h:963
NAME_LINK ExactCaseName
Definition: cdstruc.h:293
WCHAR FileNameBuffer[BYTE_COUNT_EMBEDDED_NAME]
Definition: cdstruc.h:301
struct _FCB * RootIndexFcb
Definition: cdstruc.h:560
struct _FCB * VolumeDasdFcb
Definition: cdstruc.h:559
struct _FCB * PathTableFcb
Definition: cdstruc.h:561
uint16_t * PWCHAR
Definition: typedefs.h:56

Referenced by _Requires_lock_held_().

◆ CdDeleteFcbNonpaged()

VOID CdDeleteFcbNonpaged ( _In_ PIRP_CONTEXT  IrpContext,
_In_ PFCB_NONPAGED  FcbNonpaged 
)

Definition at line 2608 of file strucsup.c.

2629{
2630 PAGED_CODE();
2631
2632 UNREFERENCED_PARAMETER( IrpContext );
2633
2634 ExDeleteResourceLite( &FcbNonpaged->FcbResource );
2635
2636 CdDeallocateFcbNonpaged( IrpContext, *(PVOID*)&FcbNonpaged );/* ReactOS Change: GCC "passing argument 1 from incompatible pointer type" */
2637
2638 return;
2639}
#define CdDeallocateFcbNonpaged(IC, FNP)
Definition: strucsup.c:90
#define ExDeleteResourceLite(res)
Definition: env_spec_w32.h:647

Referenced by CdDeleteFcb().

◆ CdDeleteVcb()

VOID CdDeleteVcb ( _In_ PIRP_CONTEXT  IrpContext,
_Inout_ PVCB  Vcb 
)

Definition at line 876 of file strucsup.c.

899{
900 PAGED_CODE();
901
904
905 UNREFERENCED_PARAMETER( IrpContext );
906
907 //
908 // Chuck the backpocket Vpb we kept just in case.
909 //
910
911 CdFreePool( &Vcb->SwapVpb );
912
913 //
914 // If there is a Vpb then we must delete it ourselves.
915 //
916
917 CdFreePool( &Vcb->Vpb );
918
919 //
920 // Dereference our target if we haven't already done so.
921 //
922
923 if (Vcb->TargetDeviceObject != NULL) {
924
925 ObDereferenceObject( Vcb->TargetDeviceObject );
926 }
927
928 //
929 // Delete the XA Sector and sector cache buffer if allocated.
930 //
931
932 CdFreePool( &Vcb->XASector );
933 CdFreePool( &Vcb->SectorCacheBuffer);
934
935 if (Vcb->SectorCacheIrp != NULL) {
936
937 IoFreeIrp( Vcb->SectorCacheIrp);
938 Vcb->SectorCacheIrp = NULL;
939
940 ExDeleteResourceLite( &Vcb->SectorCacheResource);
941 }
942
943 //
944 // Remove this entry from the global queue.
945 //
946
947 RemoveEntryList( &Vcb->VcbLinks );
948
949 //
950 // Delete the Vcb and File resources.
951 //
952
953 ExDeleteResourceLite( &Vcb->VcbResource );
954 ExDeleteResourceLite( &Vcb->FileResource );
955
956 //
957 // Delete the TOC if present.
958 //
959
960 CdFreePool( &Vcb->CdromToc );
961
962 //
963 // Uninitialize the notify structures.
964 //
965
966 if (Vcb->NotifySync != NULL) {
967
968 FsRtlNotifyUninitializeSync( &Vcb->NotifySync );
969 }
970
971 //
972 // Now delete the volume device object.
973 //
974#ifdef _MSC_VER
975#pragma prefast( suppress: __WARNING_BUFFER_UNDERFLOW, "This is ok, the Vcb is embedded in our volume device object, and that is what we are really deleting." )
976#endif
979 Vcb ));
980
981 return;
982}
#define ASSERT_EXCLUSIVE_CDDATA
Definition: cddata.h:257
#define ASSERT_EXCLUSIVE_VCB(V)
Definition: cddata.h:258
VOID NTAPI FsRtlNotifyUninitializeSync(IN PNOTIFY_SYNC *NotifySync)
Definition: notify.c:1668
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define ObDereferenceObject
Definition: obfuncs.h:203

◆ CdFcbTableCompare()

RTL_GENERIC_COMPARE_RESULTS NTAPI CdFcbTableCompare ( _In_ PRTL_GENERIC_TABLE  FcbTable,
_In_ PVOID  Fid1,
_In_ PVOID  Fid2 
)

Definition at line 2648 of file strucsup.c.

2676{
2677 FILE_ID Id1, Id2;
2678 PAGED_CODE();
2679
2680 Id1 = *((FILE_ID UNALIGNED *) Fid1);
2681 Id2 = *((FILE_ID UNALIGNED *) Fid2);
2682
2683 if (Id1.QuadPart < Id2.QuadPart) {
2684
2685 return GenericLessThan;
2686
2687 } else if (Id1.QuadPart > Id2.QuadPart) {
2688
2689 return GenericGreaterThan;
2690
2691 } else {
2692
2693 return GenericEqual;
2694 }
2695
2696 UNREFERENCED_PARAMETER( FcbTable );
2697}
#define UNALIGNED
Definition: crtdefs.h:144
LONGLONG QuadPart
Definition: typedefs.h:114
@ GenericLessThan
Definition: rtltypes.h:389
@ GenericEqual
Definition: rtltypes.h:391
@ GenericGreaterThan
Definition: rtltypes.h:390

◆ CdGetNextFcb()

PFCB CdGetNextFcb ( _In_ PIRP_CONTEXT  IrpContext,
_In_ PVCB  Vcb,
_In_ PVOID RestartKey 
)

Definition at line 2155 of file strucsup.c.

2182{
2183 PFCB Fcb;
2184
2185 PAGED_CODE();
2186
2187 UNREFERENCED_PARAMETER( IrpContext );
2188
2189 Fcb = (PFCB) RtlEnumerateGenericTableWithoutSplaying( &Vcb->FcbTable, RestartKey );
2190
2191 if (Fcb != NULL) {
2192
2193 Fcb = ((PFCB_TABLE_ELEMENT)(Fcb))->Fcb;
2194 }
2195
2196 return Fcb;
2197}
struct _FCB_TABLE_ELEMENT * PFCB_TABLE_ELEMENT
FCB * PFCB
Definition: cdstruc.h:1040
_Must_inspect_result_ NTSYSAPI PVOID NTAPI RtlEnumerateGenericTableWithoutSplaying(_In_ PRTL_GENERIC_TABLE Table, _Inout_ PVOID *RestartKey)

Referenced by _Requires_lock_held_().

◆ CdInitializeFcbFromFileContext()

VOID CdInitializeFcbFromFileContext ( _In_ PIRP_CONTEXT  IrpContext,
_Inout_ PFCB  Fcb,
_In_ PFCB  ParentFcb,
_In_ PFILE_ENUM_CONTEXT  FileContext 
)

Definition at line 1225 of file strucsup.c.

1257{
1258 PDIRENT ThisDirent = &FileContext->InitialDirent->Dirent;
1259 PCOMPOUND_DIRENT CurrentCompoundDirent;
1260
1261 LONGLONG CurrentFileOffset;
1262 ULONG CurrentMcbEntryOffset;
1263
1264 PAGED_CODE();
1265
1266 //
1267 // Use a try-finally to facilitate cleanup.
1268 //
1269
1270 CdLockFcb( IrpContext, Fcb );
1271
1272 _SEH2_TRY {
1273
1274 //
1275 // Initialize the common header in the Fcb. The node type is already
1276 // present.
1277 //
1278
1279 Fcb->Resource = &IrpContext->Vcb->FileResource;
1280
1281 //
1282 // Allocation occurs in block-sized units.
1283 //
1284
1285 Fcb->FileSize.QuadPart =
1286 Fcb->ValidDataLength.QuadPart = FileContext->FileSize;
1287
1288 Fcb->AllocationSize.QuadPart = LlBlockAlign( Fcb->Vcb, FileContext->FileSize );
1289
1290 //
1291 // Set the flags from the dirent. We always start with the read-only bit.
1292 //
1293
1295 if (FlagOn( ThisDirent->DirentFlags, CD_ATTRIBUTE_HIDDEN )) {
1296
1298 }
1299
1300 //
1301 // Convert the time to NT time.
1302 //
1303
1304 CdConvertCdTimeToNtTime( IrpContext,
1305 ThisDirent->CdTime,
1307
1308 //
1309 // Set the flag indicating the type of extent.
1310 //
1311
1312 if (ThisDirent->ExtentType != Form1Data) {
1313
1314 if (ThisDirent->ExtentType == Mode2Form2Data) {
1315
1317
1318 } else {
1319
1321 }
1322
1323 Fcb->XAAttributes = ThisDirent->XAAttributes;
1324 Fcb->XAFileNumber = ThisDirent->XAFileNumber;
1325 }
1326
1327 //
1328 // Read through all of the dirents for the file until we find the last
1329 // and add the allocation into the Mcb.
1330 //
1331
1332 CurrentCompoundDirent = FileContext->InitialDirent;
1333 CurrentFileOffset = 0;
1334 CurrentMcbEntryOffset = 0;
1335
1336 while (TRUE) {
1337
1338 CdAddAllocationFromDirent( IrpContext,
1339 Fcb,
1340 CurrentMcbEntryOffset,
1341 CurrentFileOffset,
1342 &CurrentCompoundDirent->Dirent );
1343
1344 //
1345 // Break out if we are at the last dirent.
1346 //
1347
1348 if (!FlagOn( CurrentCompoundDirent->Dirent.DirentFlags, CD_ATTRIBUTE_MULTI )) {
1349
1350 break;
1351 }
1352
1353 CurrentFileOffset += CurrentCompoundDirent->Dirent.DataLength;
1354 CurrentMcbEntryOffset += 1;
1355
1356 //
1357 // We better be able to find the next dirent.
1358 //
1359
1360 if (!CdLookupNextDirent( IrpContext,
1361 ParentFcb,
1362 &CurrentCompoundDirent->DirContext,
1363 &FileContext->CurrentDirent->DirContext )) {
1364
1366 }
1367
1368 CurrentCompoundDirent = FileContext->CurrentDirent;
1369
1370 CdUpdateDirentFromRawDirent( IrpContext,
1371 ParentFcb,
1372 &CurrentCompoundDirent->DirContext,
1373 &CurrentCompoundDirent->Dirent );
1374 }
1375
1376 //
1377 // Show that the Fcb is initialized.
1378 //
1379
1381
1382 //
1383 // Link into the other in-memory structures and into the Fcb table.
1384 //
1385
1387
1388 InsertTailList( &ParentFcb->FcbQueue, &Fcb->FcbLinks );
1389
1390 CdIncrementReferenceCounts( IrpContext, ParentFcb, 1, 1 );
1391
1392 CdInsertFcbTable( IrpContext, Fcb );
1394
1395 } _SEH2_FINALLY {
1396
1397 CdUnlockFcb( IrpContext, Fcb );
1398 } _SEH2_END;
1399
1400 return;
1401}
@ Form1Data
Definition: cd.h:524
@ Mode2Form2Data
Definition: cd.h:525
#define CD_ATTRIBUTE_HIDDEN
Definition: cd.h:353
#define CD_ATTRIBUTE_MULTI
Definition: cd.h:356
#define CdConvertCdTimeToNtTime(IC, CD, NT)
Definition: cd.h:394
VOID CdAddAllocationFromDirent(_In_ PIRP_CONTEXT IrpContext, _Inout_ PFCB Fcb, _In_ ULONG McbEntryOffset, _In_ LONGLONG StartingFileOffset, _In_ PDIRENT Dirent)
Definition: allocsup.c:335
#define CdInsertFcbTable(IC, F)
Definition: strucsup.c:129
_In_ PFCB _In_ PCD_NAME _In_ BOOLEAN _Inout_ PFILE_ENUM_CONTEXT FileContext
Definition: cdprocs.h:442
BOOLEAN CdLookupNextDirent(_In_ PIRP_CONTEXT IrpContext, _In_ PFCB Fcb, _In_ PDIRENT_ENUM_CONTEXT CurrentDirContext, _Inout_ PDIRENT_ENUM_CONTEXT NextDirContext)
Definition: dirsup.c:208
#define LlBlockAlign(V, L)
Definition: cdprocs.h:1646
#define CdIncrementReferenceCounts(IC, F, C, UC)
Definition: cdprocs.h:1317
#define FCB_STATE_MODE2FORM2_FILE
Definition: cdstruc.h:1044
#define FCB_STATE_INITIALIZED
Definition: cdstruc.h:1042
#define FCB_STATE_DA_FILE
Definition: cdstruc.h:1046
#define InsertTailList(ListHead, Entry)
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
DIRENT_ENUM_CONTEXT DirContext
Definition: cdstruc.h:1683
UCHAR DirentFlags
Definition: cdstruc.h:1613
XA_EXTENT_TYPE ExtentType
Definition: cdstruc.h:1663
PCHAR CdTime
Definition: cdstruc.h:1607
ULONG DataLength
Definition: cdstruc.h:1600
USHORT XAAttributes
Definition: cdstruc.h:1639
UCHAR XAFileNumber
Definition: cdstruc.h:1640
UCHAR XAFileNumber
Definition: cdstruc.h:989
LONGLONG CreationTime
Definition: cdstruc.h:1030
USHORT XAAttributes
Definition: cdstruc.h:983
ULONG FileAttributes
Definition: cdstruc.h:977
ERESOURCE FileResource
Definition: cdstruc.h:590
int64_t LONGLONG
Definition: typedefs.h:68
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_FILE_CORRUPT_ERROR
Definition: udferr_usr.h:168

Referenced by _Requires_lock_held_().

◆ CdInitializeFcbFromPathEntry()

VOID CdInitializeFcbFromPathEntry ( _In_ PIRP_CONTEXT  IrpContext,
_Inout_ PFCB  Fcb,
_In_opt_ PFCB  ParentFcb,
_In_ PPATH_ENTRY  PathEntry 
)

Definition at line 1136 of file strucsup.c.

1167{
1168 PAGED_CODE();
1169
1170 //
1171 // Fill in the Index specific fields of the Fcb.
1172 //
1173
1174 Fcb->StreamOffset = BytesFromBlocks( Fcb->Vcb,
1175 SectorBlockOffset( Fcb->Vcb, PathEntry->DiskOffset ));
1176
1177 Fcb->Ordinal = PathEntry->Ordinal;
1178
1179 //
1180 // Initialize the common header in the Fcb. The node type is already
1181 // present.
1182 //
1183
1184 Fcb->Resource = &Fcb->Vcb->FileResource;
1185
1186 //
1187 // Always set the sizes to one sector until we read the self-entry.
1188 //
1189
1190 Fcb->AllocationSize.QuadPart =
1191 Fcb->FileSize.QuadPart =
1192 Fcb->ValidDataLength.QuadPart = SECTOR_SIZE;
1193
1194 CdAddInitialAllocation( IrpContext,
1195 Fcb,
1196 PathEntry->DiskOffset,
1197 SECTOR_SIZE );
1198 //
1199 // State flags for this Fcb.
1200 //
1201
1203
1204 //
1205 // Link into the other in-memory structures and into the Fcb table.
1206 //
1207
1208 if (ParentFcb != NULL) {
1209
1211
1212 InsertTailList( &ParentFcb->FcbQueue, &Fcb->FcbLinks );
1213
1214 CdIncrementReferenceCounts( IrpContext, ParentFcb, 1, 1 );
1215 }
1216
1217 CdInsertFcbTable( IrpContext, Fcb );
1219
1220 return;
1221}
#define SECTOR_SIZE
Definition: fs.h:22
VOID CdAddInitialAllocation(_In_ PIRP_CONTEXT IrpContext, _Inout_ PFCB Fcb, _In_ ULONG StartingBlock, _In_ LONGLONG DataLength)
Definition: allocsup.c:484
#define SectorBlockOffset(V, LB)
Definition: cdprocs.h:1626
#define BytesFromBlocks(V, B)
Definition: cdprocs.h:1630
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705

Referenced by _Requires_lock_held_(), and CdUpdateVcbFromVolDescriptor().

◆ CdInitializeStackIrpContext()

VOID CdInitializeStackIrpContext ( _Out_ PIRP_CONTEXT  IrpContext,
_In_ PIRP_CONTEXT_LITE  IrpContextLite 
)

Definition at line 1839 of file strucsup.c.

1864{
1865 PAGED_CODE();
1866
1867 //
1868 // Zero and then initialize the structure.
1869 //
1870
1871 RtlZeroMemory( IrpContext, sizeof( IRP_CONTEXT ));
1872
1873 //
1874 // Set the proper node type code and node byte size
1875 //
1876
1877 IrpContext->NodeTypeCode = CDFS_NTC_IRP_CONTEXT;
1878 IrpContext->NodeByteSize = sizeof( IRP_CONTEXT );
1879
1880 //
1881 // Note that this is from the stack.
1882 //
1883
1884 SetFlag( IrpContext->Flags, IRP_CONTEXT_FLAG_ON_STACK );
1885
1886 //
1887 // Copy RealDevice for workque algorithms.
1888 //
1889
1890 IrpContext->RealDevice = IrpContextLite->RealDevice;
1891
1892 //
1893 // The Vcb is found in the Fcb.
1894 //
1895
1896 IrpContext->Vcb = IrpContextLite->Fcb->Vcb;
1897
1898 //
1899 // Major/Minor Function codes
1900 //
1901
1902 IrpContext->MajorFunction = IRP_MJ_CLOSE;
1903
1904 //
1905 // Set the wait parameter
1906 //
1907
1908 SetFlag( IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT );
1909
1910 return;
1911}

◆ CdInitializeVcb()

VOID CdInitializeVcb ( _In_ PIRP_CONTEXT  IrpContext,
_Inout_ PVCB  Vcb,
_In_ __drv_aliasesMem PDEVICE_OBJECT  TargetDeviceObject,
_In_ __drv_aliasesMem PVPB  Vpb,
_In_ __drv_aliasesMem PCDROM_TOC_LARGE  CdromToc,
_In_ ULONG  TocLength,
_In_ ULONG  TocTrackCount,
_In_ ULONG  TocDiskFlags,
_In_ ULONG  BlockFactor,
_In_ ULONG  MediaChangeCount 
)

Definition at line 241 of file strucsup.c.

292{
293 PAGED_CODE();
294
295 UNREFERENCED_PARAMETER( IrpContext );
296
297 //
298 // We start by first zeroing out all of the VCB, this will guarantee
299 // that any stale data is wiped clean.
300 //
301
302 RtlZeroMemory( Vcb, sizeof( VCB ));
303
304 //
305 // Set the proper node type code and node byte size.
306 //
307
308 Vcb->NodeTypeCode = CDFS_NTC_VCB;
309 Vcb->NodeByteSize = sizeof( VCB );
310
311 //
312 // Initialize the DirNotify structs. FsRtlNotifyInitializeSync can raise.
313 //
314
315 InitializeListHead( &Vcb->DirNotifyList );
316 FsRtlNotifyInitializeSync( &Vcb->NotifySync );
317
318 //
319 // Pick up a VPB right now so we know we can pull this filesystem stack
320 // off of the storage stack on demand. This can raise - if it does,
321 // uninitialize the notify structures before returning.
322 //
323
324 _SEH2_TRY {
325
327 sizeof( VPB ),
328 TAG_VPB );
329 }
331
333
334 FsRtlNotifyUninitializeSync( &Vcb->NotifySync );
335 }
336 } _SEH2_END;
337
338 //
339 // Nothing beyond this point should raise.
340 //
341
342 RtlZeroMemory( Vcb->SwapVpb, sizeof( VPB ) );
343
344 //
345 // Initialize the resource variable for the Vcb and files.
346 //
347
348 ExInitializeResourceLite( &Vcb->VcbResource );
349 ExInitializeResourceLite( &Vcb->FileResource );
350 ExInitializeFastMutex( &Vcb->VcbMutex );
351
352 //
353 // Insert this Vcb record on the CdData.VcbQueue.
354 //
355
356 InsertHeadList( &CdData.VcbQueue, &Vcb->VcbLinks );
357
358 //
359 // Set the Target Device Object and Vpb fields, referencing the
360 // Target device for the mount.
361 //
362
364 Vcb->TargetDeviceObject = TargetDeviceObject;
365 Vcb->Vpb = Vpb;
366
367 //
368 // Set the removable media flag based on the real device's
369 // characteristics
370 //
371
372 if (FlagOn( Vpb->RealDevice->Characteristics, FILE_REMOVABLE_MEDIA )) {
373
375 }
376
377 //
378 // Initialize the generic Fcb Table.
379 //
380
381 RtlInitializeGenericTable( &Vcb->FcbTable,
385 NULL );
386
387 //
388 // Show that we have a mount in progress.
389 //
390
392
393 //
394 // Refererence the Vcb for two reasons. The first is a reference
395 // that prevents the Vcb from going away on the last close unless
396 // dismount has already occurred. The second is to make sure
397 // we don't go into the dismount path on any error during mount
398 // until we get to the Mount cleanup.
399 //
400
401 Vcb->VcbReference = 1 + CDFS_RESIDUAL_REFERENCE;
402
403 //
404 // Update the TOC information in the Vcb.
405 //
406
407 Vcb->CdromToc = CdromToc;
408 Vcb->TocLength = TocLength;
409 Vcb->TrackCount = TocTrackCount;
410 Vcb->DiskFlags = TocDiskFlags;
411
412 //
413 // If this disk contains audio tracks only then set the audio flag.
414 //
415
416 if (TocDiskFlags == CDROM_DISK_AUDIO_TRACK) {
417
419 }
420
421 //
422 // Set the block factor.
423 //
424
425 Vcb->BlockFactor = BlockFactor;
426
427 //
428 // Set the media change count on the device
429 //
430
431 CdUpdateMediaChangeCount( Vcb, MediaChangeCount);
432}
#define CDFS_RESIDUAL_REFERENCE
Definition: cddata.h:43
RTL_GENERIC_COMPARE_ROUTINE CdFcbTableCompare
Definition: strucsup.c:167
RTL_GENERIC_FREE_ROUTINE CdDeallocateFcbTable
Definition: strucsup.c:188
RTL_GENERIC_ALLOCATE_ROUTINE CdAllocateFcbTable
Definition: strucsup.c:178
#define CdUpdateMediaChangeCount(V, C)
Definition: cdprocs.h:1448
#define CdUpdateVcbCondition(V, C)
Definition: cdprocs.h:1449
#define TAG_VPB
Definition: cdprocs.h:106
#define VCB_STATE_REMOVABLE_MEDIA
Definition: cdstruc.h:710
#define VCB_STATE_CDXA
Definition: cdstruc.h:711
#define VCB_STATE_AUDIO_DISK
Definition: cdstruc.h:712
struct _VCB VCB
@ VcbMountInProgress
Definition: cdstruc.h:491
#define CDFS_NTC_VCB
Definition: nodetype.h:28
#define InsertHeadList(ListHead, Entry)
IN OUT PVCB IN PDEVICE_OBJECT TargetDeviceObject
Definition: fatprocs.h:1675
IN OUT PVCB IN PDEVICE_OBJECT IN PVPB Vpb
Definition: fatprocs.h:1676
VOID NTAPI RtlInitializeGenericTable(IN PRTL_GENERIC_TABLE Table, IN PRTL_GENERIC_COMPARE_ROUTINE CompareRoutine, IN PRTL_GENERIC_ALLOCATE_ROUTINE AllocateRoutine, IN PRTL_GENERIC_FREE_ROUTINE FreeRoutine, IN PVOID TableContext)
Definition: generictable.c:100
#define FILE_REMOVABLE_MEDIA
Definition: nt_native.h:807
#define CDROM_DISK_AUDIO_TRACK
Definition: ntddcdrm.h:145
VOID NTAPI FsRtlNotifyInitializeSync(IN PNOTIFY_SYNC *NotifySync)
Definition: notify.c:1590
#define _SEH2_AbnormalTermination()
Definition: pseh2_64.h:166
LIST_ENTRY VcbQueue
Definition: cdstruc.h:334
Definition: iotypes.h:189
#define ObReferenceObject
Definition: obfuncs.h:204
RTL_GENERIC_FREE_ROUTINE * PRTL_GENERIC_FREE_ROUTINE
Definition: rtltypes.h:488
RTL_GENERIC_COMPARE_ROUTINE * PRTL_GENERIC_COMPARE_ROUTINE
Definition: rtltypes.h:471
RTL_GENERIC_ALLOCATE_ROUTINE * PRTL_GENERIC_ALLOCATE_ROUTINE
Definition: rtltypes.h:480

◆ CdLookupFcbTable()

PFCB CdLookupFcbTable ( _In_ PIRP_CONTEXT  IrpContext,
_In_ PVCB  Vcb,
_In_ FILE_ID  FileId 
)

Definition at line 2107 of file strucsup.c.

2132{
2135 PFCB ReturnFcb = NULL;
2136
2137 PAGED_CODE();
2138
2139 Key.FileId = FileId;
2140
2142
2143 if (Hit != NULL) {
2144
2145 ReturnFcb = Hit->Fcb;
2146 }
2147
2148 return ReturnFcb;
2149
2150 UNREFERENCED_PARAMETER( IrpContext );
2151}
_Must_inspect_result_ NTSYSAPI PVOID NTAPI RtlLookupElementGenericTable(_In_ PRTL_GENERIC_TABLE Table, _In_ PVOID Buffer)

Referenced by _Requires_lock_held_(), and CdCreateFcb().

◆ CdProcessToc()

NTSTATUS CdProcessToc ( _In_ PIRP_CONTEXT  IrpContext,
_In_ PDEVICE_OBJECT  TargetDeviceObject,
_In_ PCDROM_TOC_LARGE  CdromToc,
_Inout_ PULONG  Length,
_Out_ PULONG  TrackCount,
_Inout_ PULONG  DiskFlags 
)

Definition at line 2201 of file strucsup.c.

2237{
2241
2242 ULONG CurrentTrack;
2243 ULONG LocalTrackCount;
2244 ULONG LocalTocLength;
2245 ULONG Address = 0;
2246 BOOLEAN UseReadToc = FALSE;
2247
2248 union {
2249
2250 UCHAR BigEndian[2];
2251 USHORT Length;
2252
2253 } BiasedTocLength;
2254
2256
2257 PAGED_CODE();
2258
2259 //
2260 // Zero the command block. This conveniently corresponds to an
2261 // LBA mode READ_TOC request.
2262 //
2263
2264 RtlZeroMemory( &Command, sizeof( Command));
2265
2266RetryReadToc:
2267
2268 //
2269 // Go ahead and read the table of contents
2270 //
2271
2272 Status = CdPerformDevIoCtrlEx( IrpContext,
2275 &Command,
2276 sizeof( Command ),
2277 CdromToc,
2278 sizeof( CDROM_TOC_LARGE ),
2279 FALSE,
2280 TRUE,
2281 &Iosb );
2282
2283 //
2284 // Nothing to process if this request fails.
2285 //
2286
2287 if (!NT_SUCCESS( Status )) {
2288
2289 //
2290 // If the underlying device does not support READ_TOC_EX, try the old method.
2291 //
2292
2293 if (!UseReadToc &&
2295 (Status == STATUS_NOT_IMPLEMENTED) || /* ReactOS Change: we return STATUS_NOT_IMPLEMENTED for IOCTL_CDROM_READ_TOC_EX */
2297
2298 UseReadToc = TRUE;
2299 goto RetryReadToc;
2300 }
2301
2302 return Status;
2303 }
2304
2305 //
2306 // Get the number of tracks and stated size of this structure.
2307 //
2308
2309 CurrentTrack = 0;
2310 LocalTrackCount = CdromToc->LastTrack - CdromToc->FirstTrack + 1;
2311 LocalTocLength = PtrOffset( CdromToc, &CdromToc->TrackData[LocalTrackCount + 1] );
2312
2313 //
2314 // Get out if there is an immediate problem with the TOC.
2315 //
2316
2317 if ((LocalTocLength > Iosb.Information) ||
2318 (CdromToc->FirstTrack > CdromToc->LastTrack)) {
2319
2321 return Status;
2322 }
2323
2324 //
2325 // Walk through the individual tracks. Stop at the first data track after
2326 // any lead-in audio tracks.
2327 //
2328
2329 do {
2330
2331 //
2332 // Get the next track.
2333 //
2334
2335 Track = &CdromToc->TrackData[CurrentTrack];
2336
2337 //
2338 // If this is a data track then check if we have only seen audio tracks
2339 // to this point.
2340 //
2341
2342 if (FlagOn( Track->Control, TOC_DATA_TRACK )) {
2343
2344 //
2345 // If we have only seen audio tracks then assume this is a
2346 // CD+ disk. Hide the current data track and only return
2347 // the previous audio tracks. Set the disk type to be mixed
2348 // data/audio.
2349 //
2350
2351 if (FlagOn( *DiskFlags, CDROM_DISK_AUDIO_TRACK ) &&
2352 !FlagOn( *DiskFlags, CDROM_DISK_DATA_TRACK )) {
2353
2354 //
2355 // Remove one track from the TOC.
2356 //
2357
2358 CdromToc->LastTrack -= 1;
2359
2360 //
2361 // Knock 2.5 minutes off the current track to hide the final leadin.
2362 // 2.5 min = 150 sec = (x 75) 11250 frames (sectors).
2363 //
2364
2365 SwapCopyUchar4( &Address, &Track->Address);
2366 Address -= 11250;
2367 SwapCopyUchar4( &Track->Address, &Address);
2368
2369 Track->TrackNumber = TOC_LAST_TRACK;
2370
2371 //
2372 // Set the disk type to mixed data/audio.
2373 //
2374
2375 SetFlag( *DiskFlags, CDROM_DISK_DATA_TRACK );
2376
2377 break;
2378 }
2379
2380 //
2381 // Set the flag to indicate data tracks present.
2382 //
2383
2384 SetFlag( *DiskFlags, CDROM_DISK_DATA_TRACK );
2385
2386 //
2387 // If this is a audio track then set the flag indicating audio
2388 // tracks.
2389 //
2390
2391 } else {
2392
2393 SetFlag( *DiskFlags, CDROM_DISK_AUDIO_TRACK );
2394 }
2395
2396 //
2397 // Set our index for the next track.
2398 //
2399
2400 CurrentTrack += 1;
2401
2402 } while (CurrentTrack < LocalTrackCount);
2403
2404 //
2405 // Set the length to point just past the last track we looked at.
2406 //
2407
2408 *TrackCount = CurrentTrack;
2409 *Length = PtrOffset( CdromToc, &CdromToc->TrackData[CurrentTrack + 1] );
2410 BiasedTocLength.Length = (USHORT) *Length - 2;
2411
2412 CdromToc->Length[0] = BiasedTocLength.BigEndian[1];
2413 CdromToc->Length[1] = BiasedTocLength.BigEndian[0];
2414
2415 return Status;
2416}
LONG NTSTATUS
Definition: precomp.h:26
#define TOC_LAST_TRACK
Definition: cd.h:100
#define TOC_DATA_TRACK
Definition: cd.h:99
#define SwapCopyUchar4(Dst, Src)
Definition: cdprocs.h:1719
NTSTATUS CdPerformDevIoCtrlEx(_In_ PIRP_CONTEXT IrpContext, _In_ ULONG IoControlCode, _In_ PDEVICE_OBJECT Device, _In_reads_bytes_opt_(InputBufferLength) PVOID InputBuffer, _In_ ULONG InputBufferLength, _Out_writes_bytes_opt_(OutputBufferLength) PVOID OutputBuffer, _In_ ULONG OutputBufferLength, _In_ BOOLEAN InternalDeviceIoControl, _In_ BOOLEAN OverrideVerify, _Out_opt_ PIO_STATUS_BLOCK Iosb)
Definition: deviosup.c:1329
#define PtrOffset(BASE, OFFSET)
Definition: cdprocs.h:1547
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
return Iosb
Definition: create.c:4402
Status
Definition: gdiplustypes.h:25
#define Track(x, y)
Definition: memtrack.h:11
#define IOCTL_CDROM_READ_TOC_EX
Definition: ntddcdrm.h:79
#define CDROM_DISK_DATA_TRACK
Definition: ntddcdrm.h:146
#define IOCTL_CDROM_READ_TOC
Definition: ntddcdrm.h:34
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
unsigned short USHORT
Definition: pedump.c:61
static WCHAR Address[46]
Definition: ping.c:68
Definition: shell.h:41
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_DISK_CORRUPT_ERROR
Definition: udferr_usr.h:147
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ CdTocSerial()

ULONG CdTocSerial ( _In_ PIRP_CONTEXT  IrpContext,
_In_ PCDROM_TOC_LARGE  CdromToc 
)

Definition at line 2779 of file strucsup.c.

2807{
2808 ULONG SerialNumber = 0;
2809 PTRACK_DATA ThisTrack;
2810 PTRACK_DATA LastTrack;
2811 ULONG Address;
2812 ULONG MsfAddress = 0; // satisfy PREFIX
2813
2814 PAGED_CODE();
2815
2816 UNREFERENCED_PARAMETER( IrpContext );
2817
2818 //
2819 // Check if there are two tracks or fewer.
2820 //
2821
2822 LastTrack = &CdromToc->TrackData[ CdromToc->LastTrack - CdromToc->FirstTrack + 1];
2823 ThisTrack = &CdromToc->TrackData[0];
2824
2825 if (CdromToc->LastTrack - CdromToc->FirstTrack <= 1) {
2826
2827 SwapCopyUchar4( &Address, LastTrack->Address);
2829 }
2830 else {
2831
2832 //
2833 // Add the starting offset of each track and add to the serial number.
2834 //
2835
2836 while (ThisTrack != LastTrack) {
2837
2838 SwapCopyUchar4( &Address, ThisTrack->Address);
2839 CdLbnToMmSsFf( Address, (PUCHAR)&MsfAddress);
2840
2841 SerialNumber += MsfAddress;
2842 ThisTrack += 1;
2843 }
2844 }
2845
2846 return SerialNumber;
2847}
VOID CdLbnToMmSsFf(_In_ ULONG Blocks, _Out_writes_(3) PUCHAR Msf)
ULONG SerialNumber
Definition: rxce.c:117
UCHAR Address[4]
Definition: ntddcdrm.h:141
unsigned char * PUCHAR
Definition: typedefs.h:53

Referenced by CdUpdateVcbFromVolDescriptor().

◆ CdUpdateVcbFromVolDescriptor()

VOID CdUpdateVcbFromVolDescriptor ( _In_ PIRP_CONTEXT  IrpContext,
_Inout_ PVCB  Vcb,
_In_reads_bytes_opt_(SECTOR_SIZE) PCHAR  RawIsoVd 
)

Definition at line 436 of file strucsup.c.

463{
464 ULONG StartingBlock;
466
467 LONGLONG FileId = 0;
468
469 PRAW_DIRENT RawDirent;
470 PATH_ENTRY PathEntry;
471 PCD_MCB_ENTRY McbEntry;
472
473 BOOLEAN UnlockVcb = FALSE;
474
475 PAGED_CODE();
476
477 //
478 // Use a try-finally to facilitate cleanup.
479 //
480
481 _SEH2_TRY {
482
483 //
484 // Copy the block size and compute the various block masks.
485 // Block size must not be larger than the sector size. We will
486 // use a default of the CD physical sector size if we are not
487 // on a data-full disc.
488 //
489 // This must always be set.
490 //
491
492 Vcb->BlockSize = ( ARGUMENT_PRESENT( RawIsoVd ) ?
493 CdRvdBlkSz( RawIsoVd, Vcb->VcbState ) :
494 SECTOR_SIZE );
495
496 //
497 // We no longer accept media where blocksize != sector size.
498 //
499
500 if (Vcb->BlockSize != SECTOR_SIZE) {
501
503 }
504
505 Vcb->BlocksPerSector = SECTOR_SIZE / Vcb->BlockSize;
506 Vcb->BlockMask = Vcb->BlockSize - 1;
507 Vcb->BlockInverseMask = ~Vcb->BlockMask;
508
509 Vcb->BlockToSectorShift = 0;
510 Vcb->BlockToByteShift = SECTOR_SHIFT;
511
512 //
513 // If there is a volume descriptor then do the internal Fcb's and
514 // other Vcb fields.
515 //
516
517 if (ARGUMENT_PRESENT( RawIsoVd )) {
518
519 //
520 // Create the path table Fcb and refererence it and the Vcb.
521 //
522
523 CdLockVcb( IrpContext, Vcb );
524 UnlockVcb = TRUE;
525
526 Vcb->PathTableFcb = CdCreateFcb( IrpContext,
527 *((PFILE_ID) &FileId),
529 NULL );
530
531 CdIncrementReferenceCounts( IrpContext, Vcb->PathTableFcb, 1, 1 );
532 CdUnlockVcb( IrpContext, Vcb );
533 UnlockVcb = FALSE;
534
535 //
536 // Compute the stream offset and size of this path table.
537 //
538
539 StartingBlock = CdRvdPtLoc( RawIsoVd, Vcb->VcbState );
540
541 ByteCount = CdRvdPtSz( RawIsoVd, Vcb->VcbState );
542
543 Vcb->PathTableFcb->StreamOffset = BytesFromBlocks( Vcb,
544 SectorBlockOffset( Vcb, StartingBlock ));
545
546 Vcb->PathTableFcb->FileSize.QuadPart = (LONGLONG) (Vcb->PathTableFcb->StreamOffset +
547 ByteCount);
548
549 Vcb->PathTableFcb->ValidDataLength.QuadPart = Vcb->PathTableFcb->FileSize.QuadPart;
550
551 Vcb->PathTableFcb->AllocationSize.QuadPart = LlSectorAlign( Vcb->PathTableFcb->FileSize.QuadPart );
552
553 //
554 // Now add the mapping information.
555 //
556
557 CdLockFcb( IrpContext, Vcb->PathTableFcb );
558
559 CdAddInitialAllocation( IrpContext,
560 Vcb->PathTableFcb,
561 StartingBlock,
562 Vcb->PathTableFcb->AllocationSize.QuadPart );
563
564 CdUnlockFcb( IrpContext, Vcb->PathTableFcb );
565
566 //
567 // Point to the file resource.
568 //
569
570 Vcb->PathTableFcb->Resource = &Vcb->FileResource;
571
572 //
573 // Mark the Fcb as initialized and create the stream file for this.
574 //
575
576 SetFlag( Vcb->PathTableFcb->FcbState, FCB_STATE_INITIALIZED );
577
578 CdCreateInternalStream( IrpContext, Vcb, Vcb->PathTableFcb, &CdInternalStreamNames[0]);
579
580 //
581 // Create the root index and reference it in the Vcb.
582 //
583
584 CdLockVcb( IrpContext, Vcb );
585 UnlockVcb = TRUE;
586 Vcb->RootIndexFcb = CdCreateFcb( IrpContext,
587 *((PFILE_ID) &FileId),
589 NULL );
590
591 CdIncrementReferenceCounts( IrpContext, Vcb->RootIndexFcb, 1, 1 );
592 CdUnlockVcb( IrpContext, Vcb );
593 UnlockVcb = FALSE;
594
595 //
596 // Create the File id by hand for this Fcb.
597 //
598
599 CdSetFidPathTableOffset( Vcb->RootIndexFcb->FileId, Vcb->PathTableFcb->StreamOffset );
600 CdFidSetDirectory( Vcb->RootIndexFcb->FileId );
601
602 //
603 // Create a pseudo path table entry so we can call the initialization
604 // routine for the directory.
605 //
606
607 RawDirent = (PRAW_DIRENT) CdRvdDirent( RawIsoVd, Vcb->VcbState );
608
609 CopyUchar4( &PathEntry.DiskOffset, RawDirent->FileLoc );
610
611 PathEntry.DiskOffset += RawDirent->XarLen;
612 PathEntry.Ordinal = 1;
613 PathEntry.PathTableOffset = Vcb->PathTableFcb->StreamOffset;
614
616 Vcb->RootIndexFcb,
617 NULL,
618 &PathEntry );
619
620 //
621 // Create the stream file for the root directory.
622 //
623
624 CdCreateInternalStream( IrpContext, Vcb, Vcb->RootIndexFcb, &CdInternalStreamNames[1] );
625
626 //
627 // Now do the volume dasd Fcb. Create this and reference it in the
628 // Vcb.
629 //
630
631 CdLockVcb( IrpContext, Vcb );
632 UnlockVcb = TRUE;
633
634 Vcb->VolumeDasdFcb = CdCreateFcb( IrpContext,
635 *((PFILE_ID) &FileId),
637 NULL );
638
639 CdIncrementReferenceCounts( IrpContext, Vcb->VolumeDasdFcb, 1, 1 );
640 CdUnlockVcb( IrpContext, Vcb );
641 UnlockVcb = FALSE;
642
643 //
644 // The file size is the full disk.
645 //
646
647 StartingBlock = CdRvdVolSz( RawIsoVd, Vcb->VcbState );
648
649 Vcb->VolumeDasdFcb->FileSize.QuadPart = LlBytesFromBlocks( Vcb, StartingBlock );
650
651 Vcb->VolumeDasdFcb->AllocationSize.QuadPart =
652 Vcb->VolumeDasdFcb->ValidDataLength.QuadPart = Vcb->VolumeDasdFcb->FileSize.QuadPart;
653
654 //
655 // Now add the extent representing the volume 'by hand'.
656 //
657
658 CdLockFcb( IrpContext, Vcb->VolumeDasdFcb );
659
660 McbEntry = Vcb->VolumeDasdFcb->Mcb.McbArray;
661
662 McbEntry->FileOffset =
663 McbEntry->DiskOffset = 0;
664
665 McbEntry->ByteCount = Vcb->VolumeDasdFcb->AllocationSize.QuadPart;
666
667 McbEntry->DataBlockByteCount =
668 McbEntry->TotalBlockByteCount = McbEntry->ByteCount;
669
670 Vcb->VolumeDasdFcb->Mcb.CurrentEntryCount = 1;
671
672 CdUnlockFcb( IrpContext, Vcb->VolumeDasdFcb );
673
674 //
675 // Point to the file resource.
676 //
677
678 Vcb->VolumeDasdFcb->Resource = &Vcb->FileResource;
679
680 Vcb->VolumeDasdFcb->FileAttributes = FILE_ATTRIBUTE_READONLY;
681
682 //
683 // Mark the Fcb as initialized.
684 //
685
686 SetFlag( Vcb->VolumeDasdFcb->FcbState, FCB_STATE_INITIALIZED );
687
688 //
689 // Check and see if this is an XA disk.
690 //
691
692 if (FlagOn( Vcb->VcbState, VCB_STATE_ISO | VCB_STATE_JOLIET)
694 Add2Ptr( RawIsoVd, 0x400, PCHAR ),
695 8 )) {
696
697 SetFlag( Vcb->VcbState, VCB_STATE_CDXA );
698 }
699
700 //
701 // If this is a music disk then we want to mock this disk to make it
702 // look like ISO disk. We will create a pseudo root directory in
703 // that case.
704 //
705
706 } else if (FlagOn( Vcb->VcbState, VCB_STATE_AUDIO_DISK )) {
707
708 ULONG RootDirectorySize;
709
710 //
711 // Create the path table Fcb and refererence it and the Vcb.
712 //
713
714 CdLockVcb( IrpContext, Vcb );
715 UnlockVcb = TRUE;
716
717 Vcb->PathTableFcb = CdCreateFcb( IrpContext,
718 *((PFILE_ID) &FileId),
720 NULL );
721
722 CdIncrementReferenceCounts( IrpContext, Vcb->PathTableFcb, 1, 1 );
723 CdUnlockVcb( IrpContext, Vcb );
724 UnlockVcb = FALSE;
725
726 //
727 // We only create a pseudo entry for the root.
728 //
729
730 Vcb->PathTableFcb->FileSize.QuadPart = (LONGLONG) (FIELD_OFFSET( RAW_PATH_ISO, DirId ) + 2);
731
732 Vcb->PathTableFcb->ValidDataLength.QuadPart = Vcb->PathTableFcb->FileSize.QuadPart;
733
734 Vcb->PathTableFcb->AllocationSize.QuadPart = LlSectorAlign( Vcb->PathTableFcb->FileSize.QuadPart );
735
736 //
737 // Point to the file resource.
738 //
739
740 Vcb->PathTableFcb->Resource = &Vcb->FileResource;
741
742 //
743 // Mark the Fcb as initialized and create the stream file for this.
744 //
745
746 SetFlag( Vcb->PathTableFcb->FcbState, FCB_STATE_INITIALIZED );
747
748 CdCreateInternalStream( IrpContext, Vcb, Vcb->PathTableFcb, &CdInternalStreamNames[0]);
749
750 //
751 // Create the root index and reference it in the Vcb.
752 //
753
754 CdLockVcb( IrpContext, Vcb );
755 UnlockVcb = TRUE;
756 Vcb->RootIndexFcb = CdCreateFcb( IrpContext,
757 *((PFILE_ID) &FileId),
759 NULL );
760
761 CdIncrementReferenceCounts( IrpContext, Vcb->RootIndexFcb, 1, 1 );
762 CdUnlockVcb( IrpContext, Vcb );
763 UnlockVcb = FALSE;
764
765 //
766 // Create the File id by hand for this Fcb.
767 //
768
769 CdSetFidPathTableOffset( Vcb->RootIndexFcb->FileId, Vcb->PathTableFcb->StreamOffset );
770 CdFidSetDirectory( Vcb->RootIndexFcb->FileId );
771
772 //
773 // Create a pseudo path table entry so we can call the initialization
774 // routine for the directory.
775 //
776
777 RtlZeroMemory( &PathEntry, sizeof( PATH_ENTRY ));
778
779
780 PathEntry.Ordinal = 1;
781 PathEntry.PathTableOffset = Vcb->PathTableFcb->StreamOffset;
782
784 Vcb->RootIndexFcb,
785 NULL,
786 &PathEntry );
787
788 //
789 // Set the sizes by hand for this Fcb. It should have an entry for each track plus an
790 // entry for the root and parent.
791 //
792
793 RootDirectorySize = (Vcb->TrackCount + 2) * CdAudioDirentSize;
794 RootDirectorySize = SectorAlign( RootDirectorySize );
795
796 Vcb->RootIndexFcb->AllocationSize.QuadPart =
797 Vcb->RootIndexFcb->ValidDataLength.QuadPart =
798 Vcb->RootIndexFcb->FileSize.QuadPart = RootDirectorySize;
799
800 SetFlag( Vcb->RootIndexFcb->FcbState, FCB_STATE_INITIALIZED );
801
802 //
803 // Create the stream file for the root directory.
804 //
805
806 CdCreateInternalStream( IrpContext, Vcb, Vcb->RootIndexFcb, &CdInternalStreamNames[1] );
807
808 //
809 // Now do the volume dasd Fcb. Create this and reference it in the
810 // Vcb.
811 //
812
813 CdLockVcb( IrpContext, Vcb );
814 UnlockVcb = TRUE;
815
816 Vcb->VolumeDasdFcb = CdCreateFcb( IrpContext,
817 *((PFILE_ID) &FileId),
819 NULL );
820
821 CdIncrementReferenceCounts( IrpContext, Vcb->VolumeDasdFcb, 1, 1 );
822 CdUnlockVcb( IrpContext, Vcb );
823 UnlockVcb = FALSE;
824
825 //
826 // We won't allow raw reads on this Fcb so leave the size at
827 // zero.
828 //
829
830 //
831 // Point to the file resource.
832 //
833
834 Vcb->VolumeDasdFcb->Resource = &Vcb->FileResource;
835
836 Vcb->VolumeDasdFcb->FileAttributes = FILE_ATTRIBUTE_READONLY;
837
838 //
839 // Mark the Fcb as initialized.
840 //
841
842 SetFlag( Vcb->VolumeDasdFcb->FcbState, FCB_STATE_INITIALIZED );
843
844 //
845 // We will store a hard-coded name in the Vpb and use the toc as
846 // the serial number.
847 //
848
849 Vcb->Vpb->VolumeLabelLength = CdAudioLabelLength;
850
851 RtlCopyMemory( Vcb->Vpb->VolumeLabel,
854
855 //
856 // Find the serial number for the audio disk.
857 //
858
859 Vcb->Vpb->SerialNumber = CdTocSerial( IrpContext, Vcb->CdromToc );
860
861 //
862 // Set the ISO bit so we know how to treat the names.
863 //
864
865 SetFlag( Vcb->VcbState, VCB_STATE_ISO );
866 }
867
868 } _SEH2_FINALLY {
869
870 if (UnlockVcb) { CdUnlockVcb( IrpContext, Vcb ); }
871 } _SEH2_END;
872}
#define SECTOR_SHIFT
Definition: cd.h:32
#define CdRvdPtLoc(R, F)
Definition: cd.h:295
RAW_DIRENT * PRAW_DIRENT
Definition: cd.h:351
#define CdRvdBlkSz(R, F)
Definition: cd.h:289
#define CdRvdVolSz(R, F)
Definition: cd.h:313
#define CdRvdDirent(R, F)
Definition: cd.h:307
#define CdRvdPtSz(R, F)
Definition: cd.h:301
USHORT CdAudioLabelLength
Definition: cddata.c:70
WCHAR CdAudioLabel[]
Definition: cddata.c:69
ULONG CdAudioDirentSize
Definition: cddata.c:78
CHAR CdXaId[]
Definition: cddata.c:63
VOID CdCreateInternalStream(_In_ PIRP_CONTEXT IrpContext, _In_ PVCB Vcb, _Inout_ PFCB Fcb, _In_ PUNICODE_STRING Name)
Definition: cachesup.c:38
ULONG CdTocSerial(_In_ PIRP_CONTEXT IrpContext, _In_ PCDROM_TOC_LARGE CdromToc)
Definition: strucsup.c:2779
VOID CdInitializeFcbFromPathEntry(_In_ PIRP_CONTEXT IrpContext, _Inout_ PFCB Fcb, _In_opt_ PFCB ParentFcb, _In_ PPATH_ENTRY PathEntry)
Definition: strucsup.c:1136
UNICODE_STRING CdInternalStreamNames[]
Definition: strucsup.c:234
PFCB CdCreateFcb(_In_ PIRP_CONTEXT IrpContext, _In_ FILE_ID FileId, _In_ NODE_TYPE_CODE NodeTypeCode, _Out_opt_ PBOOLEAN FcbExisted)
Definition: strucsup.c:986
#define LlSectorAlign(L)
Definition: cdprocs.h:1584
#define CopyUchar4(Dst, Src)
Definition: cdprocs.h:1701
#define LlBytesFromBlocks(V, B)
Definition: cdprocs.h:1634
#define SectorAlign(L)
Definition: cdprocs.h:1580
#define VCB_STATE_JOLIET
Definition: cdstruc.h:708
#define VCB_STATE_ISO
Definition: cdstruc.h:707
#define CdFidSetDirectory(I)
Definition: cdstruc.h:1836
#define CdSetFidPathTableOffset(I, P)
Definition: cdstruc.h:1834
#define Add2Ptr(PTR, INC)
#define RtlEqualMemory(dst, src, len)
Definition: kdvm.h:18
Definition: cdstruc.h:200
LONGLONG ByteCount
Definition: cdstruc.h:209
LONGLONG TotalBlockByteCount
Definition: cdstruc.h:224
LONGLONG DiskOffset
Definition: cdstruc.h:208
LONGLONG DataBlockByteCount
Definition: cdstruc.h:223
LONGLONG FileOffset
Definition: cdstruc.h:215
Definition: cdstruc.h:1460
ULONG DiskOffset
Definition: cdstruc.h:1476
ULONG PathTableOffset
Definition: cdstruc.h:1469
ULONG Ordinal
Definition: cdstruc.h:1468
UCHAR FileLoc[4]
Definition: cd.h:334
UCHAR XarLen
Definition: cd.h:333
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
char * PCHAR
Definition: typedefs.h:51
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _In_ LARGE_INTEGER ByteCount
Definition: iotypes.h:1099

Variable Documentation

◆ CdAllocateFcbTable

PVOID NTAPI CdAllocateFcbTable

Definition at line 178 of file strucsup.c.

Referenced by CdInitializeVcb().

◆ CdDeallocateFcbTable

VOID NTAPI CdDeallocateFcbTable

Definition at line 188 of file strucsup.c.

Referenced by CdInitializeVcb().

◆ CdFcbTableCompare

Definition at line 167 of file strucsup.c.

Referenced by CdInitializeVcb().

◆ CdInternalStreamNames

UNICODE_STRING CdInternalStreamNames[]
Initial value:
= {
{ 24, 24, L"$PATH_TABLE$"},
{ 2, 2, L"\\"}
}
#define L(x)
Definition: ntvdm.h:50

Definition at line 234 of file strucsup.c.

Referenced by CdUpdateVcbFromVolDescriptor().