lockctrl.c
来自「winddk src目录下的文件系统驱动源码压缩!」· C语言 代码 · 共 712 行 · 第 1/2 页
C
712 行
FatFastUnlockAll (
IN PFILE_OBJECT FileObject,
PEPROCESS ProcessId,
OUT PIO_STATUS_BLOCK IoStatus,
IN PDEVICE_OBJECT DeviceObject
)
/*++
Routine Description:
This is a call back routine for doing the fast unlock all call.
Arguments:
FileObject - Supplies the file object used in this operation
ProcessId - Supplies the process ID used in this operation
Status - Receives the Status if this operation is successful
Return Value:
BOOLEAN - TRUE if this operation completed and FALSE if caller
needs to take the long route.
--*/
{
BOOLEAN Results;
PVCB Vcb;
PFCB Fcb;
PCCB Ccb;
DebugTrace(+1, Dbg, "FatFastUnlockAll\n", 0);
IoStatus->Information = 0;
//
// Decode the type of file object we're being asked to process and make sure
// it is only a user file open.
//
if (FatDecodeFileObject( FileObject, &Vcb, &Fcb, &Ccb ) != UserFileOpen) {
IoStatus->Status = STATUS_INVALID_PARAMETER;
DebugTrace(-1, Dbg, "FatFastUnlockAll -> TRUE (STATUS_INVALID_PARAMETER)\n", 0);
return TRUE;
}
//
// Acquire exclusive access to the Fcb this operation can always wait
//
FsRtlEnterFileSystem();
(VOID) ExAcquireResourceSharedLite( Fcb->Header.Resource, TRUE );
try {
//
// We check whether we can proceed based on the state of the file oplocks.
//
if (!FsRtlOplockIsFastIoPossible( &(Fcb)->Specific.Fcb.Oplock )) {
try_return( Results = FALSE );
}
//
// Now call the FsRtl routine to do the actual processing of the
// Lock request. The call will always succeed.
//
Results = TRUE;
IoStatus->Status = FsRtlFastUnlockAll( &Fcb->Specific.Fcb.FileLock,
FileObject,
ProcessId,
NULL );
//
// Set the flag indicating if Fast I/O is possible
//
Fcb->Header.IsFastIoPossible = FatIsFastIoPossible( Fcb );
try_exit: NOTHING;
} finally {
DebugUnwind( FatFastUnlockAll );
//
// Release the Fcb, and return to our caller
//
ExReleaseResourceLite( (Fcb)->Header.Resource );
FsRtlExitFileSystem();
DebugTrace(-1, Dbg, "FatFastUnlockAll -> %08lx\n", Results);
}
return Results;
}
BOOLEAN
FatFastUnlockAllByKey (
IN PFILE_OBJECT FileObject,
PVOID ProcessId,
ULONG Key,
OUT PIO_STATUS_BLOCK IoStatus,
IN PDEVICE_OBJECT DeviceObject
)
/*++
Routine Description:
This is a call back routine for doing the fast unlock all by key call.
Arguments:
FileObject - Supplies the file object used in this operation
ProcessId - Supplies the process ID used in this operation
Key - Supplies the key used in this operation
Status - Receives the Status if this operation is successful
Return Value:
BOOLEAN - TRUE if this operation completed and FALSE if caller
needs to take the long route.
--*/
{
BOOLEAN Results;
PVCB Vcb;
PFCB Fcb;
PCCB Ccb;
DebugTrace(+1, Dbg, "FatFastUnlockAllByKey\n", 0);
IoStatus->Information = 0;
//
// Decode the type of file object we're being asked to process and make sure
// it is only a user file open.
//
if (FatDecodeFileObject( FileObject, &Vcb, &Fcb, &Ccb ) != UserFileOpen) {
IoStatus->Status = STATUS_INVALID_PARAMETER;
DebugTrace(-1, Dbg, "FatFastUnlockAll -> TRUE (STATUS_INVALID_PARAMETER)\n", 0);
return TRUE;
}
//
// Acquire exclusive access to the Fcb this operation can always wait
//
FsRtlEnterFileSystem();
(VOID) ExAcquireResourceSharedLite( Fcb->Header.Resource, TRUE );
try {
//
// We check whether we can proceed based on the state of the file oplocks.
//
if (!FsRtlOplockIsFastIoPossible( &(Fcb)->Specific.Fcb.Oplock )) {
try_return( Results = FALSE );
}
//
// Now call the FsRtl routine to do the actual processing of the
// Lock request. The call will always succeed.
//
Results = TRUE;
IoStatus->Status = FsRtlFastUnlockAllByKey( &Fcb->Specific.Fcb.FileLock,
FileObject,
ProcessId,
Key,
NULL );
//
// Set the flag indicating if Fast I/O is possible
//
Fcb->Header.IsFastIoPossible = FatIsFastIoPossible( Fcb );
try_exit: NOTHING;
} finally {
DebugUnwind( FatFastUnlockAllByKey );
//
// Release the Fcb, and return to our caller
//
ExReleaseResourceLite( (Fcb)->Header.Resource );
FsRtlExitFileSystem();
DebugTrace(-1, Dbg, "FatFastUnlockAllByKey -> %08lx\n", Results);
}
return Results;
}
NTSTATUS
FatCommonLockControl (
IN PIRP_CONTEXT IrpContext,
IN PIRP Irp
)
/*++
Routine Description:
This is the common routine for doing Lock control operations called
by both the fsd and fsp threads
Arguments:
Irp - Supplies the Irp to process
Return Value:
NTSTATUS - The return status for the operation
--*/
{
NTSTATUS Status;
PIO_STACK_LOCATION IrpSp;
TYPE_OF_OPEN TypeOfOpen;
PVCB Vcb;
PFCB Fcb;
PCCB Ccb;
BOOLEAN OplockPostIrp = FALSE;
//
// Get a pointer to the current Irp stack location
//
IrpSp = IoGetCurrentIrpStackLocation( Irp );
DebugTrace(+1, Dbg, "FatCommonLockControl\n", 0);
DebugTrace( 0, Dbg, "Irp = %08lx\n", Irp);
DebugTrace( 0, Dbg, "MinorFunction = %08lx\n", IrpSp->MinorFunction);
//
// Decode the type of file object we're being asked to process
//
TypeOfOpen = FatDecodeFileObject( IrpSp->FileObject, &Vcb, &Fcb, &Ccb );
//
// If the file is not a user file open then we reject the request
// as an invalid parameter
//
if (TypeOfOpen != UserFileOpen) {
FatCompleteRequest( IrpContext, Irp, STATUS_INVALID_PARAMETER );
DebugTrace(-1, Dbg, "FatCommonLockControl -> STATUS_INVALID_PARAMETER\n", 0);
return STATUS_INVALID_PARAMETER;
}
//
// Acquire exclusive access to the Fcb and enqueue the Irp if we didn't
// get access
//
if (!FatAcquireSharedFcb( IrpContext, Fcb )) {
Status = FatFsdPostRequest( IrpContext, Irp );
DebugTrace(-1, Dbg, "FatCommonLockControl -> %08lx\n", Status);
return Status;
}
try {
//
// We check whether we can proceed
// based on the state of the file oplocks.
//
Status = FsRtlCheckOplock( &Fcb->Specific.Fcb.Oplock,
Irp,
IrpContext,
FatOplockComplete,
NULL );
if (Status != STATUS_SUCCESS) {
OplockPostIrp = TRUE;
try_return( NOTHING );
}
//
// Now call the FsRtl routine to do the actual processing of the
// Lock request
//
Status = FsRtlProcessFileLock( &Fcb->Specific.Fcb.FileLock, Irp, NULL );
//
// Set the flag indicating if Fast I/O is possible
//
Fcb->Header.IsFastIoPossible = FatIsFastIoPossible( Fcb );
try_exit: NOTHING;
} finally {
DebugUnwind( FatCommonLockControl );
//
// Only if this is not an abnormal termination do we delete the
// irp context
//
if (!AbnormalTermination() && !OplockPostIrp) {
FatCompleteRequest( IrpContext, FatNull, 0 );
}
//
// Release the Fcb, and return to our caller
//
FatReleaseFcb( IrpContext, Fcb );
DebugTrace(-1, Dbg, "FatCommonLockControl -> %08lx\n", Status);
}
return Status;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?