reactos/drivers/filesystems/cdfs_new/resrcsup.c
Joachim Henze 688875e411 [0.4.7][CDFS_NEW/NTOSKRNL/NDK] Switch from our old CDFS to MS-PL CDFS_NEW
The main motivation to switch to that newer driver is, that our old one
simply can not read all isos. Especially complex ones made trouble and were
only shown as empty in explorer.
It is still possible to build and use the old driver when needed, only thing
that needs to be done for that is to revert 0.4.8-dev-164-g ec6b3ecbe4

Porting back the state up to 0.4.8-release-100-g8f947b5 implies:

Fixing the following JIRA-IDs (or avoid introducing them):
CORE-18029 "Mute noisy DPRINT 'SectionObject has ImageSection'"
CORE-17405 "Fix a macro-copy-paste and shrink the binary size"
CORE-15659 "Unable to build the gcc Release version in Windows using RosBE 2.1.6 (module cdfs fails)"
CORE-14315 "CDFS_NEW assertion during first stage setup due to new CcPerformReadAhead"
CORE-14128 "Avast! Free Antivirus 7.0 hangs the system when trying to detect a newly created virus"
CORE-14067 "CDFS_NEW assertions and exceptions"
CORE-14003 "Shutting down LiveCD asserts since introduction of MS PL CDFS_NEW"
CORE-13184 "Restore ability to install from disk-image"

by picking the following commits:
0.4.8-release-100-g 8f947b5322 [NTOSKRNL] Mute noisy DPRINT 'SectionObject has ImageSection' CORE-18029
0.4.8-release-80-g eb1ea19588 [CDFS_NEW] == 0.4.15-dev-1456-g 889eab7 CORE-17405
0.4.8-release-62-g 8c07aad4a8 [CDFS_NEW/XDK] == 0.4.11-dev-39-g a2f9762 + 0.4.11-dev-40-g 6d7ec8c CORE-14067
0.4.8-release-3-g 5d976d04e8 [CDFS_NEW] == 0.4.12-dev-431-g bccad87f3c + 0.4.12-dev-432-g 3463b2db9f CORE-15659
0.4.8-RC-3-g 51f9494d48 [CDFS_NEW] superseded later by the proper fix 0.4.8-release-62-g 8c07aad4a8 CORE-14067
0.4.8-dev-1069-g a5e89014dc [CDFS_NEW] CORE-14315
0.4.8-dev-475-g a59d4674de [NTOSKRNL] io/iomgr/device.c (forgotten assert) CORE-14128
0.4.8-dev-221-g 9d67a24799 [CDFS_NEW]
0.4.8-dev-220-g 67a7e45e35 [CDFS_NEW/DOC]
0.4.8-dev-219-g 6a3bbf24e0 [CDFS_NEW]
0.4.8-dev-218-g ec26cde4a1 [CDFS_NEW]
0.4.8-dev-217-g bc2378a356 [CDFS_NEW]
0.4.8-dev-216-g 5429771b99 [CDFS_NEW]
0.4.8-dev-215-g fd34548263 [CDFS_NEW] Sync with MS-PL driver
0.4.8-dev-164-g ec6b3ecbe4 [FILESYSTEMS] switch from CDFS to CDFS_NEW in CMakeLists.txt
0.4.8-dev-160-g 2b217e4ecf [NTOSKRNL] Mute spam CcSetReadAheadGranularity()
0.4.8-dev-159-g 64cb138a67 [NTOSKRNL] Mute spam CcPurgeCacheSection()
0.4.8-dev-150-g f723d230a0 [CDFS_NEW]
0.4.8-dev-133-g faee3753ea [CDFS_NEW] CORE-14003
0.4.8-dev-132-g 1d777ffab5 [NTOSKRNL] iofunc.c CORE-14003
0.4.8-dev-131-g c3d5a3f2bd [NTOSKRNL] iofunc.c CORE-14003
0.4.8-dev-130-g 3b64f7f8fb [NTOSKRNL] ob/obref.c & co CORE-14003
0.4.8-dev-129-g 7eefe70294 [NTOSKRNL] io/iomgr.c & co CORE-14003
0.4.8-dev-127-g 5f255827d3 [CDFS_NEW]
0.4.8-dev-126-g 1bef48796e [NTOSKRNL] just a comment, superseded later
0.4.8-dev-125-g cbf0430b56 [CDFS_NEW]
0.4.8-dev-123-g f88fe43abd [NTOSKRNL] io/iomgr/device.c (forbidden DPRINT)
0.4.8-dev-122-g 6c73385625 [CDFS_NEW] CORE-13184
0.4.8-dev-97-g 94298313c0 [CDFS_NEW]
0.4.8-dev-95-g e88eeb21af [CDFS_NEW/NTOSKRNL] CcWaitForCurrentLazyWriterActivity() stub return Success
0.4.8-dev-94-g 03d5be6437 [CDFS_NEW]
0.4.8-dev-93-g fa1c60db50 [CDFS_NEW]
0.4.8-dev-92-g 8b2fd60829 [CDFS_NEW]
0.4.8-dev-91-g e4da7ecc50 [CDFS_NEW]
0.4.8-dev-90-g 7b19676e2b [CDFS_NEW]
0.4.8-dev-89-g 3d4b8783fd [CDFS_NEW]
0.4.8-dev-88-g 818025ecc8 [CDFS_NEW]
0.4.8-dev-87-g 2639dd6736 [CDFS_NEW]
0.4.8-dev-86-g 755bdb5d0b [CDFS_NEW]
0.4.8-dev-85-g 3cbcb1bade [CDFS_NEW]

