Author: gedmurphy Date: Tue Jan 5 18:43:26 2016 New Revision: 70495
URL: http://svn.reactos.org/svn/reactos?rev=70495&view=rev Log: [FLTMGR] - Fix a bug in FltpDetachFromFileSystemDevice so it correctly bails when we've walked the attached device list. - FltpDispatch can come in at high IRQL. Thanks to Thomas for noticing that err. - Add newlines to the end of DPRINTS (it's been a while...) - The filter now loads and runs in the reactos FS stack.
Modified: trunk/reactos/drivers/fs_minifilter/fltmgr/Interface.c
Modified: trunk/reactos/drivers/fs_minifilter/fltmgr/Interface.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/fs_minifilter/fltmg... ============================================================================== --- trunk/reactos/drivers/fs_minifilter/fltmgr/Interface.c [iso-8859-1] (original) +++ trunk/reactos/drivers/fs_minifilter/fltmgr/Interface.c [iso-8859-1] Tue Jan 5 18:43:26 2016 @@ -342,7 +342,6 @@ #pragma alloc_text(PAGE, FltpAttachToFileSystemDevice) #pragma alloc_text(PAGE, FltpDetachFromFileSystemDevice) #pragma alloc_text(PAGE, FltpFsNotification) -#pragma alloc_text(PAGE, FltpDispatch) #pragma alloc_text(PAGE, FltpCreate) #pragma alloc_text(PAGE, FltpFsControl) #pragma alloc_text(PAGE, FltpFastIoRead) @@ -427,8 +426,6 @@ { PFLTMGR_DEVICE_EXTENSION DeviceExtension;
- PAGED_CODE(); - DeviceExtension = DeviceObject->DeviceExtension; __debugbreak(); FLT_ASSERT(DeviceExtension && @@ -1807,7 +1804,7 @@ Status = FltpGetObjectName(DeviceObject->DriverObject, &FileSystemDeviceName); if (!NT_SUCCESS(Status)) return Status;
- DPRINT("Found device %wZ, checking if we need to attach...", &FileSystemDeviceName); + DPRINT("Found device %wZ, checking if we need to attach...\n", &FileSystemDeviceName);
/* Build up the name of the file system recognizer device */ RtlInitUnicodeString(&FsRecDeviceName, L"\FileSystem\Fs_Rec"); @@ -1828,7 +1825,7 @@ &NewDeviceObject); if (!NT_SUCCESS(Status)) { - DPRINT1("Failed to create a DO for attatching to a FS : 0x%X", Status); + DPRINT1("Failed to create a DO for attatching to a FS : 0x%X\n", Status); return Status; }
@@ -1841,11 +1838,11 @@ &DeviceExtension->AttachedToDeviceObject); if (NT_SUCCESS(Status)) { - DPRINT("Attached to %wZ", &FileSystemDeviceName); + DPRINT("Attached to %wZ\n", &FileSystemDeviceName); } else { - DPRINT1("Failed to attach to the driver stack : 0x%X", Status); + DPRINT1("Failed to attach to the driver stack : 0x%X\n", Status); goto Cleanup; }
@@ -1862,7 +1859,7 @@ Status = FltpEnumerateFileSystemVolumes(DeviceObject); if (!NT_SUCCESS(Status)) { - DPRINT1("Failed to enumerate file system volumes for this file system : 0x%X", Status); + DPRINT1("Failed to enumerate file system volumes for this file system : 0x%X\n", Status); IoDetachDevice(DeviceExtension->AttachedToDeviceObject); }
@@ -1880,28 +1877,32 @@ LONG_PTR FltpDetachFromFileSystemDevice(_In_ PDEVICE_OBJECT DeviceObject) { - PDEVICE_OBJECT AttachedDevice, LowestDevice; + PDEVICE_OBJECT AttachedDevice, NextDevice; PFLTMGR_DEVICE_EXTENSION DeviceExtension; LONG_PTR Count;
PAGED_CODE(); - - /* Get the attached device and increment the ref count on it */ + __debugbreak(); + + /* Get the top device in the chain and increment the ref count on it */ AttachedDevice = IoGetAttachedDeviceReference(DeviceObject);
- /* Loop through all attached devices until we reach the bottom (file system driver) */ - while (AttachedDevice == NULL || - AttachedDevice->DriverObject != DriverData.DriverObject) - { - /* Get the attached device */ - LowestDevice = IoGetLowerDeviceObject(AttachedDevice); - - /* Remove the reference we added. If it's zero then we're already clean */ + /* Loop all attached devices looking for our file system driver */ + while (AttachedDevice->DriverObject != DriverData.DriverObject) + { + FLT_ASSERT(AttachedDevice != NULL); + + /* Get the next lower device object. This adds a ref on NextDevice */ + NextDevice = IoGetLowerDeviceObject(AttachedDevice); + + /* Remove the reference we added */ Count = ObfDereferenceObject(AttachedDevice); - if (Count == 0) return Count; + + /* Bail if this is the last one */ + if (NextDevice == NULL) return Count;
/* Try the next one */ - AttachedDevice = LowestDevice; + AttachedDevice = NextDevice; }
@@ -1929,7 +1930,7 @@ { UNICODE_STRING DeviceName; NTSTATUS Status; - __debugbreak(); + PAGED_CODE();
/* Set an empty string */ @@ -1939,7 +1940,7 @@ Status = FltpGetBaseDeviceObjectName(DeviceObject, &DeviceName); if (NT_SUCCESS(Status)) { - /* Check if it's attaching or detaching*/ + /* Check if it's attaching or detaching */ if (FsActive) { /* Run the attach routine */ @@ -1970,7 +1971,7 @@ UNICODE_STRING SymLink;
NTSTATUS Status; - __debugbreak(); + RtlZeroMemory(&DriverData, sizeof(DRIVER_DATA)); DriverData.DriverObject = DriverObject;
@@ -1996,7 +1997,7 @@ &DeviceObject); if (!NT_SUCCESS(Status)) { - DPRINT1("fltmgr IoCreateDevice failed. Status = %X", Status); + DPRINT1("fltmgr IoCreateDevice failed. Status = %X\n", Status); goto Cleanup; }