[NTFS]
authorPierre Schweitzer <pierre@reactos.org>
Fri, 1 May 2015 18:58:00 +0000 (18:58 +0000)
committerPierre Schweitzer <pierre@reactos.org>
Fri, 1 May 2015 18:58:00 +0000 (18:58 +0000)
Why would you allocate NTFS global data structure twice to use it from only one location?
Fix that misbehavior.

svn path=/trunk/; revision=67502

reactos/drivers/filesystems/ntfs/ntfs.c

index 324b5b9..613dcda 100644 (file)
@@ -51,18 +51,28 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
 {
     UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(DEVICE_NAME);
     NTSTATUS Status;
 {
     UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(DEVICE_NAME);
     NTSTATUS Status;
+    PDEVICE_OBJECT DeviceObject;
 
     TRACE_(NTFS, "DriverEntry(%p, '%wZ')\n", DriverObject, RegistryPath);
 
 
     TRACE_(NTFS, "DriverEntry(%p, '%wZ')\n", DriverObject, RegistryPath);
 
-    /* Initialize global data */
-    NtfsGlobalData = ExAllocatePoolWithTag(NonPagedPool, sizeof(NTFS_GLOBAL_DATA), 'GRDN');
-    if (!NtfsGlobalData)
+    Status = IoCreateDevice(DriverObject,
+                            sizeof(NTFS_GLOBAL_DATA),
+                            &DeviceName,
+                            FILE_DEVICE_DISK_FILE_SYSTEM,
+                            0,
+                            FALSE,
+                            &DeviceObject);
+    if (!NT_SUCCESS(Status))
     {
     {
-        Status = STATUS_INSUFFICIENT_RESOURCES;
-        goto ErrorEnd;
+        WARN_(NTFS, "IoCreateDevice failed with status: %lx\n", Status);
+        return Status;
     }
 
     }
 
+    /* Initialize global data */
+    NtfsGlobalData = DeviceObject->DeviceExtension;
     RtlZeroMemory(NtfsGlobalData, sizeof(NTFS_GLOBAL_DATA));
     RtlZeroMemory(NtfsGlobalData, sizeof(NTFS_GLOBAL_DATA));
+
+    NtfsGlobalData->DeviceObject = DeviceObject;
     NtfsGlobalData->Identifier.Type = NTFS_TYPE_GLOBAL_DATA;
     NtfsGlobalData->Identifier.Size = sizeof(NTFS_GLOBAL_DATA);
 
     NtfsGlobalData->Identifier.Type = NTFS_TYPE_GLOBAL_DATA;
     NtfsGlobalData->Identifier.Size = sizeof(NTFS_GLOBAL_DATA);
 
@@ -89,35 +99,12 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
     /* Driver can't be unloaded */
     DriverObject->DriverUnload = NULL;
 
     /* Driver can't be unloaded */
     DriverObject->DriverUnload = NULL;
 
-    Status = IoCreateDevice(DriverObject,
-                            sizeof(NTFS_GLOBAL_DATA),
-                            &DeviceName,
-                            FILE_DEVICE_DISK_FILE_SYSTEM,
-                            0,
-                            FALSE,
-                            &NtfsGlobalData->DeviceObject);
-    if (!NT_SUCCESS(Status))
-    {
-        WARN_(NTFS, "IoCreateDevice failed with status: %lx\n", Status);
-        goto ErrorEnd;
-    }
-
     NtfsGlobalData->DeviceObject->Flags |= DO_DIRECT_IO;
 
     /* Register file system */
     IoRegisterFileSystem(NtfsGlobalData->DeviceObject);
     ObReferenceObject(NtfsGlobalData->DeviceObject);
 
     NtfsGlobalData->DeviceObject->Flags |= DO_DIRECT_IO;
 
     /* Register file system */
     IoRegisterFileSystem(NtfsGlobalData->DeviceObject);
     ObReferenceObject(NtfsGlobalData->DeviceObject);
 
-ErrorEnd:
-    if (!NT_SUCCESS(Status))
-    {
-        if (NtfsGlobalData)
-        {
-            ExDeleteResourceLite(&NtfsGlobalData->Resource);
-            ExFreePoolWithTag(NtfsGlobalData, 'GRDN');
-        }
-    }
-
     return Status;
 }
 
     return Status;
 }