2015-09-11 04:02:21 +00:00
|
|
|
/*++
|
|
|
|
|
|
|
|
Copyright (c) 1989-2000 Microsoft Corporation
|
|
|
|
|
|
|
|
Module Name:
|
|
|
|
|
|
|
|
ResrcSup.c
|
|
|
|
|
|
|
|
Abstract:
|
|
|
|
|
|
|
|
This module implements the Cdfs Resource acquisition routines
|
|
|
|
|
|
|
|
|
|
|
|
--*/
|
|
|
|
|
2017-11-23 20:05:28 +00:00
|
|
|
#include "cdprocs.h"
|
2015-09-11 04:02:21 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// The Bug check file id for this module
|
|
|
|
//
|
|
|
|
|
|
|
|
#define BugCheckFileId (CDFS_BUG_CHECK_RESRCSUP)
|
|
|
|
|
|
|
|
#ifdef ALLOC_PRAGMA
|
|
|
|
#pragma alloc_text(PAGE, CdAcquireForCache)
|
2017-11-23 20:02:16 +00:00
|
|
|
#pragma alloc_text(PAGE, CdFilterCallbackAcquireForCreateSection)
|
2015-09-11 04:02:21 +00:00
|
|
|
#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
|
|
|
|
|
2021-06-11 12:29:21 +00:00
|
|
|
|
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
|
|
|
)
|
|
|
|
|
|
|
|
/*++
|
|
|
|
|
|
|
|
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:
|
2017-11-23 20:02:16 +00:00
|
|
|
|
2017-11-23 20:05:28 +00:00
|
|
|
#ifdef _MSC_VER
|
2017-11-23 20:02:16 +00:00
|
|
|
#pragma prefast( suppress:28137, "prefast believes Wait should be a constant, but this is ok for CDFS" )
|
2017-11-23 20:05:28 +00:00
|
|
|
#endif
|
2015-09-11 04:02:21 +00:00
|
|
|
Acquired = ExAcquireResourceExclusiveLite( Resource, Wait );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AcquireShared:
|
2017-11-23 20:02:16 +00:00
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
Acquired = ExAcquireResourceSharedLite( Resource, Wait );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AcquireSharedStarveExclusive:
|
2017-11-23 20:02:16 +00:00
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
Acquired = ExAcquireSharedStarveExclusive( Resource, Wait );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2017-11-23 20:02:16 +00:00
|
|
|
Acquired = FALSE;
|
|
|
|
NT_ASSERT( FALSE );
|
2015-09-11 04:02:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2017-11-23 20:02:16 +00:00
|
|
|
// If not acquired and the user didn't specifiy IgnoreWait then
|
2015-09-11 04:02:21 +00:00
|
|
|
// raise CANT_WAIT.
|
|
|
|
//
|
|
|
|
|
|
|
|
if (!Acquired && !IgnoreWait) {
|
|
|
|
|
|
|
|
CdRaiseStatus( IrpContext, STATUS_CANT_WAIT );
|
|
|
|
}
|
|
|
|
|
|
|
|
return Acquired;
|
|
|
|
}
|
|
|
|
|
2021-06-11 12:29: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
|
|
|
)
|
|
|
|
|
|
|
|
/*++
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2018-02-12 19:45:12 +00:00
|
|
|
if (!ExAcquireResourceSharedLite( Fcb->Resource, Wait )) {
|
2018-02-25 09:13:15 +00:00
|
|
|
|
2018-02-12 19:45:12 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
NT_ASSERT(IoGetTopLevelIrp() == NULL);
|
2015-09-11 04:02:21 +00:00
|
|
|
IoSetTopLevelIrp((PIRP)FSRTL_CACHE_TOP_LEVEL_IRP);
|
|
|
|
|
2018-02-12 19:45:12 +00:00
|
|
|
return TRUE;
|
2015-09-11 04:02:21 +00:00
|
|
|
}
|
|
|
|
|
2021-06-11 12:29: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
|
|
|
)
|
|
|
|
|
|
|
|
/*++
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
NT_ASSERT(IoGetTopLevelIrp() == (PIRP)FSRTL_CACHE_TOP_LEVEL_IRP);
|
2015-09-11 04:02:21 +00:00
|
|
|
IoSetTopLevelIrp( NULL );
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
ExReleaseResourceLite( Fcb->Resource );
|
|
|
|
}
|
|
|
|
|
2021-06-11 12:29:21 +00:00
|
|
|
|
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
|
|
|
)
|
|
|
|
|
|
|
|
/*++
|
|
|
|
|
|
|
|
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();
|
2017-11-23 20:02:16 +00:00
|
|
|
|
|
|
|
UNREFERENCED_PARAMETER( Fcb );
|
|
|
|
UNREFERENCED_PARAMETER( Wait );
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-06-11 12:29:21 +00:00
|
|
|
|
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
|
|
|
)
|
|
|
|
|
|
|
|
/*++
|
|
|
|
|
|
|
|
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();
|
2017-11-23 20:02:16 +00:00
|
|
|
|
|
|
|
UNREFERENCED_PARAMETER( 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
|
|
|
)
|
|
|
|
|
|
|
|
/*++
|
|
|
|
|
|
|
|
Routine Description:
|
|
|
|
|
|
|
|
This is the callback routine for MM to use to acquire the file exclusively.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
FS_FILTER_CALLBACK_DATA - Filter based callback data that provides the file object we
|
|
|
|
want to acquire.
|
|
|
|
|
|
|
|
CompletionContext - Ignored.
|
2015-09-11 04:02:21 +00:00
|
|
|
|
|
|
|
Return Value:
|
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
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.
|
2015-09-11 04:02:21 +00:00
|
|
|
|
|
|
|
--*/
|
|
|
|
|
|
|
|
{
|
2017-11-23 20:02:16 +00:00
|
|
|
PFILE_OBJECT FileObject;
|
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
PAGED_CODE();
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2017-11-23 20:02:16 +00:00
|
|
|
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;
|
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
//
|
|
|
|
// Get the Fcb resource exclusively.
|
|
|
|
//
|
|
|
|
|
|
|
|
ExAcquireResourceExclusiveLite( &((PFCB) FileObject->FsContext)->FcbNonpaged->FcbResource,
|
2017-11-23 20:02:16 +00:00
|
|
|
TRUE );
|
2021-06-11 12:29:21 +00:00
|
|
|
|
2015-09-11 04:02:21 +00:00
|
|
|
//
|
2021-06-11 12:29:21 +00:00
|
|
|
// Take the File resource shared. We need this later on when MM calls
|
|
|
|
// QueryStandardInfo to get the file size.
|
2015-09-11 04:02:21 +00:00
|
|
|
//
|
2021-06-11 12:29:21 +00:00
|
|
|
// 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
|
2015-09-11 04:02:21 +00:00
|
|
|
// waiting on us to finish the create section.
|
|
|
|
//
|
|
|
|
|
|
|
|
ExAcquireSharedStarveExclusive( ((PFCB) FileObject->FsContext)->Resource,
|
|
|
|
TRUE );
|
2017-11-23 20:02:16 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// 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 );
|
2015-09-11 04:02:21 +00:00
|
|
|
}
|
|
|
|
|
2021-06-11 12:29: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
|
|
|
)
|
|
|
|
|
|
|
|
/*++
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|