and mute spam in opcode INSTEAD of picking:
0.4.8-dev-165-g 2284a457a3 [NTOSKRNL] oplock.c Fixup
0.4.8-dev-163-g d3d5853956 [NTOSKRNL] oplock.c Implement oplock-support
0.4.12-dev-232-g f488102c86 [CDFS] was also left out for now

I am aware, that the backport introduces white-space-glitches within CDFS_NEW.
I decided to live with them in favor of better sync to master and newer releases.
2022-01-27 21:11:23 +01:00

402 lines
8.8 KiB
C
Executable file
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*++
Copyright (c) 1989-2000 Microsoft Corporation
Module Name:
ResrcSup.c
Abstract:
This module implements the Cdfs Resource acquisition routines
--*/
#include "cdprocs.h"
//
// The Bug check file id for this module
//
#define BugCheckFileId (CDFS_BUG_CHECK_RESRCSUP)
#ifdef ALLOC_PRAGMA
#pragma alloc_text(PAGE, CdAcquireForCache)
#pragma alloc_text(PAGE, CdFilterCallbackAcquireForCreateSection)
#pragma alloc_text(PAGE, CdAcquireResource)
#pragma alloc_text(PAGE, CdNoopAcquire)
#pragma alloc_text(PAGE, CdNoopRelease)
#pragma alloc_text(PAGE, CdReleaseForCreateSection)
#pragma alloc_text(PAGE, CdReleaseFromCache)
#endif
_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))
BOOLEAN
CdAcquireResource (
_In_ PIRP_CONTEXT IrpContext,
_Inout_ PERESOURCE Resource,
_In_ BOOLEAN IgnoreWait,
_In_ TYPE_OF_ACQUIRE Type
)
/*++
Routine Description:
This is the single routine used to acquire file system resources. It
looks at the IgnoreWait flag to determine whether to try to acquire the
resource without waiting. Returning TRUE/FALSE to indicate success or
failure. Otherwise it is driven by the WAIT flag in the IrpContext and
will raise CANT_WAIT on a failure.
Arguments:
Resource - This is the resource to try and acquire.
IgnoreWait - If TRUE then this routine will not wait to acquire the
resource and will return a boolean indicating whether the resource was
acquired. Otherwise we use the flag in the IrpContext and raise
if the resource is not acquired.
Type - Indicates how we should try to get the resource.
Return Value:
BOOLEAN - TRUE if the resource is acquired. FALSE if not acquired and
IgnoreWait is specified. Otherwise we raise CANT_WAIT.
--*/
{
BOOLEAN Wait = FALSE;
BOOLEAN Acquired;
PAGED_CODE();
//
// We look first at the IgnoreWait flag, next at the flag in the Irp
// Context to decide how to acquire this resource.
//
if (!IgnoreWait && FlagOn( IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT )) {
Wait = TRUE;
}
//
// Attempt to acquire the resource either shared or exclusively.
//
switch (Type) {
case AcquireExclusive:
#ifdef _MSC_VER
#pragma prefast( suppress:28137, "prefast believes Wait should be a constant, but this is ok for CDFS" )
#endif
Acquired = ExAcquireResourceExclusiveLite( Resource, Wait );
break;
case AcquireShared:
Acquired = ExAcquireResourceSharedLite( Resource, Wait );
break;
case AcquireSharedStarveExclusive:
Acquired = ExAcquireSharedStarveExclusive( Resource, Wait );
break;
default:
Acquired = FALSE;
NT_ASSERT( FALSE );
}
//
// If not acquired and the user didn't specifiy IgnoreWait then
// raise CANT_WAIT.
//
if (!Acquired && !IgnoreWait) {
CdRaiseStatus( IrpContext, STATUS_CANT_WAIT );
}
return Acquired;
}
_Requires_lock_held_(_Global_critical_region_)
_When_(return!=0, _Acquires_shared_lock_(*Fcb->Resource))
BOOLEAN
NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
CdAcquireForCache (
_Inout_ PFCB Fcb,
_In_ BOOLEAN Wait
)
/*++
Routine Description:
The address of this routine is specified when creating a CacheMap for
a file. It is subsequently called by the Lazy Writer for synchronization.
Arguments:
Fcb - The pointer supplied as context to the cache initialization
routine.
Wait - TRUE if the caller is willing to block.
Return Value:
None
--*/
{
PAGED_CODE();
if (!ExAcquireResourceSharedLite( Fcb->Resource, Wait )) {
return FALSE;
}
NT_ASSERT(IoGetTopLevelIrp() == NULL);
IoSetTopLevelIrp((PIRP)FSRTL_CACHE_TOP_LEVEL_IRP);
return TRUE;
}
_Requires_lock_held_(_Global_critical_region_)
_Releases_lock_(*Fcb->Resource)
VOID
NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
CdReleaseFromCache (
_Inout_ PFCB Fcb
)
/*++
Routine Description:
The address of this routine is specified when creating a CacheMap for
a virtual file. It is subsequently called by the Lazy Writer to release
a resource acquired above.
Arguments:
Fcb - The pointer supplied as context to the cache initialization
routine.
Return Value:
None
--*/
{
PAGED_CODE();
NT_ASSERT(IoGetTopLevelIrp() == (PIRP)FSRTL_CACHE_TOP_LEVEL_IRP);
IoSetTopLevelIrp( NULL );
ExReleaseResourceLite( Fcb->Resource );
}
BOOLEAN
NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
CdNoopAcquire (
_In_ PVOID Fcb,
_In_ BOOLEAN Wait
)
/*++
Routine Description:
This routine does nothing.
Arguments:
Fcb - The Fcb/Vcb which was specified as a context parameter for this
routine.
Wait - TRUE if the caller is willing to block.
Return Value:
TRUE
--*/
{
PAGED_CODE();
UNREFERENCED_PARAMETER( Fcb );
UNREFERENCED_PARAMETER( Wait );
return TRUE;
}
VOID
NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
CdNoopRelease (
_In_ PVOID Fcb
)
/*++
Routine Description:
This routine does nothing.
Arguments:
Fcb - The Fcb/Vcb which was specified as a context parameter for this
routine.
Return Value:
None
--*/
{
PAGED_CODE();
UNREFERENCED_PARAMETER( Fcb );
}
_Requires_lock_held_(_Global_critical_region_)
NTSTATUS
NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
CdFilterCallbackAcquireForCreateSection (
_In_ PFS_FILTER_CALLBACK_DATA CallbackData,
_Unreferenced_parameter_ PVOID *CompletionContext
)
/*++
Routine Description:
This is the callback routine for MM to use to acquire the file exclusively.
Arguments:
FS_FILTER_CALLBACK_DATA - Filter based callback data that provides the file object we
want to acquire.
CompletionContext - Ignored.
Return Value:
On success we return STATUS_FSFILTER_OP_COMPLETED_SUCCESSFULLY.
If SyncType is SyncTypeCreateSection, we return a status that indicates there are no
writers to this file.
--*/
{
PFILE_OBJECT FileObject;
PAGED_CODE();
NT_ASSERT( CallbackData->Operation == FS_FILTER_ACQUIRE_FOR_SECTION_SYNCHRONIZATION );
NT_ASSERT( CallbackData->SizeOfFsFilterCallbackData == sizeof(FS_FILTER_CALLBACK_DATA) );
//
// Get the file object from the callback data.
//
FileObject = CallbackData->FileObject;
//
// Get the Fcb resource exclusively.
//
ExAcquireResourceExclusiveLite( &((PFCB) FileObject->FsContext)->FcbNonpaged->FcbResource,
TRUE );
//
// Take the File resource shared. We need this later on when MM calls
// QueryStandardInfo to get the file size.
//
// If we don't use StarveExclusive, then we can get wedged behind an
// exclusive waiter who is waiting on someone else holding it shared in the
// read->initializecachemap path (which calls createsection) who is in turn
// waiting on us to finish the create section.
//
ExAcquireSharedStarveExclusive( ((PFCB) FileObject->FsContext)->Resource,
TRUE );
//
// CDFS is a read-only file system, so we can always indicate no writers.
// We only do this for create section synchronization. For others we
// return the generic success STATUS_FSFILTER_OP_COMPLETED_SUCCESSFULLY.
//
if (CallbackData->Parameters.AcquireForSectionSynchronization.SyncType == SyncTypeCreateSection) {
return STATUS_FILE_LOCKED_WITH_ONLY_READERS;
} else {
return STATUS_FSFILTER_OP_COMPLETED_SUCCESSFULLY;
}
UNREFERENCED_PARAMETER( CompletionContext );
}
_Function_class_(FAST_IO_RELEASE_FILE)
_Requires_lock_held_(_Global_critical_region_)
VOID
NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
CdReleaseForCreateSection (
_In_ PFILE_OBJECT FileObject
)
/*++
Routine Description:
This is the callback routine for MM to use to release a file acquired with
the AcquireForCreateSection call above.
Arguments:
FileObject - File object for a Cdfs stream.
Return Value:
None
--*/
{
PAGED_CODE();
//
// Release the resources.
//
ExReleaseResourceLite( &((PFCB) FileObject->FsContext)->FcbNonpaged->FcbResource );
ExReleaseResourceLite( ((PFCB) FileObject->FsContext)->Resource);
}