Author: tfaber
Date: Sat Apr 9 19:33:42 2016
New Revision: 71130
URL:
http://svn.reactos.org/svn/reactos?rev=71130&view=rev
Log:
[CDFS]
- Implement file locking
CORE-10790 #resolve
Modified:
trunk/reactos/drivers/filesystems/cdfs/cdfs.c
trunk/reactos/drivers/filesystems/cdfs/cdfs.h
trunk/reactos/drivers/filesystems/cdfs/cleanup.c
trunk/reactos/drivers/filesystems/cdfs/dispatch.c
trunk/reactos/drivers/filesystems/cdfs/fcb.c
trunk/reactos/drivers/filesystems/cdfs/rw.c
Modified: trunk/reactos/drivers/filesystems/cdfs/cdfs.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/cdfs/c…
==============================================================================
--- trunk/reactos/drivers/filesystems/cdfs/cdfs.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/cdfs/cdfs.c [iso-8859-1] Sat Apr 9 19:33:42 2016
@@ -96,6 +96,7 @@
DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] = CdfsFsdDispatch;
DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] = CdfsFsdDispatch;
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = CdfsFsdDispatch;
+ DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] = CdfsFsdDispatch;
CdfsGlobalData->FastIoDispatch.SizeOfFastIoDispatch = sizeof(FAST_IO_DISPATCH);
CdfsGlobalData->FastIoDispatch.FastIoCheckIfPossible = CdfsFastIoCheckIfPossible;
Modified: trunk/reactos/drivers/filesystems/cdfs/cdfs.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/cdfs/c…
==============================================================================
--- trunk/reactos/drivers/filesystems/cdfs/cdfs.h [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/cdfs/cdfs.h [iso-8859-1] Sat Apr 9 19:33:42 2016
@@ -220,6 +220,7 @@
ERESOURCE NameListResource;
LIST_ENTRY ShortNameList;
+ FILE_LOCK FileLock;
} FCB, *PFCB;
Modified: trunk/reactos/drivers/filesystems/cdfs/cleanup.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/cdfs/c…
==============================================================================
--- trunk/reactos/drivers/filesystems/cdfs/cleanup.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/cdfs/cleanup.c [iso-8859-1] Sat Apr 9 19:33:42
2016
@@ -35,18 +35,20 @@
/* FUNCTIONS ****************************************************************/
static NTSTATUS
-CdfsCleanupFile(PDEVICE_EXTENSION DeviceExt,
+CdfsCleanupFile(PCDFS_IRP_CONTEXT IrpContext,
PFILE_OBJECT FileObject)
/*
* FUNCTION: Cleans up after a file has been closed.
*/
{
+ PDEVICE_EXTENSION DeviceExt;
PFCB Fcb;
DPRINT("CdfsCleanupFile(DeviceExt %p, FileObject %p)\n",
DeviceExt,
FileObject);
+ DeviceExt = IrpContext->DeviceObject->DeviceExtension;
Fcb = FileObject->FsContext;
if (!Fcb)
{
@@ -57,6 +59,15 @@
FsRtlNotifyCleanup(DeviceExt->NotifySync,
&(DeviceExt->NotifyList),
FileObject->FsContext2);
+
+ if (!CdfsFCBIsDirectory(Fcb) &&
+ FsRtlAreThereCurrentFileLocks(&Fcb->FileLock))
+ {
+ FsRtlFastUnlockAll(&Fcb->FileLock,
+ FileObject,
+ IoGetRequestorProcess(IrpContext->Irp),
+ NULL);
+ }
/* Uninitialize file cache if initialized for this file object. */
if (FileObject->SectionObjectPointer &&
FileObject->SectionObjectPointer->SharedCacheMap)
@@ -99,7 +110,7 @@
KeEnterCriticalRegion();
ExAcquireResourceExclusiveLite(&DeviceExtension->DirResource, TRUE);
- Status = CdfsCleanupFile(DeviceExtension, FileObject);
+ Status = CdfsCleanupFile(IrpContext, FileObject);
ExReleaseResourceLite(&DeviceExtension->DirResource);
KeLeaveCriticalRegion();
Modified: trunk/reactos/drivers/filesystems/cdfs/dispatch.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/cdfs/d…
==============================================================================
--- trunk/reactos/drivers/filesystems/cdfs/dispatch.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/cdfs/dispatch.c [iso-8859-1] Sat Apr 9 19:33:42
2016
@@ -55,6 +55,34 @@
static
NTSTATUS
+CdfsLockControl(
+ IN PCDFS_IRP_CONTEXT IrpContext)
+{
+ PFCB Fcb;
+ NTSTATUS Status;
+
+ DPRINT("CdfsLockControl(IrpContext %p)\n", IrpContext);
+
+ if (IrpContext->DeviceObject == CdfsGlobalData->DeviceObject)
+ {
+ return STATUS_INVALID_DEVICE_REQUEST;
+ }
+
+ Fcb = IrpContext->FileObject->FsContext;
+ if (CdfsFCBIsDirectory(Fcb))
+ {
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ IrpContext->Flags &= ~IRPCONTEXT_COMPLETE;
+ Status = FsRtlProcessFileLock(&Fcb->FileLock,
+ IrpContext->Irp,
+ NULL);
+ return Status;
+}
+
+static
+NTSTATUS
CdfsDispatch(PCDFS_IRP_CONTEXT IrpContext)
{
PIRP Irp = IrpContext->Irp;
@@ -114,6 +142,10 @@
case IRP_MJ_FILE_SYSTEM_CONTROL:
Status = CdfsFileSystemControl(IrpContext);
+ break;
+
+ case IRP_MJ_LOCK_CONTROL:
+ Status = CdfsLockControl(IrpContext);
break;
}
Modified: trunk/reactos/drivers/filesystems/cdfs/fcb.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/cdfs/f…
==============================================================================
--- trunk/reactos/drivers/filesystems/cdfs/fcb.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/cdfs/fcb.c [iso-8859-1] Sat Apr 9 19:33:42 2016
@@ -97,6 +97,7 @@
Fcb->RFCB.Resource = &Fcb->MainResource;
Fcb->RFCB.IsFastIoPossible = FastIoIsNotPossible;
InitializeListHead(&Fcb->ShortNameList);
+ FsRtlInitializeFileLock(&Fcb->FileLock, NULL, NULL);
return(Fcb);
}
@@ -107,6 +108,7 @@
{
PLIST_ENTRY Entry;
+ FsRtlUninitializeFileLock(&Fcb->FileLock);
ExDeleteResourceLite(&Fcb->PagingIoResource);
ExDeleteResourceLite(&Fcb->MainResource);
Modified: trunk/reactos/drivers/filesystems/cdfs/rw.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/cdfs/r…
==============================================================================
--- trunk/reactos/drivers/filesystems/cdfs/rw.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/cdfs/rw.c [iso-8859-1] Sat Apr 9 19:33:42 2016
@@ -41,7 +41,7 @@
/* FUNCTIONS ****************************************************************/
static NTSTATUS
-CdfsReadFile(PDEVICE_EXTENSION DeviceExt,
+CdfsReadFile(PCDFS_IRP_CONTEXT IrpContext,
PFILE_OBJECT FileObject,
PUCHAR Buffer,
ULONG Length,
@@ -53,6 +53,7 @@
*/
{
NTSTATUS Status = STATUS_SUCCESS;
+ PDEVICE_EXTENSION DeviceExt;
PFCB Fcb;
ULONG ToRead = Length;
@@ -63,6 +64,7 @@
if (Length == 0)
return(STATUS_SUCCESS);
+ DeviceExt = IrpContext->DeviceObject->DeviceExtension;
Fcb = (PFCB)FileObject->FsContext;
if (ReadOffset >= Fcb->Entry.DataLengthL)
@@ -70,6 +72,15 @@
if (ReadOffset + Length > Fcb->Entry.DataLengthL)
ToRead = Fcb->Entry.DataLengthL - ReadOffset;
+
+ if (!(IrpFlags & IRP_PAGING_IO) &&
+ FsRtlAreThereCurrentFileLocks(&Fcb->FileLock))
+ {
+ if (!FsRtlCheckLockForReadAccess(&Fcb->FileLock, IrpContext->Irp))
+ {
+ return STATUS_FILE_LOCK_CONFLICT;
+ }
+ }
DPRINT("Reading %u bytes at %u\n", Length, ReadOffset);
@@ -179,8 +190,6 @@
PCDFS_IRP_CONTEXT IrpContext)
{
PIRP Irp;
- PDEVICE_OBJECT DeviceObject;
- PDEVICE_EXTENSION DeviceExt;
PIO_STACK_LOCATION Stack;
PFILE_OBJECT FileObject;
PVOID Buffer = NULL;
@@ -194,17 +203,15 @@
ASSERT(IrpContext);
Irp = IrpContext->Irp;
- DeviceObject = IrpContext->DeviceObject;
Stack = IrpContext->Stack;
- DeviceExt = DeviceObject->DeviceExtension;
FileObject = Stack->FileObject;
ReadLength = Stack->Parameters.Read.Length;
ReadOffset = Stack->Parameters.Read.ByteOffset;
if (ReadLength) Buffer = MmGetSystemAddressForMdl(Irp->MdlAddress);
- Status = CdfsReadFile(DeviceExt,
+ Status = CdfsReadFile(IrpContext,
FileObject,
Buffer,
ReadLength,