Author: gedmurphy
Date: Tue Sep  6 16:33:46 2016
New Revision: 72593

URL: http://svn.reactos.org/svn/reactos?rev=72593&view=rev
Log:
[FLTMGR]
- Properly handle requests that were sent directly to the fltmgr instead of 
sending them down the stack
- Add a separate callback for IRP_MJ_DEVICE_CONTROL and forward them on to an 
internal handler
- We can now open a handle to the fltmgr and send IOCTLs down to it.

Modified:
    trunk/reactos/drivers/filters/fltmgr/Interface.c

Modified: trunk/reactos/drivers/filters/fltmgr/Interface.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filters/fltmgr/Interface.c?rev=72593&r1=72592&r2=72593&view=diff
==============================================================================
--- trunk/reactos/drivers/filters/fltmgr/Interface.c    [iso-8859-1] (original)
+++ trunk/reactos/drivers/filters/fltmgr/Interface.c    [iso-8859-1] Tue Sep  6 
16:33:46 2016
@@ -1,7 +1,7 @@
 /*
 * PROJECT:         Filesystem Filter Manager
 * LICENSE:         GPL - See COPYING in the top level directory
-* FILE:            drivers/fs_minifilter/fltmgr/interface.c
+* FILE:            drivers/filters/fltmgr/interface.c
 * PURPOSE:         Implements the driver interface
 * PROGRAMMERS:     Ged Murphy (gedmur...@reactos.org)
 */
@@ -9,6 +9,7 @@
 /* INCLUDES ******************************************************************/
 
 #include "fltmgr.h"
+#include "fltmgrint.h"
 
 //#define NDEBUG
 #include <debug.h>
@@ -95,6 +96,13 @@
 NTSTATUS
 NTAPI
 FltpFsControl(
+    _In_ PDEVICE_OBJECT DeviceObject,
+    _Inout_ PIRP Irp
+);
+
+NTSTATUS
+NTAPI
+FltpDeviceControl(
     _In_ PDEVICE_OBJECT DeviceObject,
     _Inout_ PIRP Irp
 );
@@ -344,6 +352,7 @@
 #pragma alloc_text(PAGE, FltpFsNotification)
 #pragma alloc_text(PAGE, FltpCreate)
 #pragma alloc_text(PAGE, FltpFsControl)
+#pragma alloc_text(PAGE, FltpDeviceControl)
 #pragma alloc_text(PAGE, FltpFastIoRead)
 #pragma alloc_text(PAGE, FltpFastIoWrite)
 #pragma alloc_text(PAGE, FltpFastIoQueryBasicInfo)
@@ -366,25 +375,10 @@
 #pragma alloc_text(PAGE, FltpFastIoQueryOpen)
 #endif
 
-#define MAX_DEVNAME_LENGTH  64
+
 
 DRIVER_DATA DriverData;
 
