[MOUNTMGR] QueryPointsFromMemory: take into account the multiple MOUNTMGR_MOUNT_POINT
[reactos.git] / drivers / filters / mountmgr / point.c
index 0c2136c..35fe8bb 100644 (file)
@@ -60,7 +60,7 @@ MountMgrCreatePointWorker(IN PDEVICE_EXTENSION DeviceExtension,
     {
         DeviceInformation = CONTAINING_RECORD(DeviceEntry, DEVICE_INFORMATION, DeviceListEntry);
 
-        if (RtlCompareUnicodeString(&TargetDeviceName, &(DeviceInformation->DeviceName), TRUE) == 0)
+        if (RtlEqualUnicodeString(&TargetDeviceName, &(DeviceInformation->DeviceName), TRUE))
         {
             break;
         }
@@ -221,7 +221,7 @@ MountMgrCreatePointWorker(IN PDEVICE_EXTENSION DeviceExtension,
     FreePool(SymLink.Buffer);
     MountMgrNotify(DeviceExtension);
 
-    if (!DeviceInformation->Volume)
+    if (!DeviceInformation->ManuallyRegistered)
     {
         MountMgrNotifyNameChange(DeviceExtension, DeviceName, FALSE);
     }
@@ -322,7 +322,7 @@ QueryPointsFromMemory(IN PDEVICE_EXTENSION DeviceExtension,
     {
         if (DeviceEntry == &(DeviceExtension->DeviceListHead))
         {
-            if (DeviceName.Buffer)
+            if (SymbolicName)
             {
                 FreePool(DeviceName.Buffer);
             }
@@ -332,21 +332,29 @@ QueryPointsFromMemory(IN PDEVICE_EXTENSION DeviceExtension,
     }
 
     /* Now, ensure output buffer can hold everything */
-    Stack = IoGetNextIrpStackLocation(Irp);
+    Stack = IoGetCurrentIrpStackLocation(Irp);
     MountPoints = (PMOUNTMGR_MOUNT_POINTS)Irp->AssociatedIrp.SystemBuffer;
 
     /* Ensure we set output to let user reallocate! */
-    MountPoints->Size = sizeof(MOUNTMGR_MOUNT_POINTS) + TotalSize;
+    MountPoints->Size = sizeof(MOUNTMGR_MOUNT_POINTS) + TotalSymLinks * sizeof(MOUNTMGR_MOUNT_POINT) + TotalSize;
     MountPoints->NumberOfMountPoints = TotalSymLinks;
+    Irp->IoStatus.Information = MountPoints->Size;
 
     if (MountPoints->Size > Stack->Parameters.DeviceIoControl.OutputBufferLength)
     {
+        Irp->IoStatus.Information = sizeof(MOUNTMGR_MOUNT_POINTS);
+
+        if (SymbolicName)
+        {
+            FreePool(DeviceName.Buffer);
+        }
+
         return STATUS_BUFFER_OVERFLOW;
     }
 
     /* Now, start putting mount points */
+    TotalSize = sizeof(MOUNTMGR_MOUNT_POINTS) + TotalSymLinks * sizeof(MOUNTMGR_MOUNT_POINT);
     TotalSymLinks = 0;
-    TotalSize = 0;
     for (DeviceEntry = DeviceExtension->DeviceListHead.Flink;
          DeviceEntry != &(DeviceExtension->DeviceListHead);
          DeviceEntry = DeviceEntry->Flink)
@@ -356,7 +364,7 @@ QueryPointsFromMemory(IN PDEVICE_EXTENSION DeviceExtension,
         /* Find back correct mount point */
         if (UniqueId)
         {
-            if (!UniqueId->UniqueIdLength != DeviceInformation->UniqueId->UniqueIdLength)
+            if (UniqueId->UniqueIdLength != DeviceInformation->UniqueId->UniqueIdLength)
             {
                 continue;
             }
@@ -383,16 +391,12 @@ QueryPointsFromMemory(IN PDEVICE_EXTENSION DeviceExtension,
         {
             SymlinkInformation = CONTAINING_RECORD(SymlinksEntry, SYMLINK_INFORMATION, SymbolicLinksListEntry);
 
-
-            MountPoints->MountPoints[TotalSymLinks].SymbolicLinkNameOffset = sizeof(MOUNTMGR_MOUNT_POINTS) +
-                                                                             TotalSize;
+            MountPoints->MountPoints[TotalSymLinks].SymbolicLinkNameOffset = TotalSize;
             MountPoints->MountPoints[TotalSymLinks].SymbolicLinkNameLength = SymlinkInformation->Name.Length;
-            MountPoints->MountPoints[TotalSymLinks].UniqueIdOffset = sizeof(MOUNTMGR_MOUNT_POINTS) +
-                                                                     SymlinkInformation->Name.Length +
+            MountPoints->MountPoints[TotalSymLinks].UniqueIdOffset = SymlinkInformation->Name.Length +
                                                                      TotalSize;
             MountPoints->MountPoints[TotalSymLinks].UniqueIdLength = DeviceInformation->UniqueId->UniqueIdLength;
-            MountPoints->MountPoints[TotalSymLinks].DeviceNameOffset = sizeof(MOUNTMGR_MOUNT_POINTS) +
-                                                                       SymlinkInformation->Name.Length +
+            MountPoints->MountPoints[TotalSymLinks].DeviceNameOffset = SymlinkInformation->Name.Length +
                                                                        DeviceInformation->UniqueId->UniqueIdLength +
                                                                        TotalSize;
             MountPoints->MountPoints[TotalSymLinks].DeviceNameLength = DeviceInformation->DeviceName.Length;
@@ -416,6 +420,11 @@ QueryPointsFromMemory(IN PDEVICE_EXTENSION DeviceExtension,
         }
     }
 
+    if (SymbolicName)
+    {
+        FreePool(DeviceName.Buffer);
+    }
+
     return STATUS_SUCCESS;
 }
 
@@ -449,7 +458,7 @@ QueryPointsFromSymbolicLinkName(IN PDEVICE_EXTENSION DeviceExtension,
         {
             DeviceInformation = CONTAINING_RECORD(DeviceEntry, DEVICE_INFORMATION, DeviceListEntry);
 
-            if (RtlEqualUnicodeString(&DeviceName, &(DeviceInformation->DeviceName), TRUE) == 0)
+            if (RtlEqualUnicodeString(&DeviceName, &(DeviceInformation->DeviceName), TRUE))
             {
                 break;
             }
@@ -465,11 +474,11 @@ QueryPointsFromSymbolicLinkName(IN PDEVICE_EXTENSION DeviceExtension,
         /* Check for the link */
         for (SymlinksEntry = DeviceInformation->SymbolicLinksListHead.Flink;
              SymlinksEntry != &(DeviceInformation->SymbolicLinksListHead);
-             SymlinksEntry = DeviceEntry->Flink)
+             SymlinksEntry = SymlinksEntry->Flink)
         {
             SymlinkInformation = CONTAINING_RECORD(SymlinksEntry, SYMLINK_INFORMATION, SymbolicLinksListEntry);
 
-            if (RtlEqualUnicodeString(SymbolicName, &SymlinkInformation->Name, TRUE) == 0)
+            if (RtlEqualUnicodeString(SymbolicName, &SymlinkInformation->Name, TRUE))
             {
                 break;
             }
@@ -497,7 +506,7 @@ QueryPointsFromSymbolicLinkName(IN PDEVICE_EXTENSION DeviceExtension,
             {
                 SymlinkInformation = CONTAINING_RECORD(SymlinksEntry, SYMLINK_INFORMATION, SymbolicLinksListEntry);
 
-                if (RtlEqualUnicodeString(SymbolicName, &SymlinkInformation->Name, TRUE) == 0)
+                if (RtlEqualUnicodeString(SymbolicName, &SymlinkInformation->Name, TRUE))
                 {
                     break;
                 }
@@ -517,7 +526,7 @@ QueryPointsFromSymbolicLinkName(IN PDEVICE_EXTENSION DeviceExtension,
     }
 
     /* Get output buffer */
-    Stack = IoGetNextIrpStackLocation(Irp);
+    Stack = IoGetCurrentIrpStackLocation(Irp);
     MountPoints = (PMOUNTMGR_MOUNT_POINTS)Irp->AssociatedIrp.SystemBuffer;
 
     /* Compute output length */
@@ -527,9 +536,12 @@ QueryPointsFromSymbolicLinkName(IN PDEVICE_EXTENSION DeviceExtension,
     /* Give length to allow reallocation */
     MountPoints->Size = sizeof(MOUNTMGR_MOUNT_POINTS) + TotalLength;
     MountPoints->NumberOfMountPoints = 1;
+    Irp->IoStatus.Information = sizeof(MOUNTMGR_MOUNT_POINTS) + TotalLength;
 
     if (MountPoints->Size > Stack->Parameters.DeviceIoControl.OutputBufferLength)
     {
+        Irp->IoStatus.Information = sizeof(MOUNTMGR_MOUNT_POINTS);
+
         return STATUS_BUFFER_OVERFLOW;
     }