2015-09-11 04:02:21 +00:00
|
|
|
/*++
|
|
|
|
|
|
|
|
Copyright (c) 1989-2000 Microsoft Corporation
|
|
|
|
|
|
|
|
Module Name:
|
|
|
|
|
|
|
|
CdProcs.h
|
|
|
|
|
|
|
|
Abstract:
|
|
|
|
|
|
|
|
This module defines all of the globally used procedures in the Cdfs
|
|
|
|
file system.
|
|
|
|
|
|
|
|
|
|
|
|
--*/
|
|
|
|
|
|
|
|
#ifndef _CDPROCS_
|
|
|
|
#define _CDPROCS_
|
|
|
|
|
2017-11-23 20:05:28 +00:00
|
|
|
#ifdef _MSC_VER
|
2017-11-23 20:02:16 +00:00
|
|
|
#pragma warning( disable: 4127 ) // conditional expression is constant
|
|
|
|
|
|
|
|
#pragma warning( push )
|
|
|
|
#pragma warning( disable: 4201 ) // nonstandard extension used : nameless struct/union
|
|
|
|
#pragma warning( disable: 4214 ) // nonstandard extension used : bit field types
|
2017-11-23 20:05:28 +00:00
|
|
|
#endif
|
2017-11-23 20:02:16 +00:00
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
#include <ntifs.h>
|
|
|
|
|
|
|
|
#include <ntddcdrm.h>
|
|
|
|
#include <ntdddisk.h>
|
|
|
|
#include <ntddscsi.h>
|
2017-11-23 20:05:28 +00:00
|
|
|
#ifdef __REACTOS__
|
|
|
|
#include <pseh/pseh2.h>
|
|
|
|
#endif
|
2015-09-11 04:02:21 +00:00
|
|
|
|
|
|
|
#ifndef INLINE
|
|
|
|
#define INLINE __inline
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "nodetype.h"
|
2017-11-23 20:05:28 +00:00
|
|
|
#include "cd.h"
|
|
|
|
#include "cdstruc.h"
|
|
|
|
#include "cddata.h"
|
2017-11-23 20:02:16 +00:00
|
|
|
|
|
|
|
#ifdef CDFS_TELEMETRY_DATA
|
|
|
|
|
|
|
|
#include <winmeta.h>
|
|
|
|
#include <TraceLoggingProvider.h>
|
|
|
|
#include <telemetry\MicrosoftTelemetry.h>
|
|
|
|
|
|
|
|
#endif // CDFS_TELEMETRY_DATA
|
2015-09-11 04:02:21 +00:00
|
|
|
|
2017-11-23 20:05:28 +00:00
|
|
|
#ifdef _MSC_VER
|
2017-11-23 20:02:16 +00:00
|
|
|
#pragma warning( pop )
|
2017-11-23 20:05:28 +00:00
|
|
|
#endif
|
2015-09-11 04:02:21 +00:00
|
|
|
|
2020-07-18 13:31:48 +00:00
|
|
|
#ifdef __REACTOS__
|
|
|
|
// Downgrade unsupported NT6.2+ features.
|
|
|
|
#undef MdlMappingNoExecute
|
|
|
|
#define MdlMappingNoExecute 0
|
|
|
|
#define NonPagedPoolNx NonPagedPool
|
|
|
|
#define NonPagedPoolNxCacheAligned NonPagedPoolCacheAligned
|
|
|
|
#endif
|
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
//**** x86 compiler bug ****
|
|
|
|
|
|
|
|
#if defined(_M_IX86)
|
|
|
|
#undef Int64ShraMod32
|
|
|
|
#define Int64ShraMod32(a, b) ((LONGLONG)(a) >> (b))
|
|
|
|
#endif
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
#ifndef Min
|
|
|
|
#define Min(a, b) ((a) < (b) ? (a) : (b))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef Max
|
|
|
|
#define Max(a, b) ((a) > (b) ? (a) : (b))
|
|
|
|
#endif
|
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
//
|
|
|
|
// Here are the different pool tags.
|
|
|
|
//
|
|
|
|
|
2017-11-06 18:42:27 +00:00
|
|
|
#define TAG_CCB 'ccdC' // Ccb
|
|
|
|
#define TAG_CDROM_TOC 'ctdC' // TOC
|
|
|
|
#define TAG_DIRENT_NAME 'nddC' // CdName in dirent
|
|
|
|
#define TAG_ENUM_EXPRESSION 'eedC' // Search expression for enumeration
|
|
|
|
#define TAG_FCB_DATA 'dfdC' // Data Fcb
|
|
|
|
#define TAG_FCB_INDEX 'ifdC' // Index Fcb
|
|
|
|
#define TAG_FCB_NONPAGED 'nfdC' // Nonpaged Fcb
|
|
|
|
#define TAG_FCB_TABLE 'tfdC' // Fcb Table entry
|
|
|
|
#define TAG_FILE_NAME 'nFdC' // Filename buffer
|
|
|
|
#define TAG_GEN_SHORT_NAME 'sgdC' // Generated short name
|
|
|
|
#define TAG_IO_BUFFER 'fbdC' // Temporary IO buffer
|
|
|
|
#define TAG_IO_CONTEXT 'oidC' // Io context for async reads
|
|
|
|
#define TAG_IRP_CONTEXT 'cidC' // Irp Context
|
|
|
|
#define TAG_IRP_CONTEXT_LITE 'lidC' // Irp Context lite
|
|
|
|
#define TAG_MCB_ARRAY 'amdC' // Mcb array
|
|
|
|
#define TAG_PATH_ENTRY_NAME 'nPdC' // CdName in path entry
|
|
|
|
#define TAG_PREFIX_ENTRY 'epdC' // Prefix Entry
|
|
|
|
#define TAG_PREFIX_NAME 'npdC' // Prefix Entry name
|
|
|
|
#define TAG_SPANNING_PATH_TABLE 'psdC' // Buffer for spanning path table
|
|
|
|
#define TAG_UPCASE_NAME 'nudC' // Buffer for upcased name
|
|
|
|
#define TAG_VOL_DESC 'dvdC' // Buffer for volume descriptor
|
|
|
|
#define TAG_VPB 'pvdC' // Vpb allocated in filesystem
|
2015-09-11 04:02:21 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Tag all of our allocations if tagging is turned on
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifdef POOL_TAGGING
|
|
|
|
|
|
|
|
#undef FsRtlAllocatePool
|
|
|
|
#undef FsRtlAllocatePoolWithQuota
|
|
|
|
#define FsRtlAllocatePool(a,b) FsRtlAllocatePoolWithTag(a,b,'sfdC')
|
|
|
|
#define FsRtlAllocatePoolWithQuota(a,b) FsRtlAllocatePoolWithQuotaTag(a,b,'sfdC')
|
|
|
|
|
|
|
|
#endif // POOL_TAGGING
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// File access check routine, implemented in AcChkSup.c
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// BOOLEAN
|
|
|
|
// CdIllegalFcbAccess (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _In_ TYPE_OF_OPEN TypeOfOpen,
|
|
|
|
// _In_ ACCESS_MASK DesiredAccess
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
|
|
|
|
#define CdIllegalFcbAccess(IC,T,DA) ( \
|
|
|
|
BooleanFlagOn( (DA), \
|
|
|
|
((T) != UserVolumeOpen ? \
|
|
|
|
(FILE_WRITE_ATTRIBUTES | \
|
|
|
|
FILE_WRITE_DATA | \
|
|
|
|
FILE_WRITE_EA | \
|
|
|
|
FILE_ADD_FILE | \
|
|
|
|
FILE_ADD_SUBDIRECTORY | \
|
|
|
|
FILE_APPEND_DATA) : 0) | \
|
|
|
|
FILE_DELETE_CHILD | \
|
|
|
|
DELETE | \
|
|
|
|
WRITE_DAC ))
|
|
|
|
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
//
|
|
|
|
// Allocation support routines, implemented in AllocSup.c
|
|
|
|
//
|
|
|
|
// These routines are for querying allocation on individual streams.
|
|
|
|
//
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
2015-09-11 04:02:21 +00:00
|
|
|
VOID
|
|
|
|
CdLookupAllocation (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PFCB Fcb,
|
|
|
|
_In_ LONGLONG FileOffset,
|
|
|
|
_Out_ PLONGLONG DiskOffset,
|
|
|
|
_Out_ PULONG ByteCount
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdAddAllocationFromDirent (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PFCB Fcb,
|
|
|
|
_In_ ULONG McbEntryOffset,
|
|
|
|
_In_ LONGLONG StartingFileOffset,
|
|
|
|
_In_ PDIRENT Dirent
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdAddInitialAllocation (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PFCB Fcb,
|
|
|
|
_In_ ULONG StartingBlock,
|
|
|
|
_In_ LONGLONG DataLength
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdTruncateAllocation (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PFCB Fcb,
|
|
|
|
_In_ LONGLONG StartingFileOffset
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_At_(Fcb->NodeByteSize, _In_range_(>=, FIELD_OFFSET( FCB, FcbType )))
|
2015-09-11 04:02:21 +00:00
|
|
|
VOID
|
|
|
|
CdInitializeMcb (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_updates_bytes_(Fcb->NodeByteSize) PFCB Fcb
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_At_(Fcb->NodeByteSize, _In_range_(>=, FIELD_OFFSET( FCB, FcbType )))
|
|
|
|
_When_(Fcb->NodeTypeCode == CDFS_NTC_FCB_PATH_TABLE, _At_(Fcb->NodeByteSize, _In_range_(==, SIZEOF_FCB_INDEX)))
|
|
|
|
_When_(Fcb->NodeTypeCode == CDFS_NTC_FCB_INDEX, _At_(Fcb->NodeByteSize, _In_range_(==, SIZEOF_FCB_INDEX)))
|
|
|
|
_When_(Fcb->NodeTypeCode == CDFS_NTC_FCB_DATA, _At_(Fcb->NodeByteSize, _In_range_(==, SIZEOF_FCB_DATA)))
|
2015-09-11 04:02:21 +00:00
|
|
|
VOID
|
|
|
|
CdUninitializeMcb (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_updates_bytes_(Fcb->NodeByteSize) PFCB Fcb
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
//
|
|
|
|
// Buffer control routines for data caching, implemented in CacheSup.c
|
|
|
|
//
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdCreateInternalStream (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PVCB Vcb,
|
|
|
|
_Inout_ PFCB Fcb,
|
|
|
|
_In_ PUNICODE_STRING Name
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdDeleteInternalStream (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PFCB Fcb
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
CdCompleteMdl (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PIRP Irp
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
2015-09-11 04:02:21 +00:00
|
|
|
NTSTATUS
|
|
|
|
CdPurgeVolume (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PVCB Vcb,
|
|
|
|
_In_ BOOLEAN DismountUnderway
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:05:28 +00:00
|
|
|
static /* ReactOS Change: GCC "multiple definition" */
|
|
|
|
INLINE /* GCC only accepts __inline as the first modifier */
|
2017-11-23 20:02:16 +00:00
|
|
|
VOID
|
|
|
|
CdVerifyOrCreateDirStreamFile (
|
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PFCB Fcb
|
|
|
|
)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Unsafe test to see if call / lock neccessary.
|
|
|
|
//
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
if (NULL == Fcb->FileObject) {
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
CdCreateInternalStream( IrpContext,
|
|
|
|
Fcb->Vcb,
|
2021-06-11 12:29:21 +00:00
|
|
|
Fcb,
|
2017-11-23 20:02:16 +00:00
|
|
|
&Fcb->FileNamePrefix.ExactCaseName.FileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdUnpinData (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _Inout_ PBCB *Bcb
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
|
|
|
|
#define CdUnpinData(IC,B) \
|
|
|
|
if (*(B) != NULL) { CcUnpinData( *(B) ); *(B) = NULL; }
|
|
|
|
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
//
|
|
|
|
// Device I/O routines, implemented in DevIoSup.c
|
|
|
|
//
|
|
|
|
// These routines perform the actual device read and writes. They only affect
|
|
|
|
// the on disk structure and do not alter any other data structures.
|
|
|
|
//
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
|
|
|
VOID
|
|
|
|
CdFreeDirCache (
|
|
|
|
_In_ PIRP_CONTEXT IrpContext
|
|
|
|
);
|
|
|
|
|
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
2015-09-11 04:02:21 +00:00
|
|
|
NTSTATUS
|
|
|
|
CdNonCachedRead (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PFCB Fcb,
|
|
|
|
_In_ LONGLONG StartingOffset,
|
|
|
|
_In_ ULONG ByteCount
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
2015-09-11 04:02:21 +00:00
|
|
|
NTSTATUS
|
|
|
|
CdNonCachedXARead (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PFCB Fcb,
|
|
|
|
_In_ LONGLONG StartingOffset,
|
|
|
|
_In_ ULONG ByteCount
|
|
|
|
);
|
|
|
|
|
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
|
|
|
NTSTATUS
|
|
|
|
CdVolumeDasdWrite (
|
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PFCB Fcb,
|
|
|
|
_In_ LONGLONG StartingOffset,
|
|
|
|
_In_ ULONG ByteCount
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
CdReadSectors (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ LONGLONG StartingOffset,
|
|
|
|
_In_ ULONG ByteCount,
|
|
|
|
_In_ BOOLEAN ReturnError,
|
|
|
|
_Out_writes_bytes_(ByteCount) PVOID Buffer,
|
|
|
|
_In_ PDEVICE_OBJECT TargetDeviceObject
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
CdCreateUserMdl (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ ULONG BufferLength,
|
|
|
|
_In_ BOOLEAN RaiseOnError,
|
|
|
|
_In_ LOCK_OPERATION Operation
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
NTSTATUS
|
2017-11-23 20:02:16 +00:00
|
|
|
FASTCALL
|
2015-09-11 04:02:21 +00:00
|
|
|
CdPerformDevIoCtrl (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ ULONG IoControlCode,
|
|
|
|
_In_ PDEVICE_OBJECT Device,
|
|
|
|
_Out_writes_bytes_opt_(OutputBufferLength) PVOID OutputBuffer,
|
|
|
|
_In_ ULONG OutputBufferLength,
|
|
|
|
_In_ BOOLEAN InternalDeviceIoControl,
|
|
|
|
_In_ BOOLEAN OverrideVerify,
|
|
|
|
_Out_opt_ PIO_STATUS_BLOCK Iosb
|
|
|
|
);
|
|
|
|
|
|
|
|
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
|
|
|
|
);
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
CdHijackIrpAndFlushDevice (
|
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PIRP Irp,
|
|
|
|
_In_ PDEVICE_OBJECT TargetDeviceObject
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdMapUserBuffer (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext
|
|
|
|
// _Out_ PVOID UserBuffer
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// Returns pointer to sys address. Will raise on failure.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdLockUserBuffer (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _Inout_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _In_ ULONG BufferLength
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
|
|
|
|
#define CdMapUserBuffer(IC, UB) { \
|
|
|
|
*(UB) = (PVOID) ( ((IC)->Irp->MdlAddress == NULL) ? \
|
|
|
|
(IC)->Irp->UserBuffer : \
|
2017-11-23 20:02:16 +00:00
|
|
|
(MmGetSystemAddressForMdlSafe( (IC)->Irp->MdlAddress, NormalPagePriority | MdlMappingNoExecute))); \
|
2015-09-11 04:02:21 +00:00
|
|
|
if (NULL == *(UB)) { \
|
|
|
|
CdRaiseStatus( (IC), STATUS_INSUFFICIENT_RESOURCES); \
|
|
|
|
} \
|
2021-06-11 12:29:21 +00:00
|
|
|
}
|
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
#define CdLockUserBuffer(IC,BL,OP) { \
|
|
|
|
if ((IC)->Irp->MdlAddress == NULL) { \
|
|
|
|
(VOID) CdCreateUserMdl( (IC), (BL), TRUE, (OP) ); \
|
|
|
|
} \
|
2015-09-11 04:02:21 +00:00
|
|
|
}
|
|
|
|
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
//
|
|
|
|
// Dirent support routines, implemented in DirSup.c
|
|
|
|
//
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdLookupDirent (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PFCB Fcb,
|
|
|
|
_In_ ULONG DirentOffset,
|
|
|
|
_Out_ PDIRENT_ENUM_CONTEXT DirContext
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
CdLookupNextDirent (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PFCB Fcb,
|
|
|
|
_In_ PDIRENT_ENUM_CONTEXT CurrentDirContext,
|
|
|
|
_Inout_ PDIRENT_ENUM_CONTEXT NextDirContext
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2021-06-11 12:29:21 +00:00
|
|
|
_At_(Dirent->CdTime, _Post_notnull_)
|
2015-09-11 04:02:21 +00:00
|
|
|
VOID
|
|
|
|
CdUpdateDirentFromRawDirent (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PFCB Fcb,
|
|
|
|
_In_ PDIRENT_ENUM_CONTEXT DirContext,
|
|
|
|
_Inout_ PDIRENT Dirent
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdUpdateDirentName (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PDIRENT Dirent,
|
|
|
|
_In_ ULONG IgnoreCase
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Success_(return != FALSE) BOOLEAN
|
2015-09-11 04:02:21 +00:00
|
|
|
CdFindFile (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PFCB Fcb,
|
|
|
|
_In_ PCD_NAME Name,
|
|
|
|
_In_ BOOLEAN IgnoreCase,
|
|
|
|
_Inout_ PFILE_ENUM_CONTEXT FileContext,
|
|
|
|
_Out_ PCD_NAME *MatchingName
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
CdFindDirectory (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PFCB Fcb,
|
|
|
|
_In_ PCD_NAME Name,
|
|
|
|
_In_ BOOLEAN IgnoreCase,
|
|
|
|
_Inout_ PFILE_ENUM_CONTEXT FileContext
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_At_(FileContext->ShortName.FileName.MaximumLength, _In_range_(>=, BYTE_COUNT_8_DOT_3))
|
2015-09-11 04:02:21 +00:00
|
|
|
BOOLEAN
|
|
|
|
CdFindFileByShortName (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PFCB Fcb,
|
|
|
|
_In_ PCD_NAME Name,
|
|
|
|
_In_ BOOLEAN IgnoreCase,
|
|
|
|
_In_ ULONG ShortNameDirentOffset,
|
|
|
|
_Inout_ PFILE_ENUM_CONTEXT FileContext
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
CdLookupNextInitialFileDirent (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PFCB Fcb,
|
|
|
|
_Inout_ PFILE_ENUM_CONTEXT FileContext
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdLookupLastFileDirent (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PFCB Fcb,
|
|
|
|
_In_ PFILE_ENUM_CONTEXT FileContext
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdCleanupFileContext (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PFILE_ENUM_CONTEXT FileContext
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdInitializeFileContext (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _Out_ PFILE_ENUM_CONTEXT FileContext
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdInitializeDirent (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _Out_ PDIRENT Dirent
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdInitializeDirContext (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _Out_ PDIRENT_ENUM_CONTEXT DirContext
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdCleanupDirent (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _Inout_ PDIRENT Dirent
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdCleanupDirContext (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _Inout_ PDIRENT_ENUM_CONTEXT DirContext
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdLookupInitialFileDirent (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _In_ PFCB Fcb,
|
|
|
|
// _Out_ PFILE_ENUM_CONTEXT FileContext,
|
|
|
|
// _In_ ULONG DirentOffset
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
|
|
|
|
#define CdInitializeFileContext(IC,FC) { \
|
|
|
|
RtlZeroMemory( FC, sizeof( FILE_ENUM_CONTEXT )); \
|
|
|
|
(FC)->PriorDirent = &(FC)->Dirents[0]; \
|
|
|
|
(FC)->InitialDirent = &(FC)->Dirents[1]; \
|
|
|
|
(FC)->CurrentDirent = &(FC)->Dirents[2]; \
|
|
|
|
(FC)->ShortName.FileName.MaximumLength = BYTE_COUNT_8_DOT_3; \
|
|
|
|
(FC)->ShortName.FileName.Buffer = (FC)->ShortNameBuffer; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CdInitializeDirent(IC,D) \
|
|
|
|
RtlZeroMemory( D, sizeof( DIRENT ))
|
|
|
|
|
|
|
|
#define CdInitializeDirContext(IC,DC) \
|
|
|
|
RtlZeroMemory( DC, sizeof( DIRENT_ENUM_CONTEXT ))
|
|
|
|
|
|
|
|
#define CdCleanupDirent(IC,D) { \
|
|
|
|
if (FlagOn( (D)->Flags, DIRENT_FLAG_ALLOC_BUFFER )) { \
|
|
|
|
CdFreePool( &(D)->CdFileName.FileName.Buffer ); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CdCleanupDirContext(IC,DC) \
|
|
|
|
CdUnpinData( (IC), &(DC)->Bcb )
|
|
|
|
|
|
|
|
#define CdLookupInitialFileDirent(IC,F,FC,DO) \
|
|
|
|
CdLookupDirent( IC, \
|
|
|
|
F, \
|
|
|
|
DO, \
|
|
|
|
&(FC)->InitialDirent->DirContext ); \
|
|
|
|
CdUpdateDirentFromRawDirent( IC, \
|
|
|
|
F, \
|
|
|
|
&(FC)->InitialDirent->DirContext, \
|
|
|
|
&(FC)->InitialDirent->Dirent )
|
|
|
|
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
//
|
|
|
|
// The following routines are used to manipulate the fscontext fields
|
|
|
|
// of the file object, implemented in FilObSup.c
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// Type of opens. FilObSup.c depends on this order.
|
|
|
|
//
|
|
|
|
|
|
|
|
typedef enum _TYPE_OF_OPEN {
|
|
|
|
|
|
|
|
UnopenedFileObject = 0,
|
|
|
|
StreamFileOpen,
|
|
|
|
UserVolumeOpen,
|
|
|
|
UserDirectoryOpen,
|
|
|
|
UserFileOpen,
|
|
|
|
BeyondValidType
|
|
|
|
|
|
|
|
} TYPE_OF_OPEN;
|
|
|
|
typedef TYPE_OF_OPEN *PTYPE_OF_OPEN;
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_When_(TypeOfOpen == UnopenedFileObject, _At_(Fcb, _In_opt_))
|
|
|
|
_When_(TypeOfOpen != UnopenedFileObject, _At_(Fcb, _In_))
|
2015-09-11 04:02:21 +00:00
|
|
|
VOID
|
|
|
|
CdSetFileObject (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PFILE_OBJECT FileObject,
|
|
|
|
_In_ TYPE_OF_OPEN TypeOfOpen,
|
|
|
|
PFCB Fcb,
|
|
|
|
_In_opt_ PCCB Ccb
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_When_(return == UnopenedFileObject, _At_(*Fcb, _Post_null_))
|
|
|
|
_When_(return != UnopenedFileObject, _At_(Fcb, _Outptr_))
|
|
|
|
_When_(return == UnopenedFileObject, _At_(*Ccb, _Post_null_))
|
|
|
|
_When_(return != UnopenedFileObject, _At_(Ccb, _Outptr_))
|
2015-09-11 04:02:21 +00:00
|
|
|
TYPE_OF_OPEN
|
|
|
|
CdDecodeFileObject (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PFILE_OBJECT FileObject,
|
|
|
|
PFCB *Fcb,
|
|
|
|
PCCB *Ccb
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
TYPE_OF_OPEN
|
|
|
|
CdFastDecodeFileObject (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PFILE_OBJECT FileObject,
|
|
|
|
_Out_ PFCB *Fcb
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
//
|
|
|
|
// Name support routines, implemented in NameSup.c
|
|
|
|
//
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Post_satisfies_(_Old_(CdName->FileName.Length) >=
|
|
|
|
CdName->FileName.Length + CdName->VersionString.Length)
|
2015-09-11 04:02:21 +00:00
|
|
|
VOID
|
|
|
|
CdConvertNameToCdName (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PCD_NAME CdName
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdConvertBigToLittleEndian (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_reads_bytes_(ByteCount) PCHAR BigEndian,
|
|
|
|
_In_ ULONG ByteCount,
|
|
|
|
_Out_writes_bytes_(ByteCount) PCHAR LittleEndian
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdUpcaseName (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PCD_NAME Name,
|
|
|
|
_Inout_ PCD_NAME UpcaseName
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdDissectName (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PUNICODE_STRING RemainingName,
|
|
|
|
_Out_ PUNICODE_STRING FinalName
|
|
|
|
);
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
CdIsLegalName (
|
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PUNICODE_STRING FileName
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
CdIs8dot3Name (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ UNICODE_STRING FileName
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdGenerate8dot3Name (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PUNICODE_STRING FileName,
|
|
|
|
_In_ ULONG DirentOffset,
|
|
|
|
_Out_writes_bytes_to_(BYTE_COUNT_8_DOT_3, *ShortByteCount) PWCHAR ShortFileName,
|
|
|
|
_Out_ PUSHORT ShortByteCount
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
CdIsNameInExpression (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PCD_NAME CurrentName,
|
|
|
|
_In_ PCD_NAME SearchExpression,
|
|
|
|
_In_ ULONG WildcardFlags,
|
|
|
|
_In_ BOOLEAN CheckVersion
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
ULONG
|
|
|
|
CdShortNameDirentOffset (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PUNICODE_STRING Name
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
FSRTL_COMPARISON_RESULT
|
|
|
|
CdFullCompareNames (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PUNICODE_STRING NameA,
|
|
|
|
_In_ PUNICODE_STRING NameB
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
//
|
|
|
|
// Filesystem control operations. Implemented in Fsctrl.c
|
|
|
|
//
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
|
|
|
_Requires_lock_held_(Vcb->VcbResource)
|
2015-09-11 04:02:21 +00:00
|
|
|
NTSTATUS
|
|
|
|
CdLockVolumeInternal (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PVCB Vcb,
|
|
|
|
_In_opt_ PFILE_OBJECT FileObject
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
CdUnlockVolumeInternal (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PVCB Vcb,
|
|
|
|
_In_opt_ PFILE_OBJECT FileObject
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
//
|
|
|
|
// Path table enumeration routines. Implemented in PathSup.c
|
|
|
|
//
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdLookupPathEntry (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ ULONG PathEntryOffset,
|
|
|
|
_In_ ULONG Ordinal,
|
|
|
|
_In_ BOOLEAN VerifyBounds,
|
|
|
|
_Inout_ PCOMPOUND_PATH_ENTRY CompoundPathEntry
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
CdLookupNextPathEntry (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PPATH_ENUM_CONTEXT PathContext,
|
|
|
|
_Inout_ PPATH_ENTRY PathEntry
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2021-06-11 12:29:21 +00:00
|
|
|
_Success_(return != FALSE)
|
2015-09-11 04:02:21 +00:00
|
|
|
BOOLEAN
|
|
|
|
CdFindPathEntry (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PFCB ParentFcb,
|
|
|
|
_In_ PCD_NAME DirName,
|
|
|
|
_In_ BOOLEAN IgnoreCase,
|
|
|
|
_Inout_ PCOMPOUND_PATH_ENTRY CompoundPathEntry
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdUpdatePathEntryName (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PPATH_ENTRY PathEntry,
|
|
|
|
_In_ BOOLEAN IgnoreCase
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdInitializeCompoundPathEntry (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _Out_ PCOMPOUND_PATH_ENTRY CompoundPathEntry
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdCleanupCompoundPathEntry (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _Out_ PCOMPOUND_PATH_ENTRY CompoundPathEntry
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
|
|
|
|
#define CdInitializeCompoundPathEntry(IC,CP) \
|
|
|
|
RtlZeroMemory( CP, sizeof( COMPOUND_PATH_ENTRY ))
|
|
|
|
|
|
|
|
#define CdCleanupCompoundPathEntry(IC,CP) { \
|
|
|
|
CdUnpinData( (IC), &(CP)->PathContext.Bcb ); \
|
|
|
|
if ((CP)->PathContext.AllocatedData) { \
|
|
|
|
CdFreePool( &(CP)->PathContext.Data ); \
|
|
|
|
} \
|
|
|
|
if (FlagOn( (CP)->PathEntry.Flags, PATH_ENTRY_FLAG_ALLOC_BUFFER )) { \
|
|
|
|
CdFreePool( &(CP)->PathEntry.CdDirName.FileName.Buffer ); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
//
|
|
|
|
// Largest matching prefix searching routines, implemented in PrefxSup.c
|
|
|
|
//
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdInsertPrefix (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PFCB Fcb,
|
|
|
|
_In_ PCD_NAME Name,
|
|
|
|
_In_ BOOLEAN IgnoreCase,
|
|
|
|
_In_ BOOLEAN ShortNameMatch,
|
|
|
|
_Inout_ PFCB ParentFcb
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdRemovePrefix (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PFCB Fcb
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
2015-09-11 04:02:21 +00:00
|
|
|
VOID
|
|
|
|
CdFindPrefix (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PFCB *CurrentFcb,
|
|
|
|
_Inout_ PUNICODE_STRING RemainingName,
|
|
|
|
_In_ BOOLEAN IgnoreCase
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
//
|
|
|
|
// Synchronization routines. Implemented in Resrcsup.c
|
|
|
|
//
|
|
|
|
// The following routines/macros are used to synchronize the in-memory structures.
|
|
|
|
//
|
|
|
|
// Routine/Macro Synchronizes Subsequent
|
|
|
|
//
|
|
|
|
// CdAcquireCdData Volume Mounts/Dismounts,Vcb Queue CdReleaseCdData
|
|
|
|
// CdAcquireVcbExclusive Vcb for open/close CdReleaseVcb
|
|
|
|
// CdAcquireVcbShared Vcb for open/close CdReleaseVcb
|
|
|
|
// CdAcquireAllFiles Locks out operations to all files CdReleaseAllFiles
|
|
|
|
// CdAcquireFileExclusive Locks out file operations CdReleaseFile
|
|
|
|
// CdAcquireFileShared Files for file operations CdReleaseFile
|
|
|
|
// CdAcquireFcbExclusive Fcb for open/close CdReleaseFcb
|
|
|
|
// CdAcquireFcbShared Fcb for open/close CdReleaseFcb
|
|
|
|
// CdLockCdData Fields in CdData CdUnlockCdData
|
|
|
|
// CdLockVcb Vcb fields, FcbReference, FcbTable CdUnlockVcb
|
|
|
|
// CdLockFcb Fcb fields, prefix table, Mcb CdUnlockFcb
|
|
|
|
//
|
|
|
|
|
|
|
|
typedef enum _TYPE_OF_ACQUIRE {
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
AcquireExclusive,
|
|
|
|
AcquireShared,
|
|
|
|
AcquireSharedStarveExclusive
|
|
|
|
|
|
|
|
} TYPE_OF_ACQUIRE, *PTYPE_OF_ACQUIRE;
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
|
|
|
_When_(Type == AcquireExclusive && return != FALSE, _Acquires_exclusive_lock_(*Resource))
|
|
|
|
_When_(Type == AcquireShared && return != FALSE, _Acquires_shared_lock_(*Resource))
|
|
|
|
_When_(Type == AcquireSharedStarveExclusive && return != FALSE, _Acquires_shared_lock_(*Resource))
|
|
|
|
_When_(IgnoreWait == FALSE, _Post_satisfies_(return == TRUE))
|
2015-09-11 04:02:21 +00:00
|
|
|
BOOLEAN
|
|
|
|
CdAcquireResource (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PERESOURCE Resource,
|
|
|
|
_In_ BOOLEAN IgnoreWait,
|
|
|
|
_In_ TYPE_OF_ACQUIRE Type
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
//
|
|
|
|
// BOOLEAN
|
|
|
|
// CdAcquireCdData (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdReleaseCdData (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// BOOLEAN
|
|
|
|
// CdAcquireVcbExclusive (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _Inout_ PVCB Vcb,
|
|
|
|
// _In_ BOOLEAN IgnoreWait
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// BOOLEAN
|
|
|
|
// CdAcquireVcbShared (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _Inout_ PVCB Vcb,
|
|
|
|
// _In_ BOOLEAN IgnoreWait
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdReleaseVcb (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _Inout_ PVCB Vcb
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdAcquireAllFiles (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT,
|
|
|
|
// _In_ PVCB Vcb
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdReleaseAllFiles (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT,
|
|
|
|
// _In_ PVCB Vcb
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdAcquireFileExclusive (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _Inout_ PFCB Fcb,
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdAcquireFileShared (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _Inout_ PFCB Fcb
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdReleaseFile (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _Inout_ PFCB Fcb
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// BOOLEAN
|
|
|
|
// CdAcquireFcbExclusive (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _Inout_ PFCB Fcb,
|
|
|
|
// _In_ BOOLEAN IgnoreWait
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// BOOLEAN
|
|
|
|
// CdAcquireFcbShared (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _Inout_ PFCB Fcb,
|
|
|
|
// _In_ BOOLEAN IgnoreWait
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// BOOLEAN
|
|
|
|
// CdReleaseFcb (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _Inout_ PFCB Fcb
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdLockCdData (
|
|
|
|
// );
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdUnlockCdData (
|
|
|
|
// );
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdLockVcb (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdUnlockVcb (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdLockFcb (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _Inout_ PFCB Fcb
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdUnlockFcb (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _Inout_ PFCB Fcb
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
|
|
|
|
#define CdAcquireCacheForRead( IC) \
|
|
|
|
ExAcquireResourceSharedLite( &(IC)->Vcb->SectorCacheResource, TRUE)
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
#define CdAcquireCacheForUpdate( IC) \
|
|
|
|
ExAcquireResourceExclusiveLite( &(IC)->Vcb->SectorCacheResource, TRUE)
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
#define CdReleaseCache( IC) \
|
|
|
|
ExReleaseResourceLite( &(IC)->Vcb->SectorCacheResource);
|
|
|
|
|
|
|
|
#define CdConvertCacheToShared( IC) \
|
|
|
|
ExConvertExclusiveToSharedLite( &(IC)->Vcb->SectorCacheResource);
|
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
#define CdAcquireCdData(IC) \
|
|
|
|
ExAcquireResourceExclusiveLite( &CdData.DataResource, TRUE )
|
|
|
|
|
|
|
|
#define CdReleaseCdData(IC) \
|
|
|
|
ExReleaseResourceLite( &CdData.DataResource )
|
|
|
|
|
|
|
|
#define CdAcquireVcbExclusive(IC,V,I) \
|
|
|
|
CdAcquireResource( (IC), &(V)->VcbResource, (I), AcquireExclusive )
|
|
|
|
|
|
|
|
#define CdAcquireVcbShared(IC,V,I) \
|
|
|
|
CdAcquireResource( (IC), &(V)->VcbResource, (I), AcquireShared )
|
|
|
|
|
|
|
|
#define CdReleaseVcb(IC,V) \
|
|
|
|
ExReleaseResourceLite( &(V)->VcbResource )
|
|
|
|
|
|
|
|
#define CdAcquireAllFiles(IC,V) \
|
|
|
|
CdAcquireResource( (IC), &(V)->FileResource, FALSE, AcquireExclusive )
|
|
|
|
|
|
|
|
#define CdReleaseAllFiles(IC,V) \
|
|
|
|
ExReleaseResourceLite( &(V)->FileResource )
|
|
|
|
|
|
|
|
#define CdAcquireFileExclusive(IC,F) \
|
|
|
|
CdAcquireResource( (IC), (F)->Resource, FALSE, AcquireExclusive )
|
|
|
|
|
|
|
|
#define CdAcquireFileShared(IC,F) \
|
|
|
|
CdAcquireResource( (IC), (F)->Resource, FALSE, AcquireShared )
|
|
|
|
|
|
|
|
#define CdAcquireFileSharedStarveExclusive(IC,F) \
|
|
|
|
CdAcquireResource( (IC), (F)->Resource, FALSE, AcquireSharedStarveExclusive )
|
|
|
|
|
|
|
|
#define CdReleaseFile(IC,F) \
|
|
|
|
ExReleaseResourceLite( (F)->Resource )
|
|
|
|
|
|
|
|
#define CdAcquireFcbExclusive(IC,F,I) \
|
|
|
|
CdAcquireResource( (IC), &(F)->FcbNonpaged->FcbResource, (I), AcquireExclusive )
|
|
|
|
|
|
|
|
#define CdAcquireFcbShared(IC,F,I) \
|
|
|
|
CdAcquireResource( (IC), &(F)->FcbNonpaged->FcbResource, (I), AcquireShared )
|
|
|
|
|
|
|
|
#define CdReleaseFcb(IC,F) \
|
|
|
|
ExReleaseResourceLite( &(F)->FcbNonpaged->FcbResource )
|
|
|
|
|
|
|
|
#define CdLockCdData() \
|
|
|
|
ExAcquireFastMutex( &CdData.CdDataMutex ); \
|
|
|
|
CdData.CdDataLockThread = PsGetCurrentThread()
|
|
|
|
|
|
|
|
#define CdUnlockCdData() \
|
|
|
|
CdData.CdDataLockThread = NULL; \
|
|
|
|
ExReleaseFastMutex( &CdData.CdDataMutex )
|
|
|
|
|
|
|
|
#define CdLockVcb(IC,V) \
|
|
|
|
ExAcquireFastMutex( &(V)->VcbMutex ); \
|
2017-11-23 20:02:16 +00:00
|
|
|
NT_ASSERT( NULL == (V)->VcbLockThread); \
|
2015-09-11 04:02:21 +00:00
|
|
|
(V)->VcbLockThread = PsGetCurrentThread()
|
|
|
|
|
|
|
|
#define CdUnlockVcb(IC,V) \
|
2017-11-23 20:02:16 +00:00
|
|
|
NT_ASSERT( NULL != (V)->VcbLockThread); \
|
2015-09-11 04:02:21 +00:00
|
|
|
(V)->VcbLockThread = NULL; \
|
|
|
|
ExReleaseFastMutex( &(V)->VcbMutex )
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
#if defined(_PREFAST_)
|
|
|
|
|
|
|
|
_Success_(return)
|
|
|
|
_IRQL_saves_global_(OldIrql, FastMutex)
|
|
|
|
BOOLEAN DummySaveIrql(_Inout_ PFAST_MUTEX FastMutex);
|
|
|
|
|
|
|
|
_Success_(return)
|
|
|
|
_IRQL_restores_global_(OldIrql, FastMutex)
|
|
|
|
BOOLEAN DummyRestoreIrql(_Inout_ PFAST_MUTEX FastMutex);
|
|
|
|
#endif // _PREFAST_
|
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
#define CdLockFcb(IC,F) { \
|
|
|
|
PVOID _CurrentThread = PsGetCurrentThread(); \
|
|
|
|
if (_CurrentThread != (F)->FcbLockThread) { \
|
|
|
|
ExAcquireFastMutex( &(F)->FcbNonpaged->FcbMutex ); \
|
2017-11-23 20:02:16 +00:00
|
|
|
NT_ASSERT( (F)->FcbLockCount == 0 ); \
|
|
|
|
_Analysis_assume_( (F)->FcbLockCount == 0 ); \
|
2015-09-11 04:02:21 +00:00
|
|
|
(F)->FcbLockThread = _CurrentThread; \
|
|
|
|
} \
|
2017-11-23 20:02:16 +00:00
|
|
|
else \
|
|
|
|
{ \
|
|
|
|
_Analysis_assume_lock_held_( (F)->FcbNonpaged->FcbMutex ); \
|
|
|
|
_Analysis_assume_(FALSE != DummySaveIrql(&(F)->FcbNonpaged->FcbMutex)); \
|
|
|
|
} \
|
2015-09-11 04:02:21 +00:00
|
|
|
(F)->FcbLockCount += 1; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CdUnlockFcb(IC,F) { \
|
|
|
|
(F)->FcbLockCount -= 1; \
|
|
|
|
if ((F)->FcbLockCount == 0) { \
|
|
|
|
(F)->FcbLockThread = NULL; \
|
|
|
|
ExReleaseFastMutex( &(F)->FcbNonpaged->FcbMutex ); \
|
|
|
|
} \
|
2017-11-23 20:02:16 +00:00
|
|
|
else \
|
|
|
|
{ \
|
|
|
|
_Analysis_assume_lock_not_held_( (F)->FcbNonpaged->FcbMutex ); \
|
|
|
|
_Analysis_assume_(FALSE != DummyRestoreIrql(&(F)->FcbNonpaged->FcbMutex)); \
|
|
|
|
} \
|
2015-09-11 04:02:21 +00:00
|
|
|
}
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
//
|
|
|
|
// The following macro is used to retrieve the oplock structure within
|
|
|
|
// the Fcb. This structure was moved to the advanced Fcb header
|
|
|
|
// in Win8.
|
|
|
|
//
|
|
|
|
|
|
|
|
#if (NTDDI_VERSION >= NTDDI_WIN8)
|
|
|
|
|
|
|
|
#define CdGetFcbOplock(F) &(F)->Header.Oplock
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define CdGetFcbOplock(F) &(F)->Oplock
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
BOOLEAN
|
2017-11-23 20:05:28 +00:00
|
|
|
NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
|
2015-09-11 04:02:21 +00:00
|
|
|
CdNoopAcquire (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PVOID Fcb,
|
|
|
|
_In_ BOOLEAN Wait
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
2017-11-23 20:05:28 +00:00
|
|
|
NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
|
2015-09-11 04:02:21 +00:00
|
|
|
CdNoopRelease (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PVOID Fcb
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
|
|
|
_When_(return!=0, _Acquires_shared_lock_(*Fcb->Resource))
|
2015-09-11 04:02:21 +00:00
|
|
|
BOOLEAN
|
2017-11-23 20:05:28 +00:00
|
|
|
NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
|
2015-09-11 04:02:21 +00:00
|
|
|
CdAcquireForCache (
|
2017-11-23 20:02:16 +00:00
|
|
|
_Inout_ PFCB Fcb,
|
|
|
|
_In_ BOOLEAN Wait
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
|
|
|
_Releases_lock_(*Fcb->Resource)
|
2015-09-11 04:02:21 +00:00
|
|
|
VOID
|
2017-11-23 20:05:28 +00:00
|
|
|
NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
|
2015-09-11 04:02:21 +00:00
|
|
|
CdReleaseFromCache (
|
2017-11-23 20:02:16 +00:00
|
|
|
_Inout_ PFCB Fcb
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
|
|
|
NTSTATUS
|
2017-11-23 20:05:28 +00:00
|
|
|
NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
|
2017-11-23 20:02:16 +00:00
|
|
|
CdFilterCallbackAcquireForCreateSection (
|
|
|
|
_In_ PFS_FILTER_CALLBACK_DATA CallbackData,
|
|
|
|
_Unreferenced_parameter_ PVOID *CompletionContext
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Function_class_(FAST_IO_RELEASE_FILE)
|
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
2015-09-11 04:02:21 +00:00
|
|
|
VOID
|
2017-11-23 20:05:28 +00:00
|
|
|
NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
|
2015-09-11 04:02:21 +00:00
|
|
|
CdReleaseForCreateSection (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PFILE_OBJECT FileObject
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
//
|
|
|
|
// In-memory structure support routines. Implemented in StrucSup.c
|
|
|
|
//
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdInitializeVcb (
|
2017-11-23 20:02:16 +00:00
|
|
|
_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
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdUpdateVcbFromVolDescriptor (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PVCB Vcb,
|
|
|
|
_In_reads_bytes_opt_(SECTOR_SIZE) PCHAR RawIsoVd
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdDeleteVcb (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PVCB Vcb
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
PFCB
|
|
|
|
CdCreateFcb (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ FILE_ID FileId,
|
|
|
|
_In_ NODE_TYPE_CODE NodeTypeCode,
|
|
|
|
_Out_opt_ PBOOLEAN FcbExisted
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdInitializeFcbFromPathEntry (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PFCB Fcb,
|
|
|
|
_In_opt_ PFCB ParentFcb,
|
|
|
|
_In_ PPATH_ENTRY PathEntry
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdInitializeFcbFromFileContext (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PFCB Fcb,
|
|
|
|
_In_ PFCB ParentFcb,
|
|
|
|
_In_ PFILE_ENUM_CONTEXT FileContext
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
PCCB
|
|
|
|
CdCreateCcb (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PFCB Fcb,
|
|
|
|
_In_ ULONG Flags
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdDeleteCcb (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ __drv_freesMem( Pool ) PCCB Ccb
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_When_(RaiseOnError || return, _At_(Fcb->FileLock, _Post_notnull_))
|
|
|
|
_When_(RaiseOnError, _At_(IrpContext, _Pre_notnull_))
|
2015-09-11 04:02:21 +00:00
|
|
|
BOOLEAN
|
|
|
|
CdCreateFileLock (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_opt_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PFCB Fcb,
|
|
|
|
_In_ BOOLEAN RaiseOnError
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdDeleteFileLock (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PFILE_LOCK FileLock
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Ret_valid_ PIRP_CONTEXT
|
2015-09-11 04:02:21 +00:00
|
|
|
CdCreateIrpContext (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP Irp,
|
|
|
|
_In_ BOOLEAN Wait
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdCleanupIrpContext (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ BOOLEAN Post
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdInitializeStackIrpContext (
|
2017-11-23 20:02:16 +00:00
|
|
|
_Out_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PIRP_CONTEXT_LITE IrpContextLite
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
//
|
|
|
|
// PIRP_CONTEXT_LITE
|
|
|
|
// CdCreateIrpContextLite (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdFreeIrpContextLite (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _Inout_ PIRP_CONTEXT_LITE IrpContextLite
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
|
|
|
|
#define CdCreateIrpContextLite(IC) \
|
|
|
|
ExAllocatePoolWithTag( CdNonPagedPool, sizeof( IRP_CONTEXT_LITE ), TAG_IRP_CONTEXT_LITE )
|
|
|
|
|
|
|
|
#define CdFreeIrpContextLite(ICL) \
|
|
|
|
CdFreePool( &(ICL) )
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
2015-09-11 04:02:21 +00:00
|
|
|
VOID
|
|
|
|
CdTeardownStructures (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PFCB StartingFcb,
|
|
|
|
_Out_ PBOOLEAN RemovedStartingFcb
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdIncrementCleanupCounts (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _Inout_ PFCB Fcb
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdDecrementCleanupCounts (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _Inout_ PFCB Fcb
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdIncrementReferenceCounts (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _Inout_ PFCB Fcb,
|
|
|
|
// _In_ ULONG ReferenceCount
|
|
|
|
// _In_ ULONG UserReferenceCount
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdDecrementReferenceCounts (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _Inout_ PFCB Fcb,
|
|
|
|
// _In_ ULONG ReferenceCount
|
|
|
|
// _In_ ULONG UserReferenceCount
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdIncrementFcbReference (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _Inout_ PFCB Fcb
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdDecrementFcbReference (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _Inout_ PFCB Fcb
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
|
|
|
|
#define CdIncrementCleanupCounts(IC,F) { \
|
|
|
|
ASSERT_LOCKED_VCB( (F)->Vcb ); \
|
|
|
|
(F)->FcbCleanup += 1; \
|
|
|
|
(F)->Vcb->VcbCleanup += 1; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CdDecrementCleanupCounts(IC,F) { \
|
|
|
|
ASSERT_LOCKED_VCB( (F)->Vcb ); \
|
|
|
|
(F)->FcbCleanup -= 1; \
|
|
|
|
(F)->Vcb->VcbCleanup -= 1; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CdIncrementReferenceCounts(IC,F,C,UC) { \
|
|
|
|
ASSERT_LOCKED_VCB( (F)->Vcb ); \
|
|
|
|
(F)->FcbReference += (C); \
|
|
|
|
(F)->FcbUserReference += (UC); \
|
|
|
|
(F)->Vcb->VcbReference += (C); \
|
|
|
|
(F)->Vcb->VcbUserReference += (UC); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CdDecrementReferenceCounts(IC,F,C,UC) { \
|
|
|
|
ASSERT_LOCKED_VCB( (F)->Vcb ); \
|
|
|
|
(F)->FcbReference -= (C); \
|
|
|
|
(F)->FcbUserReference -= (UC); \
|
|
|
|
(F)->Vcb->VcbReference -= (C); \
|
|
|
|
(F)->Vcb->VcbUserReference -= (UC); \
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// PCD_IO_CONTEXT
|
|
|
|
// CdAllocateIoContext (
|
|
|
|
// );
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdFreeIoContext (
|
|
|
|
// PCD_IO_CONTEXT IoContext
|
|
|
|
// );
|
|
|
|
//
|
|
|
|
|
|
|
|
#define CdAllocateIoContext() \
|
|
|
|
FsRtlAllocatePoolWithTag( CdNonPagedPool, \
|
|
|
|
sizeof( CD_IO_CONTEXT ), \
|
|
|
|
TAG_IO_CONTEXT )
|
|
|
|
|
2017-11-23 20:05:28 +00:00
|
|
|
#define CdFreeIoContext(IO) CdFreePool( (PVOID) &(IO) ) /* ReactOS Change: GCC "passing argument 1 from incompatible pointer type" */
|
2015-09-11 04:02:21 +00:00
|
|
|
|
|
|
|
PFCB
|
|
|
|
CdLookupFcbTable (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PVCB Vcb,
|
|
|
|
_In_ FILE_ID FileId
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
PFCB
|
|
|
|
CdGetNextFcb (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PVCB Vcb,
|
|
|
|
_In_ PVOID *RestartKey
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
CdProcessToc (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PDEVICE_OBJECT TargetDeviceObject,
|
|
|
|
_In_ PCDROM_TOC_LARGE CdromToc,
|
|
|
|
_Inout_ PULONG Length,
|
|
|
|
_Out_ PULONG TrackCount,
|
|
|
|
_Inout_ PULONG DiskFlags
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
//
|
|
|
|
// For debugging purposes we sometimes want to allocate our structures from nonpaged
|
|
|
|
// pool so that in the kernel debugger we can walk all the structures.
|
|
|
|
//
|
|
|
|
|
|
|
|
#define CdPagedPool PagedPool
|
2017-11-23 20:02:16 +00:00
|
|
|
#define CdNonPagedPool NonPagedPoolNx
|
|
|
|
#define CdNonPagedPoolCacheAligned NonPagedPoolNxCacheAligned
|
2015-09-11 04:02:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Verification support routines. Contained in verfysup.c
|
|
|
|
//
|
|
|
|
|
2017-11-23 20:05:28 +00:00
|
|
|
static /* ReactOS Change: GCC "multiple definition" */
|
2017-11-23 20:02:16 +00:00
|
|
|
INLINE
|
2015-09-11 04:02:21 +00:00
|
|
|
BOOLEAN
|
2017-11-23 20:02:16 +00:00
|
|
|
CdOperationIsDasdOpen (
|
|
|
|
_In_ PIRP_CONTEXT IrpContext
|
2015-09-11 04:02:21 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation( IrpContext->Irp);
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
return ((IrpContext->MajorFunction == IRP_MJ_CREATE) &&
|
|
|
|
(IrpSp->FileObject->FileName.Length == 0) &&
|
|
|
|
(IrpSp->FileObject->RelatedFileObject == NULL));
|
|
|
|
}
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
2015-09-11 04:02:21 +00:00
|
|
|
NTSTATUS
|
|
|
|
CdPerformVerify (
|
2017-11-23 20:02:16 +00:00
|
|
|
_Inout_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PIRP Irp,
|
|
|
|
_In_ PDEVICE_OBJECT DeviceToVerify
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
2015-09-11 04:02:21 +00:00
|
|
|
BOOLEAN
|
|
|
|
CdCheckForDismount (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PVCB Vcb,
|
|
|
|
_In_ BOOLEAN Force
|
|
|
|
);
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
CdMarkDevForVerifyIfVcbMounted (
|
|
|
|
_Inout_ PVCB Vcb
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdVerifyVcb (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PVCB Vcb
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
CdVerifyFcbOperation (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_opt_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PFCB Fcb
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
2015-09-11 04:02:21 +00:00
|
|
|
BOOLEAN
|
|
|
|
CdDismountVcb (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PVCB Vcb
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Macros to abstract device verify flag changes.
|
|
|
|
//
|
|
|
|
|
|
|
|
#define CdUpdateMediaChangeCount( V, C) (V)->MediaChangeCount = (C)
|
|
|
|
#define CdUpdateVcbCondition( V, C) (V)->VcbCondition = (C)
|
|
|
|
|
|
|
|
#define CdMarkRealDevForVerify( DO) SetFlag( (DO)->Flags, DO_VERIFY_VOLUME)
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
#define CdMarkRealDevVerifyOk( DO) ClearFlag( (DO)->Flags, DO_VERIFY_VOLUME)
|
|
|
|
|
|
|
|
|
|
|
|
#define CdRealDevNeedsVerify( DO) BooleanFlagOn( (DO)->Flags, DO_VERIFY_VOLUME)
|
|
|
|
|
|
|
|
//
|
|
|
|
// BOOLEAN
|
|
|
|
// CdIsRawDevice (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PIRP_CONTEXT IrpContext,
|
|
|
|
// _In_ NTSTATUS Status
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
|
|
|
|
#define CdIsRawDevice(IC,S) ( \
|
|
|
|
((S) == STATUS_DEVICE_NOT_READY) || \
|
|
|
|
((S) == STATUS_NO_MEDIA_IN_DEVICE) \
|
|
|
|
)
|
|
|
|
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
//
|
|
|
|
// Work queue routines for posting and retrieving an Irp, implemented in
|
|
|
|
// workque.c
|
|
|
|
//
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
2015-09-11 04:02:21 +00:00
|
|
|
NTSTATUS
|
2017-11-23 20:02:16 +00:00
|
|
|
CdFsdPostRequest (
|
|
|
|
_Inout_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PIRP Irp
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
2015-09-11 04:02:21 +00:00
|
|
|
VOID
|
2017-11-23 20:05:28 +00:00
|
|
|
NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
|
2015-09-11 04:02:21 +00:00
|
|
|
CdPrePostIrp (
|
2017-11-23 20:02:16 +00:00
|
|
|
_Inout_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PIRP Irp
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
2015-09-11 04:02:21 +00:00
|
|
|
VOID
|
2017-11-23 20:05:28 +00:00
|
|
|
NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
|
2015-09-11 04:02:21 +00:00
|
|
|
CdOplockComplete (
|
2017-11-23 20:02:16 +00:00
|
|
|
_Inout_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PIRP Irp
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
//
|
|
|
|
// Miscellaneous support routines
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// This macro returns TRUE if a flag in a set of flags is on and FALSE
|
|
|
|
// otherwise
|
|
|
|
//
|
|
|
|
|
2017-11-23 20:05:28 +00:00
|
|
|
/* GCC complains about multi-line comments.
|
2017-11-23 20:02:16 +00:00
|
|
|
//#ifndef BooleanFlagOn
|
2015-09-11 04:02:21 +00:00
|
|
|
//#define BooleanFlagOn(F,SF) ( \
|
|
|
|
// (BOOLEAN)(((F) & (SF)) != 0) \
|
|
|
|
//)
|
|
|
|
//#endif
|
|
|
|
|
|
|
|
//#ifndef SetFlag
|
|
|
|
//#define SetFlag(Flags,SingleFlag) { \
|
|
|
|
// (Flags) |= (SingleFlag); \
|
|
|
|
//}
|
|
|
|
//#endif
|
|
|
|
|
|
|
|
//#ifndef ClearFlag
|
|
|
|
//#define ClearFlag(Flags,SingleFlag) { \
|
|
|
|
// (Flags) &= ~(SingleFlag); \
|
|
|
|
//}
|
|
|
|
//#endif
|
2017-11-23 20:05:28 +00:00
|
|
|
*/
|
2015-09-11 04:02:21 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// CAST
|
|
|
|
// Add2Ptr (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PVOID Pointer,
|
|
|
|
// _In_ ULONG Increment
|
|
|
|
// _In_ (CAST)
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// ULONG
|
|
|
|
// PtrOffset (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PVOID BasePtr,
|
|
|
|
// _In_ PVOID OffsetPtr
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
|
|
|
|
#define Add2Ptr(PTR,INC,CAST) ((CAST)((PUCHAR)(PTR) + (INC)))
|
|
|
|
|
|
|
|
#define PtrOffset(BASE,OFFSET) ((ULONG)((ULONG_PTR)(OFFSET) - (ULONG_PTR)(BASE)))
|
|
|
|
|
|
|
|
//
|
|
|
|
// This macro takes a pointer (or ulong) and returns its rounded up word
|
|
|
|
// value
|
|
|
|
//
|
|
|
|
|
|
|
|
#define WordAlign(Ptr) ( \
|
|
|
|
((((ULONG)(Ptr)) + 1) & 0xfffffffe) \
|
|
|
|
)
|
|
|
|
|
|
|
|
//
|
|
|
|
// This macro takes a pointer (or ulong) and returns its rounded up longword
|
|
|
|
// value
|
|
|
|
//
|
|
|
|
|
|
|
|
#define LongAlign(Ptr) ( \
|
|
|
|
((((ULONG)(Ptr)) + 3) & 0xfffffffc) \
|
|
|
|
)
|
|
|
|
|
|
|
|
//
|
|
|
|
// This macro takes a pointer (or ulong) and returns its rounded up quadword
|
|
|
|
// value
|
|
|
|
//
|
|
|
|
|
|
|
|
#define QuadAlign(Ptr) ( \
|
|
|
|
((((ULONG)(Ptr)) + 7) & 0xfffffff8) \
|
|
|
|
)
|
|
|
|
|
|
|
|
//
|
|
|
|
// The following macros round up and down to sector boundaries.
|
|
|
|
//
|
|
|
|
|
|
|
|
#define SectorAlign(L) ( \
|
|
|
|
((((ULONG)(L)) + (SECTOR_SIZE - 1)) & ~(SECTOR_SIZE - 1)) \
|
|
|
|
)
|
|
|
|
|
|
|
|
#define LlSectorAlign(L) ( \
|
|
|
|
((((LONGLONG)(L)) + (SECTOR_SIZE - 1)) & ~(SECTOR_SIZE - 1)) \
|
|
|
|
)
|
|
|
|
|
|
|
|
#define SectorTruncate(L) ( \
|
|
|
|
((ULONG)(L)) & ~(SECTOR_SIZE - 1) \
|
|
|
|
)
|
|
|
|
|
|
|
|
#define LlSectorTruncate(L) ( \
|
|
|
|
((LONGLONG)(L)) & ~(SECTOR_SIZE - 1) \
|
|
|
|
)
|
|
|
|
|
|
|
|
#define BytesFromSectors(L) ( \
|
|
|
|
((ULONG) (L)) << SECTOR_SHIFT \
|
|
|
|
)
|
|
|
|
|
|
|
|
#define SectorsFromBytes(L) ( \
|
|
|
|
((ULONG) (L)) >> SECTOR_SHIFT \
|
|
|
|
)
|
|
|
|
|
2017-11-23 20:05:28 +00:00
|
|
|
static /* ReactOS Change: GCC "multiple definition" */
|
2017-11-23 20:02:16 +00:00
|
|
|
INLINE
|
|
|
|
ULONG
|
2021-06-11 12:29:21 +00:00
|
|
|
SectorsFromLlBytes(
|
2017-11-23 20:02:16 +00:00
|
|
|
ULONGLONG Bytes
|
|
|
|
) {
|
|
|
|
|
|
|
|
return (ULONG)(Bytes >> SECTOR_SHIFT);
|
|
|
|
}
|
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
#define LlBytesFromSectors(L) ( \
|
|
|
|
Int64ShllMod32( (LONGLONG)(L), SECTOR_SHIFT ) \
|
|
|
|
)
|
|
|
|
|
|
|
|
#define LlSectorsFromBytes(L) ( \
|
|
|
|
Int64ShraMod32( (LONGLONG)(L), SECTOR_SHIFT ) \
|
|
|
|
)
|
|
|
|
|
|
|
|
#define SectorOffset(L) ( \
|
|
|
|
((ULONG)(ULONG_PTR) (L)) & SECTOR_MASK \
|
|
|
|
)
|
|
|
|
|
|
|
|
#define SectorBlockOffset(V,LB) ( \
|
|
|
|
((ULONG) (LB)) & ((V)->BlocksPerSector - 1) \
|
|
|
|
)
|
|
|
|
|
|
|
|
#define BytesFromBlocks(V,B) ( \
|
|
|
|
(ULONG) (B) << (V)->BlockToByteShift \
|
|
|
|
)
|
|
|
|
|
|
|
|
#define LlBytesFromBlocks(V,B) ( \
|
|
|
|
Int64ShllMod32( (LONGLONG) (B), (V)->BlockToByteShift ) \
|
|
|
|
)
|
|
|
|
|
|
|
|
#define BlockAlign(V,L) ( \
|
|
|
|
((ULONG)(L) + (V)->BlockMask) & (V)->BlockInverseMask \
|
|
|
|
)
|
|
|
|
|
|
|
|
//
|
|
|
|
// Carefully make sure the mask is sign extended to 64bits
|
|
|
|
//
|
|
|
|
|
|
|
|
#define LlBlockAlign(V,L) ( \
|
|
|
|
((LONGLONG)(L) + (V)->BlockMask) & (LONGLONG)((LONG)(V)->BlockInverseMask) \
|
|
|
|
)
|
|
|
|
|
|
|
|
#define BlockOffset(V,L) ( \
|
|
|
|
((ULONG) (L)) & (V)->BlockMask \
|
|
|
|
)
|
|
|
|
|
|
|
|
#define RawSectorAlign( B) ((((B)+(RAW_SECTOR_SIZE - 1)) / RAW_SECTOR_SIZE) * RAW_SECTOR_SIZE)
|
|
|
|
|
|
|
|
//
|
|
|
|
// The following types and macros are used to help unpack the packed and
|
|
|
|
// misaligned fields found in the Bios parameter block
|
|
|
|
//
|
|
|
|
|
|
|
|
typedef union _UCHAR1 {
|
|
|
|
UCHAR Uchar[1];
|
|
|
|
UCHAR ForceAlignment;
|
|
|
|
} UCHAR1, *PUCHAR1;
|
|
|
|
|
|
|
|
typedef union _UCHAR2 {
|
|
|
|
UCHAR Uchar[2];
|
|
|
|
USHORT ForceAlignment;
|
|
|
|
} UCHAR2, *PUCHAR2;
|
|
|
|
|
|
|
|
typedef union _UCHAR4 {
|
|
|
|
UCHAR Uchar[4];
|
|
|
|
ULONG ForceAlignment;
|
|
|
|
} UCHAR4, *PUCHAR4;
|
|
|
|
|
|
|
|
typedef union _USHORT2 {
|
|
|
|
USHORT Ushort[2];
|
|
|
|
ULONG ForceAlignment;
|
|
|
|
} USHORT2, *PUSHORT2;
|
|
|
|
|
|
|
|
//
|
|
|
|
// This macro copies an unaligned src byte to an aligned dst byte
|
|
|
|
//
|
|
|
|
|
|
|
|
#define CopyUchar1(Dst,Src) { \
|
|
|
|
*((UCHAR1 *)(Dst)) = *((UNALIGNED UCHAR1 *)(Src)); \
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// This macro copies an unaligned src word to an aligned dst word
|
|
|
|
//
|
|
|
|
|
|
|
|
#define CopyUchar2(Dst,Src) { \
|
|
|
|
*((UCHAR2 *)(Dst)) = *((UNALIGNED UCHAR2 *)(Src)); \
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// This macro copies an unaligned src longword to an aligned dsr longword
|
|
|
|
//
|
|
|
|
|
|
|
|
#define CopyUchar4(Dst,Src) { \
|
|
|
|
*((UCHAR4 *)(Dst)) = *((UNALIGNED UCHAR4 *)(Src)); \
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// This macro copies an unaligned src longword to an aligned dsr longword
|
|
|
|
// accessing the source on a word boundary.
|
|
|
|
//
|
|
|
|
|
|
|
|
#define CopyUshort2(Dst,Src) { \
|
|
|
|
*((USHORT2 *)(Dst)) = *((UNALIGNED USHORT2 *)(Src));\
|
|
|
|
}
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
//
|
|
|
|
// This macro copies an unaligned src longword to a dst longword,
|
|
|
|
// performing an little/big endian swap.
|
|
|
|
//
|
|
|
|
|
|
|
|
#define SwapCopyUchar4(Dst,Src) { \
|
|
|
|
*((UNALIGNED UCHAR1 *)(Dst)) = *((UNALIGNED UCHAR1 *)(Src) + 3); \
|
|
|
|
*((UNALIGNED UCHAR1 *)(Dst) + 1) = *((UNALIGNED UCHAR1 *)(Src) + 2); \
|
|
|
|
*((UNALIGNED UCHAR1 *)(Dst) + 2) = *((UNALIGNED UCHAR1 *)(Src) + 1); \
|
|
|
|
*((UNALIGNED UCHAR1 *)(Dst) + 3) = *((UNALIGNED UCHAR1 *)(Src)); \
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdLbnToMmSsFf (
|
|
|
|
_In_ ULONG Blocks,
|
|
|
|
_Out_writes_(3) PUCHAR Msf
|
|
|
|
);
|
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
//
|
|
|
|
// Following routines handle entry in and out of the filesystem. They are
|
|
|
|
// contained in CdData.c
|
|
|
|
//
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_IRQL_requires_max_(APC_LEVEL)
|
|
|
|
__drv_dispatchType(DRIVER_DISPATCH)
|
|
|
|
__drv_dispatchType(IRP_MJ_CREATE)
|
|
|
|
__drv_dispatchType(IRP_MJ_CLOSE)
|
|
|
|
__drv_dispatchType(IRP_MJ_READ)
|
|
|
|
__drv_dispatchType(IRP_MJ_WRITE)
|
|
|
|
__drv_dispatchType(IRP_MJ_QUERY_INFORMATION)
|
|
|
|
__drv_dispatchType(IRP_MJ_SET_INFORMATION)
|
|
|
|
__drv_dispatchType(IRP_MJ_QUERY_VOLUME_INFORMATION)
|
|
|
|
__drv_dispatchType(IRP_MJ_DIRECTORY_CONTROL)
|
|
|
|
__drv_dispatchType(IRP_MJ_FILE_SYSTEM_CONTROL)
|
|
|
|
__drv_dispatchType(IRP_MJ_DEVICE_CONTROL)
|
|
|
|
__drv_dispatchType(IRP_MJ_LOCK_CONTROL)
|
|
|
|
__drv_dispatchType(IRP_MJ_CLEANUP)
|
|
|
|
__drv_dispatchType(IRP_MJ_PNP)
|
|
|
|
__drv_dispatchType(IRP_MJ_SHUTDOWN)
|
2015-09-11 04:02:21 +00:00
|
|
|
NTSTATUS
|
2017-11-25 19:15:28 +00:00
|
|
|
NTAPI
|
2015-09-11 04:02:21 +00:00
|
|
|
CdFsdDispatch (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PDEVICE_OBJECT DeviceObject,
|
|
|
|
_Inout_ PIRP Irp
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
// DRIVER_DISPATCH CdFsdDispatch;
|
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
LONG
|
|
|
|
CdExceptionFilter (
|
2017-11-23 20:02:16 +00:00
|
|
|
_Inout_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PEXCEPTION_POINTERS ExceptionPointer
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
2015-09-11 04:02:21 +00:00
|
|
|
NTSTATUS
|
|
|
|
CdProcessException (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_opt_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PIRP Irp,
|
|
|
|
_In_ NTSTATUS ExceptionCode
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdCompleteRequest (
|
2017-11-23 20:02:16 +00:00
|
|
|
_Inout_opt_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_opt_ PIRP Irp,
|
|
|
|
_In_ NTSTATUS Status
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdRaiseStatus (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PRIP_CONTEXT IrpContext,
|
|
|
|
// _In_ NT_STATUS Status
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdNormalizeAndRaiseStatus (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _In_ PRIP_CONTEXT IrpContext,
|
|
|
|
// _In_ NT_STATUS Status
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
#define AssertVerifyDevice(C, S) \
|
2017-11-23 20:02:16 +00:00
|
|
|
NT_ASSERT( (C) == NULL || \
|
2015-09-11 04:02:21 +00:00
|
|
|
FlagOn( (C)->Flags, IRP_CONTEXT_FLAG_IN_FSP ) || \
|
|
|
|
!((S) == STATUS_VERIFY_REQUIRED && \
|
|
|
|
IoGetDeviceToVerify( PsGetCurrentThread() ) == NULL ));
|
|
|
|
|
|
|
|
#define AssertVerifyDeviceIrp(I) \
|
2017-11-23 20:02:16 +00:00
|
|
|
NT_ASSERT( (I) == NULL || \
|
2015-09-11 04:02:21 +00:00
|
|
|
!(((I)->IoStatus.Status) == STATUS_VERIFY_REQUIRED && \
|
|
|
|
((I)->Tail.Overlay.Thread == NULL || \
|
|
|
|
IoGetDeviceToVerify( (I)->Tail.Overlay.Thread ) == NULL )));
|
|
|
|
#else
|
|
|
|
#define AssertVerifyDevice(C, S)
|
|
|
|
#define AssertVerifyDeviceIrp(I)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CD_SANITY
|
|
|
|
|
|
|
|
DECLSPEC_NORETURN
|
|
|
|
VOID
|
2017-11-23 20:02:16 +00:00
|
|
|
CdRaiseStatusEx (
|
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ NTSTATUS Status,
|
|
|
|
_In_ BOOLEAN NormalizeStatus,
|
|
|
|
_In_opt_ ULONG FileId,
|
|
|
|
_In_opt_ ULONG Line
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2019-01-22 17:49:51 +00:00
|
|
|
#ifdef __REACTOS__
|
|
|
|
static // make windows gcc release build compile
|
|
|
|
#endif
|
2019-01-22 18:20:47 +00:00
|
|
|
INLINE
|
2015-09-11 04:02:21 +00:00
|
|
|
DECLSPEC_NORETURN
|
|
|
|
VOID
|
|
|
|
CdRaiseStatusEx(
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ NTSTATUS Status,
|
|
|
|
_In_ BOOLEAN NormalizeStatus,
|
|
|
|
_In_ ULONG Fileid,
|
|
|
|
_In_ ULONG Line
|
2015-09-11 04:02:21 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
if (NormalizeStatus) {
|
|
|
|
|
|
|
|
IrpContext->ExceptionStatus = FsRtlNormalizeNtstatus( Status, STATUS_UNEXPECTED_IO_ERROR);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
IrpContext->ExceptionStatus = Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
IrpContext->RaisedAtLineFile = (Fileid << 16) | Line;
|
|
|
|
|
|
|
|
ExRaiseStatus( IrpContext->ExceptionStatus );
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define CdRaiseStatus( IC, S) CdRaiseStatusEx( (IC), (S), FALSE, BugCheckFileId, __LINE__);
|
|
|
|
#define CdNormalizeAndRaiseStatus( IC, S) CdRaiseStatusEx( (IC), (S), TRUE, BugCheckFileId, __LINE__);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Following are the fast entry points.
|
|
|
|
//
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
// _Success_(return != FALSE)
|
|
|
|
// BOOLEAN
|
|
|
|
// CdFastQueryBasicInfo (
|
|
|
|
// _In_ PFILE_OBJECT FileObject,
|
|
|
|
// _In_ BOOLEAN Wait,
|
|
|
|
// _Out_ PFILE_BASIC_INFORMATION Buffer,
|
|
|
|
// _Out_ PIO_STATUS_BLOCK IoStatus,
|
|
|
|
// _In_ PDEVICE_OBJECT DeviceObject
|
|
|
|
// );
|
2015-09-11 04:02:21 +00:00
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
FAST_IO_QUERY_BASIC_INFO CdFastQueryBasicInfo;
|
2015-09-11 04:02:21 +00:00
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
// _Success_(return != FALSE)
|
|
|
|
// BOOLEAN
|
|
|
|
// CdFastQueryStdInfo (
|
|
|
|
// _In_ PFILE_OBJECT FileObject,
|
|
|
|
// _In_ BOOLEAN Wait,
|
|
|
|
// _Out_ PFILE_STANDARD_INFORMATION Buffer,
|
|
|
|
// _Out_ PIO_STATUS_BLOCK IoStatus,
|
|
|
|
// _In_ PDEVICE_OBJECT DeviceObject
|
|
|
|
// );
|
2015-09-11 04:02:21 +00:00
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
FAST_IO_QUERY_STANDARD_INFO CdFastQueryStdInfo;
|
2015-09-11 04:02:21 +00:00
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
// BOOLEAN
|
|
|
|
// CdFastLock (
|
|
|
|
// _In_ PFILE_OBJECT FileObject,
|
|
|
|
// _In_ PLARGE_INTEGER FileOffset,
|
|
|
|
// _In_ PLARGE_INTEGER Length,
|
|
|
|
// _In_ PEPROCESS ProcessId,
|
|
|
|
// _In_ ULONG Key,
|
|
|
|
// _In_ BOOLEAN FailImmediately,
|
|
|
|
// _In_ BOOLEAN ExclusiveLock,
|
|
|
|
// _Out_ PIO_STATUS_BLOCK IoStatus,
|
|
|
|
// _In_ PDEVICE_OBJECT DeviceObject
|
|
|
|
// );
|
2015-09-11 04:02:21 +00:00
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
FAST_IO_LOCK CdFastLock;
|
2015-09-11 04:02:21 +00:00
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
// BOOLEAN
|
|
|
|
// CdFastUnlockSingle (
|
|
|
|
// _In_ PFILE_OBJECT FileObject,
|
|
|
|
// _In_ PLARGE_INTEGER FileOffset,
|
|
|
|
// _In_ PLARGE_INTEGER Length,
|
|
|
|
// _In_ PEPROCESS ProcessId,
|
|
|
|
// _In_ ULONG Key,
|
|
|
|
// _Out_ PIO_STATUS_BLOCK IoStatus,
|
|
|
|
// _In_ PDEVICE_OBJECT DeviceObject
|
|
|
|
// );
|
2015-09-11 04:02:21 +00:00
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
FAST_IO_UNLOCK_SINGLE CdFastUnlockSingle;
|
|
|
|
|
|
|
|
// BOOLEAN
|
|
|
|
// CdFastUnlockAll (
|
|
|
|
// _In_ PFILE_OBJECT FileObject,
|
|
|
|
// _In_ PEPROCESS ProcessId,
|
|
|
|
// _Out_ PIO_STATUS_BLOCK IoStatus,
|
|
|
|
// _In_ PDEVICE_OBJECT DeviceObject
|
|
|
|
// );
|
|
|
|
|
|
|
|
FAST_IO_UNLOCK_ALL CdFastUnlockAll;
|
|
|
|
|
|
|
|
// BOOLEAN
|
|
|
|
// CdFastUnlockAllByKey (
|
|
|
|
// _In_ PFILE_OBJECT FileObject,
|
|
|
|
// _In_ PVOID ProcessId,
|
|
|
|
// _In_ ULONG Key,
|
|
|
|
// _Out_ PIO_STATUS_BLOCK IoStatus,
|
|
|
|
// _In_ PDEVICE_OBJECT DeviceObject
|
|
|
|
// );
|
|
|
|
|
|
|
|
FAST_IO_UNLOCK_ALL_BY_KEY CdFastUnlockAllByKey;
|
|
|
|
|
|
|
|
// BOOLEAN
|
|
|
|
// CdFastIoCheckIfPossible (
|
|
|
|
// _In_ PFILE_OBJECT FileObject,
|
|
|
|
// _In_ PLARGE_INTEGER FileOffset,
|
|
|
|
// _In_ ULONG Length,
|
|
|
|
// _In_ BOOLEAN Wait,
|
|
|
|
// _In_ ULONG LockKey,
|
|
|
|
// _In_ BOOLEAN CheckForReadOperation,
|
|
|
|
// _Out_ PIO_STATUS_BLOCK IoStatus,
|
|
|
|
// _In_ PDEVICE_OBJECT DeviceObject
|
|
|
|
// );
|
|
|
|
|
|
|
|
FAST_IO_CHECK_IF_POSSIBLE CdFastIoCheckIfPossible;
|
|
|
|
|
|
|
|
// _Success_(return != FALSE)
|
|
|
|
// BOOLEAN
|
|
|
|
// CdFastQueryNetworkInfo (
|
|
|
|
// _In_ PFILE_OBJECT FileObject,
|
|
|
|
// _In_ BOOLEAN Wait,
|
|
|
|
// _Out_ PFILE_NETWORK_OPEN_INFORMATION Buffer,
|
|
|
|
// _Out_ PIO_STATUS_BLOCK IoStatus,
|
|
|
|
// _In_ PDEVICE_OBJECT DeviceObject
|
|
|
|
// );
|
|
|
|
|
|
|
|
FAST_IO_QUERY_NETWORK_OPEN_INFO CdFastQueryNetworkInfo;
|
2015-09-11 04:02:21 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Following are the routines to handle the top level thread logic.
|
|
|
|
//
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdSetThreadContext (
|
2017-11-23 20:02:16 +00:00
|
|
|
_Inout_ PIRP_CONTEXT IrpContext,
|
|
|
|
_In_ PTHREAD_CONTEXT ThreadContext
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// VOID
|
|
|
|
// CdRestoreThreadContext (
|
2017-11-23 20:02:16 +00:00
|
|
|
// _Inout_ PIRP_CONTEXT IrpContext
|
2015-09-11 04:02:21 +00:00
|
|
|
// );
|
|
|
|
//
|
|
|
|
|
|
|
|
#define CdRestoreThreadContext(IC) \
|
|
|
|
(IC)->ThreadContext->Cdfs = 0; \
|
|
|
|
IoSetTopLevelIrp( (IC)->ThreadContext->SavedTopLevelIrp ); \
|
|
|
|
(IC)->ThreadContext = NULL
|
|
|
|
|
|
|
|
ULONG
|
|
|
|
CdSerial32 (
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_reads_bytes_(ByteCount) PCHAR Buffer,
|
|
|
|
_In_ ULONG ByteCount
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
//
|
|
|
|
// The following macro is used to determine if an FSD thread can block
|
|
|
|
// for I/O or wait for a resource. It returns TRUE if the thread can
|
|
|
|
// block and FALSE otherwise. This attribute can then be used to call
|
|
|
|
// the FSD & FSP common work routine with the proper wait value.
|
|
|
|
//
|
|
|
|
|
|
|
|
#define CanFsdWait(I) IoIsOperationSynchronous(I)
|
|
|
|
|
|
|
|
//
|
|
|
|
// The following macro is used to set the fast i/o possible bits in the
|
|
|
|
// FsRtl header.
|
|
|
|
//
|
|
|
|
// FastIoIsNotPossible - If the Fcb is bad or there are oplocks on the file.
|
|
|
|
//
|
|
|
|
// FastIoIsQuestionable - If there are file locks.
|
|
|
|
//
|
|
|
|
// FastIoIsPossible - In all other cases.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
#define CdIsFastIoPossible(F) ((BOOLEAN) \
|
|
|
|
((((F)->Vcb->VcbCondition != VcbMounted ) || \
|
2017-11-23 20:02:16 +00:00
|
|
|
!FsRtlOplockIsFastIoPossible( CdGetFcbOplock(F) )) ? \
|
2015-09-11 04:02:21 +00:00
|
|
|
\
|
|
|
|
FastIoIsNotPossible : \
|
|
|
|
\
|
|
|
|
((((F)->FileLock != NULL) && FsRtlAreThereCurrentFileLocks( (F)->FileLock )) ? \
|
|
|
|
\
|
|
|
|
FastIoIsQuestionable : \
|
|
|
|
\
|
|
|
|
FastIoIsPossible)) \
|
|
|
|
)
|
|
|
|
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
//
|
|
|
|
// The FSP level dispatch/main routine. This is the routine that takes
|
|
|
|
// IRP's off of the work queue and calls the appropriate FSP level
|
|
|
|
// work routine.
|
|
|
|
//
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
// VOID
|
|
|
|
// CdFspDispatch ( // implemented in FspDisp.c
|
|
|
|
// _Inout_ PIRP_CONTEXT IrpContext
|
|
|
|
// );
|
|
|
|
|
|
|
|
WORKER_THREAD_ROUTINE CdFspDispatch;
|
2015-09-11 04:02:21 +00:00
|
|
|
|
|
|
|
VOID
|
|
|
|
CdFspClose ( // implemented in Close.c
|
2017-11-23 20:02:16 +00:00
|
|
|
_In_opt_ PVCB Vcb
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
//
|
|
|
|
// The following routines are the entry points for the different operations
|
|
|
|
// based on the IrpSp major functions.
|
|
|
|
//
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
2015-09-11 04:02:21 +00:00
|
|
|
NTSTATUS
|
|
|
|
CdCommonCreate ( // Implemented in Create.c
|
2017-11-23 20:02:16 +00:00
|
|
|
_Inout_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PIRP Irp
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
2015-09-11 04:02:21 +00:00
|
|
|
NTSTATUS
|
|
|
|
CdCommonClose ( // Implemented in Close.c
|
2017-11-23 20:02:16 +00:00
|
|
|
_Inout_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PIRP Irp
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
2015-09-11 04:02:21 +00:00
|
|
|
NTSTATUS
|
|
|
|
CdCommonRead ( // Implemented in Read.c
|
2017-11-23 20:02:16 +00:00
|
|
|
_Inout_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PIRP Irp
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
|
|
|
NTSTATUS
|
|
|
|
CdCommonWrite ( // Implemented in Write.c
|
|
|
|
_Inout_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PIRP Irp
|
|
|
|
);
|
|
|
|
|
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
2015-09-11 04:02:21 +00:00
|
|
|
NTSTATUS
|
|
|
|
CdCommonQueryInfo ( // Implemented in FileInfo.c
|
2017-11-23 20:02:16 +00:00
|
|
|
_Inout_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PIRP Irp
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
2015-09-11 04:02:21 +00:00
|
|
|
NTSTATUS
|
|
|
|
CdCommonSetInfo ( // Implemented in FileInfo.c
|
2017-11-23 20:02:16 +00:00
|
|
|
_Inout_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PIRP Irp
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
2015-09-11 04:02:21 +00:00
|
|
|
NTSTATUS
|
|
|
|
CdCommonQueryVolInfo ( // Implemented in VolInfo.c
|
2017-11-23 20:02:16 +00:00
|
|
|
_Inout_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PIRP Irp
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
2015-09-11 04:02:21 +00:00
|
|
|
NTSTATUS
|
|
|
|
CdCommonDirControl ( // Implemented in DirCtrl.c
|
2017-11-23 20:02:16 +00:00
|
|
|
_Inout_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PIRP Irp
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
2015-09-11 04:02:21 +00:00
|
|
|
NTSTATUS
|
|
|
|
CdCommonFsControl ( // Implemented in FsCtrl.c
|
2017-11-23 20:02:16 +00:00
|
|
|
_Inout_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PIRP Irp
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
CdCommonDevControl ( // Implemented in DevCtrl.c
|
2017-11-23 20:02:16 +00:00
|
|
|
_Inout_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PIRP Irp
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
CdCommonLockControl ( // Implemented in LockCtrl.c
|
2017-11-23 20:02:16 +00:00
|
|
|
_Inout_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PIRP Irp
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
2015-09-11 04:02:21 +00:00
|
|
|
NTSTATUS
|
|
|
|
CdCommonCleanup ( // Implemented in Cleanup.c
|
2017-11-23 20:02:16 +00:00
|
|
|
_Inout_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PIRP Irp
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
2015-09-11 04:02:21 +00:00
|
|
|
NTSTATUS
|
|
|
|
CdCommonPnp ( // Implemented in Pnp.c
|
2017-11-23 20:02:16 +00:00
|
|
|
_Inout_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PIRP Irp
|
|
|
|
);
|
|
|
|
|
|
|
|
_Requires_lock_held_(_Global_critical_region_)
|
|
|
|
NTSTATUS
|
|
|
|
CdCommonShutdown ( // Implemented in Shutdown.c
|
|
|
|
_Inout_ PIRP_CONTEXT IrpContext,
|
|
|
|
_Inout_ PIRP Irp
|
2015-09-11 04:02:21 +00:00
|
|
|
);
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
//
|
|
|
|
// The following macros are used to establish the semantics needed
|
|
|
|
// to do a return from within a try-finally clause. As a rule every
|
|
|
|
// try clause must end with a label call try_exit. For example,
|
|
|
|
//
|
|
|
|
// try {
|
|
|
|
// :
|
|
|
|
// :
|
|
|
|
//
|
|
|
|
// try_exit: NOTHING;
|
|
|
|
// } finally {
|
|
|
|
//
|
|
|
|
// :
|
|
|
|
// :
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// Every return statement executed inside of a try clause should use the
|
|
|
|
// try_return macro. If the compiler fully supports the try-finally construct
|
|
|
|
// then the macro should be
|
|
|
|
//
|
|
|
|
// #define try_return(S) { return(S); }
|
|
|
|
//
|
|
|
|
// If the compiler does not support the try-finally construct then the macro
|
|
|
|
// should be
|
|
|
|
//
|
|
|
|
// #define try_return(S) { S; goto try_exit; }
|
|
|
|
//
|
|
|
|
|
2017-11-23 20:05:28 +00:00
|
|
|
#ifndef __REACTOS__
|
2017-11-06 18:55:34 +00:00
|
|
|
#define try_return(S) { S; goto try_exit; }
|
|
|
|
#define try_leave(S) { S; leave; }
|
2017-11-23 20:05:28 +00:00
|
|
|
#else
|
|
|
|
#define try_return(S) { S; goto try_exit; }
|
|
|
|
#define try_leave(S) { S; _SEH2_LEAVE; }
|
|
|
|
#endif
|
2015-09-11 04:02:21 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Encapsulate safe pool freeing
|
|
|
|
//
|
2017-11-23 20:05:28 +00:00
|
|
|
/* ReactOS Change: GCC "passing argument 1 of CdFreePool from incompatible pointer type" */
|
|
|
|
#define CdFreePool(x) _CdFreePool((PVOID*)(x))
|
2015-09-11 04:02:21 +00:00
|
|
|
|
2017-11-23 20:05:28 +00:00
|
|
|
static /* ReactOS Change: GCC "multiple definition" */
|
2017-11-23 20:02:16 +00:00
|
|
|
INLINE
|
|
|
|
VOID
|
2017-11-23 20:05:28 +00:00
|
|
|
_CdFreePool(
|
2017-11-23 20:02:16 +00:00
|
|
|
_Inout_ _At_(*Pool, __drv_freesMem(Mem) _Post_null_) PVOID *Pool
|
2015-09-11 04:02:21 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
if (*Pool != NULL) {
|
|
|
|
|
|
|
|
ExFreePool(*Pool);
|
|
|
|
*Pool = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
#ifdef CDFS_TELEMETRY_DATA
|
|
|
|
|
|
|
|
//
|
|
|
|
// CDFS Telemetry. Current implementation uses the Telemetry TraceLogging APIs.
|
|
|
|
//
|
|
|
|
// The Telemetry TraceLoggingWrite() routines use a lot of stack space. We must
|
|
|
|
// therefor wrap all our telemetry points with our own routines, and add a guard to
|
|
|
|
// make sure there's enough stack space to call these routines.
|
|
|
|
//
|
|
|
|
// These telemetry routines should not be called on high-performance code paths.
|
|
|
|
//
|
|
|
|
|
|
|
|
TRACELOGGING_DECLARE_PROVIDER( CdTelemetryProvider );
|
|
|
|
|
|
|
|
VOID
|
|
|
|
CdInitializeTelemetry (
|
|
|
|
VOID
|
|
|
|
);
|
|
|
|
|
|
|
|
DECLSPEC_NOINLINE
|
|
|
|
VOID
|
|
|
|
CdTelemetryMount (
|
|
|
|
__in PGUID VolumeGuid,
|
|
|
|
__in NTSTATUS Status,
|
|
|
|
__in PVCB Vcb
|
|
|
|
);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Every additional argument passed to TraceLoggingWrite() consumes an additional
|
|
|
|
// 16 to 32 bytes extra stack space. Having 512 bytes reserved space should be
|
|
|
|
// sufficient for up to 20 arguments or so. This will be less of course if our
|
|
|
|
// wrapper routines also declare their own local variables.
|
|
|
|
//
|
|
|
|
|
|
|
|
#define CDFS_TELEMETRY_STACK_THRESHOLD_DEFAULT 512 // for "small" telemetry points
|
|
|
|
#define CDFS_TELEMETRY_STACK_THRESHOLD_LARGE 2048 // for "large" telemetry points
|
|
|
|
|
|
|
|
INLINE
|
|
|
|
BOOLEAN
|
|
|
|
CdTelemetryGuard (
|
|
|
|
__in ULONG StackSpaceNeeded )
|
|
|
|
/*++
|
|
|
|
|
|
|
|
Routine Description:
|
|
|
|
|
|
|
|
This routine returns TRUE only when:
|
|
|
|
|
|
|
|
1) There is an ETW listener, AND
|
|
|
|
2) There is enough free stack space to safely call the Telemetry TraceLogging APIs
|
|
|
|
|
|
|
|
We'll also count how many times there wasn't enough stack space, and include this
|
|
|
|
value as part of the periodic cdfs Telemetry.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
|
|
|
|
StackSpaceNeeded - Stack space needed in bytes
|
|
|
|
|
|
|
|
--*/
|
|
|
|
{
|
|
|
|
ASSERT( IoGetRemainingStackSize() >= StackSpaceNeeded );
|
|
|
|
|
|
|
|
if (CdTelemetryProvider->LevelPlus1 <= 5) {
|
|
|
|
|
|
|
|
//
|
|
|
|
// Bail out early if there are no ETW listeners
|
|
|
|
//
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IoGetRemainingStackSize() < StackSpaceNeeded) {
|
|
|
|
|
|
|
|
//
|
|
|
|
// Count how many times it was unsafe to generate telemetry because of
|
|
|
|
// not enough stack space.
|
|
|
|
//
|
|
|
|
|
|
|
|
InterlockedIncrement( &CdTelemetryData.MissedTelemetryPoints );
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CdTelemetryMountSafe( VolumeGuid, Status, Vcb ) \
|
|
|
|
if (CdTelemetryGuard( CDFS_TELEMETRY_STACK_THRESHOLD_LARGE )) { \
|
|
|
|
CdTelemetryMount( VolumeGuid, Status, Vcb ); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#if DBG
|
|
|
|
#define CDFS_TELEMETRY_PERIODIC_INTERVAL CdTelemetryData.PeriodicInterval
|
|
|
|
#else
|
|
|
|
#define CDFS_TELEMETRY_PERIODIC_INTERVAL INTERVAL_ONE_DAY
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else // CDFS_TELEMETRY_DATA
|
|
|
|
|
|
|
|
//
|
|
|
|
// When CDFS_TELEMETRY_DATA is not defined then the CdTelemetry___Safe() routines
|
|
|
|
// expand to nothing. This minimizes the cdfs.sys binary footprint. This also
|
|
|
|
// means that the places where these Safe() routines are called do not
|
|
|
|
// have to have to be surrounded by #ifdef CDFS_TELEMETRY_DATA .. #endif
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#define CdTelemetryMountSafe( ... ) NOTHING
|
|
|
|
|
|
|
|
#endif // CDFS_TELEMETRY_DATA
|
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
#endif // _CDPROCS_
|
|
|
|
|
|
|
|
|