sys: IRP_MJ_READ, IRP_MJ_WRITE: file lock support

This commit is contained in:
Bill Zissimopoulos 2016-04-06 16:04:42 -07:00
parent 218ad0be8c
commit 66dbfb24ff
2 changed files with 28 additions and 8 deletions

View File

@ -97,10 +97,6 @@ static NTSTATUS FspFsvolReadCached(
FSP_FILE_NODE *FileNode = FileObject->FsContext;
LARGE_INTEGER ReadOffset = IrpSp->Parameters.Read.ByteOffset;
ULONG ReadLength = IrpSp->Parameters.Read.Length;
#if 0
/* !!!: lock support! */
ULONG ReadKey = IrpSp->Parameters.Read.Key;
#endif
BOOLEAN SynchronousIo = BooleanFlagOn(FileObject->Flags, FO_SYNCHRONOUS_IO);
FSP_FSCTL_FILE_INFO FileInfo;
CC_FILE_SIZES FileSizes;
@ -112,6 +108,13 @@ static NTSTATUS FspFsvolReadCached(
if (!Success)
return FspWqRepostIrpWorkItem(Irp, FspFsvolReadCached, 0);
/* check the file locks */
if (!FsRtlCheckLockForReadAccess(&FileNode->FileLock, Irp))
{
FspFileNodeRelease(FileNode, Main);
return STATUS_FILE_LOCK_CONFLICT;
}
/* trim ReadLength; the cache manager does not tolerate reads beyond file size */
ASSERT(FspTimeoutInfinity32 ==
FspFsvolDeviceExtension(FsvolDeviceObject)->VolumeParams.FileInfoTimeout);
@ -234,6 +237,13 @@ static NTSTATUS FspFsvolReadNonCached(
if (!Success)
return FspWqRepostIrpWorkItem(Irp, FspFsvolReadNonCached, 0);
/* check the file locks */
if (!PagingIo && !FsRtlCheckLockForReadAccess(&FileNode->FileLock, Irp))
{
FspFileNodeRelease(FileNode, Full);
return STATUS_FILE_LOCK_CONFLICT;
}
/* if this is a non-cached transfer on a cached file then flush the file */
if (!PagingIo && 0 != FileObject->SectionObjectPointer->DataSectionObject)
{

View File

@ -98,10 +98,6 @@ static NTSTATUS FspFsvolWriteCached(
FSP_FILE_NODE *FileNode = FileObject->FsContext;
LARGE_INTEGER WriteOffset = IrpSp->Parameters.Write.ByteOffset;
ULONG WriteLength = IrpSp->Parameters.Write.Length;
#if 0
/* !!!: lock support! */
ULONG WriteKey = IrpSp->Parameters.Write.Key;
#endif
BOOLEAN WriteToEndOfFile =
FILE_WRITE_TO_END_OF_FILE == WriteOffset.LowPart && -1L == WriteOffset.HighPart;
BOOLEAN SynchronousIo = BooleanFlagOn(FileObject->Flags, FO_SYNCHRONOUS_IO);
@ -134,6 +130,13 @@ static NTSTATUS FspFsvolWriteCached(
if (!Success)
return FspWqRepostIrpWorkItem(Irp, FspFsvolWriteCached, 0);
/* check the file locks */
if (!FsRtlCheckLockForWriteAccess(&FileNode->FileLock, Irp))
{
FspFileNodeRelease(FileNode, Main);
return STATUS_FILE_LOCK_CONFLICT;
}
/* compute new file size */
ASSERT(FspTimeoutInfinity32 ==
FspFsvolDeviceExtension(FsvolDeviceObject)->VolumeParams.FileInfoTimeout);
@ -300,6 +303,13 @@ static NTSTATUS FspFsvolWriteNonCached(
if (!Success)
return FspWqRepostIrpWorkItem(Irp, FspFsvolWriteNonCached, 0);
/* check the file locks */
if (!PagingIo && !FsRtlCheckLockForWriteAccess(&FileNode->FileLock, Irp))
{
FspFileNodeRelease(FileNode, Full);
return STATUS_FILE_LOCK_CONFLICT;
}
/* if this is a non-cached transfer on a cached file then flush and purge the file */
if (!PagingIo && 0 != FileObject->SectionObjectPointer->DataSectionObject)
{