-
-typedef struct _FLTMGR_DEVICE_EXTENSION
-{
-    /* The file system we're attached to */
-    PDEVICE_OBJECT AttachedToDeviceObject;
-
-    /* The storage stack(disk) accociated with the file system device object 
we're attached to */
-    PDEVICE_OBJECT StorageStackDeviceObject;
-
-    /* Either physical drive for volume device objects otherwise
-     * it's the name of the control device we're attached to */
-    UNICODE_STRING DeviceName;
-    WCHAR DeviceNameBuffer[MAX_DEVNAME_LENGTH];
-
-} FLTMGR_DEVICE_EXTENSION, *PFLTMGR_DEVICE_EXTENSION;
 
 typedef struct _DETACH_DEVICE_WORK_ITEM
 {
@@ -427,17 +421,37 @@
 {
     PFLTMGR_DEVICE_EXTENSION DeviceExtension;
     PIO_STACK_LOCATION StackPtr;
-
-    DeviceExtension = DeviceObject->DeviceExtension;
-    __debugbreak();
+    NTSTATUS Status;
+
+    DeviceExtension = DeviceObject->DeviceExtension;
+
+    /* Check if this is a request for us */
+    if (DeviceObject == DriverData.DeviceObject)
+    {
+        FLT_ASSERT(DeviceObject->DriverObject == DriverData.DriverObject);
+        FLT_ASSERT(DeviceExtension == NULL);
+
+        /* Hand it off to our internal handler */
+        Status = FltpDispatchHandler(DeviceObject, Irp);
+        if (Status != STATUS_REPARSE)
+        {
+            Irp->IoStatus.Status = Status;
+            Irp->IoStatus.Information = 0;
+            IoCompleteRequest(Irp, 0);
+        }
+        return Status;
+    }
+
     FLT_ASSERT(DeviceExtension &&
                DeviceExtension->AttachedToDeviceObject);
 
     StackPtr = IoGetCurrentIrpStackLocation(Irp);
     if (StackPtr->MajorFunction == IRP_MJ_SHUTDOWN)
     {
-        //FltpProcessShutdownRequest(DeviceObject);
-    }
+        // handle shutdown request
+    }
+
+    DPRINT1("Received %X from %wZ\n", StackPtr->MajorFunction, 
&DeviceExtension->DeviceName);
 
     /* Just pass the IRP down the stack */
     IoSkipCurrentIrpStackLocation(Irp);
@@ -454,9 +468,24 @@
     PAGED_CODE();
 
     DeviceExtension = DeviceObject->DeviceExtension;
-    __debugbreak();
+
+    /* Check if this is a request for us */
+    if (DeviceObject == DriverData.DeviceObject)
+    {
+        FLT_ASSERT(DeviceObject->DriverObject == DriverData.DriverObject);
+        FLT_ASSERT(DeviceExtension == NULL);
+
+        /* Someone wants a handle to the fltmgr, allow it */
+        Irp->IoStatus.Status = STATUS_SUCCESS;
+        Irp->IoStatus.Information = 0;
+        IofCompleteRequest(Irp, 0);
+        return STATUS_SUCCESS;
+    }
+
     FLT_ASSERT(DeviceExtension &&
                DeviceExtension->AttachedToDeviceObject);
+
+    DPRINT1("Received create from %wZ (%lu)\n", &DeviceExtension->DeviceName, 
PsGetCurrentProcessId());
 
     /* Just pass the IRP down the stack */
     IoSkipCurrentIrpStackLocation(Irp);
@@ -472,10 +501,53 @@
 
     PAGED_CODE();
 
-    DeviceExtension = DeviceObject->DeviceExtension;
-    __debugbreak();
+    /* Check if this is a request for us */
+    if (DeviceObject == DriverData.DeviceObject)
+    {
+        /* We don't handle this request */
+        Irp->IoStatus.Information = 0;
+        Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
+        IofCompleteRequest(Irp, 0);
+        return STATUS_INVALID_DEVICE_REQUEST;
+    }
+
+    DeviceExtension = DeviceObject->DeviceExtension;
+
     FLT_ASSERT(DeviceExtension &&
                DeviceExtension->AttachedToDeviceObject);
+
+    /* Just pass the IRP down the stack */
+    IoSkipCurrentIrpStackLocation(Irp);
+    return IoCallDriver(DeviceExtension->AttachedToDeviceObject, Irp);
+}
+
+NTSTATUS
+NTAPI
+FltpDeviceControl(_In_ PDEVICE_OBJECT DeviceObject,
+                  _Inout_ PIRP Irp)
+{
+    PFLTMGR_DEVICE_EXTENSION DeviceExtension;
+    NTSTATUS Status;
+
+    /* Check if the request was meant for us */
+    if (DeviceObject == DriverData.DeviceObject)
+    {
+        Status = FltpDeviceControlHandler(DeviceObject, Irp);
+        if (Status != STATUS_REPARSE)
+        {
+            Irp->IoStatus.Status = Status;
+            Irp->IoStatus.Information = 0;
+            IoCompleteRequest(Irp, 0);
+        }
+
+        return Status;
+    }
+
+    DeviceExtension = DeviceObject->DeviceExtension;
+
+    FLT_ASSERT(DeviceExtension &&
+               DeviceExtension->AttachedToDeviceObject);
+
     /* Just pass the IRP down the stack */
     IoSkipCurrentIrpStackLocation(Irp);
     return IoCallDriver(DeviceExtension->AttachedToDeviceObject, Irp);
@@ -1890,7 +1962,6 @@
     LONG_PTR Count;
 
     PAGED_CODE();
-    __debugbreak();
 
     /* Get the top device in the chain and increment the ref count on it */
     AttachedDevice = IoGetAttachedDeviceReference(DeviceObject);
@@ -2099,6 +2170,7 @@
     DriverObject->MajorFunction[IRP_MJ_CREATE_NAMED_PIPE] = FltpCreate;
     DriverObject->MajorFunction[IRP_MJ_CREATE_MAILSLOT] = FltpCreate;
     DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = FltpFsControl;
+    DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = FltpDeviceControl;
 
     /* The FastIo diapatch table is stored in the pool along with a tag */
     FastIoDispatch = ExAllocatePoolWithTag(NonPagedPool, 
sizeof(FAST_IO_DISPATCH), FM_TAG_DISPATCH_TABLE);


Reply via email to