Author: pschweitzer
Date: Mon Feb 22 22:20:54 2016
New Revision: 70772
URL:
http://svn.reactos.org/svn/reactos?rev=70772&view=rev
Log:
[NTFS]
- Implement IRP_MJ_CLEANUP (minus the cases we can't deal with yet)
- Implement open handles count for FCB & VCB
- Implement volume locking (so useful)
Modified:
trunk/reactos/drivers/filesystems/ntfs/CMakeLists.txt
trunk/reactos/drivers/filesystems/ntfs/close.c
trunk/reactos/drivers/filesystems/ntfs/create.c
trunk/reactos/drivers/filesystems/ntfs/dispatch.c
trunk/reactos/drivers/filesystems/ntfs/fsctl.c
trunk/reactos/drivers/filesystems/ntfs/ntfs.c
trunk/reactos/drivers/filesystems/ntfs/ntfs.h
Modified: trunk/reactos/drivers/filesystems/ntfs/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/ntfs/C…
==============================================================================
--- trunk/reactos/drivers/filesystems/ntfs/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/ntfs/CMakeLists.txt [iso-8859-1] Mon Feb 22 22:20:54
2016
@@ -2,6 +2,7 @@
list(APPEND SOURCE
attrib.c
blockdev.c
+ cleanup.c
close.c
create.c
devctl.c
Modified: trunk/reactos/drivers/filesystems/ntfs/close.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/ntfs/c…
==============================================================================
--- trunk/reactos/drivers/filesystems/ntfs/close.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/ntfs/close.c [iso-8859-1] Mon Feb 22 22:20:54 2016
@@ -59,6 +59,7 @@
FileObject->FsContext2 = NULL;
FileObject->FsContext = NULL;
FileObject->SectionObjectPointer = NULL;
+ DeviceExt->OpenHandleCount--;
if (FileObject->FileName.Buffer)
{
Modified: trunk/reactos/drivers/filesystems/ntfs/create.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/ntfs/c…
==============================================================================
--- trunk/reactos/drivers/filesystems/ntfs/create.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/ntfs/create.c [iso-8859-1] Mon Feb 22 22:20:54 2016
@@ -351,6 +351,12 @@
return STATUS_INVALID_PARAMETER;
}
+ /* Deny create if the volume is locked */
+ if (DeviceExt->Flags & VCB_VOLUME_LOCKED)
+ {
+ return STATUS_ACCESS_DENIED;
+ }
+
FileObject = Stack->FileObject;
if (RequestedDisposition == FILE_CREATE ||
@@ -500,6 +506,12 @@
}
}
+ if (NT_SUCCESS(Status))
+ {
+ Fcb->OpenHandleCount++;
+ DeviceExt->OpenHandleCount++;
+ }
+
/*
* If the directory containing the file to open doesn't exist then
* fail immediately
Modified: trunk/reactos/drivers/filesystems/ntfs/dispatch.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/ntfs/d…
==============================================================================
--- trunk/reactos/drivers/filesystems/ntfs/dispatch.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/ntfs/dispatch.c [iso-8859-1] Mon Feb 22 22:20:54
2016
@@ -101,6 +101,10 @@
Status = NtfsClose(IrpContext);
break;
+ case IRP_MJ_CLEANUP:
+ Status = NtfsCleanup(IrpContext);
+ break;
+
case IRP_MJ_CREATE:
Status = NtfsCreate(IrpContext);
break;
Modified: trunk/reactos/drivers/filesystems/ntfs/fsctl.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/ntfs/f…
==============================================================================
--- trunk/reactos/drivers/filesystems/ntfs/fsctl.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/ntfs/fsctl.c [iso-8859-1] Mon Feb 22 22:20:54 2016
@@ -835,6 +835,55 @@
static
NTSTATUS
+LockOrUnlockVolume(PDEVICE_EXTENSION DeviceExt,
+ PIRP Irp,
+ BOOLEAN Lock)
+{
+ PFILE_OBJECT FileObject;
+ PNTFS_FCB Fcb;
+ PIO_STACK_LOCATION Stack;
+
+ DPRINT("LockOrUnlockVolume(%p, %p, %d)\n", DeviceExt, Irp, Lock);
+
+ Stack = IoGetCurrentIrpStackLocation(Irp);
+ FileObject = Stack->FileObject;
+ Fcb = FileObject->FsContext;
+
+ /* Only allow locking with the volume open */
+ if (!(Fcb->Flags & FCB_IS_VOLUME))
+ {
+ return STATUS_ACCESS_DENIED;
+ }
+
+ /* Bail out if it's already in the demanded state */
+ if (((DeviceExt->Flags & VCB_VOLUME_LOCKED) && Lock) ||
+ (!(DeviceExt->Flags & VCB_VOLUME_LOCKED) && !Lock))
+ {
+ return STATUS_ACCESS_DENIED;
+ }
+
+ /* Deny locking if we're not alone */
+ if (Lock && DeviceExt->OpenHandleCount != 1)
+ {
+ return STATUS_ACCESS_DENIED;
+ }
+
+ /* Finally, proceed */
+ if (Lock)
+ {
+ DeviceExt->Flags |= VCB_VOLUME_LOCKED;
+ }
+ else
+ {
+ DeviceExt->Flags &= ~VCB_VOLUME_LOCKED;
+ }
+
+ return STATUS_SUCCESS;
+}
+
+
+static
+NTSTATUS
NtfsUserFsRequest(PDEVICE_OBJECT DeviceObject,
PIRP Irp)
{
@@ -854,7 +903,6 @@
case FSCTL_EXTEND_VOLUME:
//case FSCTL_GET_RETRIEVAL_POINTER_BASE:
case FSCTL_GET_RETRIEVAL_POINTERS:
- case FSCTL_LOCK_VOLUME:
//case FSCTL_LOOKUP_STREAM_FROM_CLUSTER:
case FSCTL_MARK_HANDLE:
case FSCTL_MOVE_FILE:
@@ -862,13 +910,20 @@
case FSCTL_READ_FILE_USN_DATA:
case FSCTL_READ_USN_JOURNAL:
//case FSCTL_SHRINK_VOLUME:
- case FSCTL_UNLOCK_VOLUME:
case FSCTL_WRITE_USN_CLOSE_RECORD:
UNIMPLEMENTED;
DPRINT1("Unimplemented user request: %x\n",
Stack->Parameters.FileSystemControl.FsControlCode);
Status = STATUS_NOT_IMPLEMENTED;
break;
+ case FSCTL_LOCK_VOLUME:
+ Status = LockOrUnlockVolume(DeviceExt, Irp, TRUE);
+ break;
+
+ case FSCTL_UNLOCK_VOLUME:
+ Status = LockOrUnlockVolume(DeviceExt, Irp, FALSE);
+ break;
+
case FSCTL_GET_NTFS_VOLUME_DATA:
Status = GetNfsVolumeData(DeviceExt, Irp);
break;
Modified: trunk/reactos/drivers/filesystems/ntfs/ntfs.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/ntfs/n…
==============================================================================
--- trunk/reactos/drivers/filesystems/ntfs/ntfs.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/ntfs/ntfs.c [iso-8859-1] Mon Feb 22 22:20:54 2016
@@ -135,6 +135,7 @@
{
DriverObject->MajorFunction[IRP_MJ_CREATE] = NtfsFsdDispatch;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = NtfsFsdDispatch;
+ DriverObject->MajorFunction[IRP_MJ_CLEANUP] = NtfsFsdDispatch;
DriverObject->MajorFunction[IRP_MJ_READ] = NtfsFsdDispatch;
DriverObject->MajorFunction[IRP_MJ_WRITE] = NtfsFsdDispatch;
DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = NtfsFsdDispatch;
Modified: trunk/reactos/drivers/filesystems/ntfs/ntfs.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/ntfs/n…
==============================================================================
--- trunk/reactos/drivers/filesystems/ntfs/ntfs.h [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/ntfs/ntfs.h [iso-8859-1] Mon Feb 22 22:20:54 2016
@@ -116,7 +116,12 @@
NTFS_INFO NtfsInfo;
+ ULONG Flags;
+ ULONG OpenHandleCount;
+
} DEVICE_EXTENSION, *PDEVICE_EXTENSION, NTFS_VCB, *PNTFS_VCB;
+
+#define VCB_VOLUME_LOCKED 0x0001
typedef struct
{
@@ -460,6 +465,7 @@
LONG RefCount;
ULONG Flags;
+ ULONG OpenHandleCount;
ULONGLONG MFTIndex;
USHORT LinkCount;
@@ -565,6 +571,12 @@
/* close.c */
NTSTATUS
+NtfsCleanup(PNTFS_IRP_CONTEXT IrpContext);
+
+
+/* close.c */
+
+NTSTATUS
NtfsCloseFile(PDEVICE_EXTENSION DeviceExt,
PFILE_OBJECT FileObject);