PDEVICE_INFORMATION DeviceInformation = NULL, DeviceInfo;
/* Get device name */
- Status = QueryDeviceInformation(SymbolicLinkName,
+ Status = QueryDeviceInformation(DeviceName,
&TargetDeviceName,
NULL, NULL, NULL,
NULL, NULL, NULL);
{
DeviceInformation = CONTAINING_RECORD(DeviceEntry, DEVICE_INFORMATION, DeviceListEntry);
- if (RtlCompareUnicodeString(&TargetDeviceName, &(DeviceInformation->DeviceName), TRUE) == 0)
+ if (RtlEqualUnicodeString(&TargetDeviceName, &(DeviceInformation->DeviceName), TRUE))
{
break;
}
FreePool(SymLink.Buffer);
MountMgrNotify(DeviceExtension);
- if (!DeviceInformation->Volume)
+ if (!DeviceInformation->ManuallyRegistered)
{
MountMgrNotifyNameChange(DeviceExtension, DeviceName, FALSE);
}
NTSTATUS Status;
PIO_STACK_LOCATION Stack;
UNICODE_STRING DeviceName;
- ULONG TotalSize, TotalSymLinks;
PMOUNTMGR_MOUNT_POINTS MountPoints;
PDEVICE_INFORMATION DeviceInformation;
PLIST_ENTRY DeviceEntry, SymlinksEntry;
PSYMLINK_INFORMATION SymlinkInformation;
+ USHORT UniqueIdLength, DeviceNameLength;
+ ULONG TotalSize, TotalSymLinks, UniqueIdOffset, DeviceNameOffset;
/* If we got a symbolic link, query device */
if (SymbolicName)
{
if (DeviceEntry == &(DeviceExtension->DeviceListHead))
{
- if (DeviceName.Buffer)
+ if (SymbolicName)
{
FreePool(DeviceName.Buffer);
}
}
/* 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)
/* Find back correct mount point */
if (UniqueId)
{
- if (!UniqueId->UniqueIdLength != DeviceInformation->UniqueId->UniqueIdLength)
+ if (UniqueId->UniqueIdLength != DeviceInformation->UniqueId->UniqueIdLength)
{
continue;
}
}
}
+ /* Save our information about shared data */
+ UniqueIdOffset = TotalSize;
+ UniqueIdLength = DeviceInformation->UniqueId->UniqueIdLength;
+ DeviceNameOffset = TotalSize + UniqueIdLength;
+ DeviceNameLength = DeviceInformation->DeviceName.Length;
+
+ /* Initialize first symlink */
+ MountPoints->MountPoints[TotalSymLinks].UniqueIdOffset = UniqueIdOffset;
+ MountPoints->MountPoints[TotalSymLinks].UniqueIdLength = UniqueIdLength;
+ MountPoints->MountPoints[TotalSymLinks].DeviceNameOffset = DeviceNameOffset;
+ MountPoints->MountPoints[TotalSymLinks].DeviceNameLength = DeviceNameLength;
+
+ /* And copy data */
+ RtlCopyMemory((PWSTR)((ULONG_PTR)MountPoints + UniqueIdOffset),
+ DeviceInformation->UniqueId->UniqueId, UniqueIdLength);
+ RtlCopyMemory((PWSTR)((ULONG_PTR)MountPoints + DeviceNameOffset),
+ DeviceInformation->DeviceName.Buffer, DeviceNameLength);
+
+ TotalSize += DeviceInformation->UniqueId->UniqueIdLength + DeviceInformation->DeviceName.Length;
+
/* Now we've got it, but all the data */
for (SymlinksEntry = DeviceInformation->SymbolicLinksListHead.Flink;
SymlinksEntry != &(DeviceInformation->SymbolicLinksListHead);
{
SymlinkInformation = CONTAINING_RECORD(SymlinksEntry, SYMLINK_INFORMATION, SymbolicLinksListEntry);
+ /* First, set shared data */
- MountPoints->MountPoints[TotalSymLinks].SymbolicLinkNameOffset = sizeof(MOUNTMGR_MOUNT_POINTS) +
- TotalSize;
+ /* Only put UniqueID if online */
+ if (SymlinkInformation->Online)
+ {
+ MountPoints->MountPoints[TotalSymLinks].UniqueIdOffset = UniqueIdOffset;
+ MountPoints->MountPoints[TotalSymLinks].UniqueIdLength = UniqueIdLength;
+ }
+ else
+ {
+ MountPoints->MountPoints[TotalSymLinks].UniqueIdOffset = 0;
+ MountPoints->MountPoints[TotalSymLinks].UniqueIdLength = 0;
+ }
+
+ MountPoints->MountPoints[TotalSymLinks].DeviceNameOffset = DeviceNameOffset;
+ MountPoints->MountPoints[TotalSymLinks].DeviceNameLength = DeviceNameLength;
+
+ /* And now, copy specific symlink info */
+ MountPoints->MountPoints[TotalSymLinks].SymbolicLinkNameOffset = TotalSize;
MountPoints->MountPoints[TotalSymLinks].SymbolicLinkNameLength = SymlinkInformation->Name.Length;
- MountPoints->MountPoints[TotalSymLinks].UniqueIdOffset = sizeof(MOUNTMGR_MOUNT_POINTS) +
- SymlinkInformation->Name.Length +
- TotalSize;
- MountPoints->MountPoints[TotalSymLinks].UniqueIdLength = DeviceInformation->UniqueId->UniqueIdLength;
- MountPoints->MountPoints[TotalSymLinks].DeviceNameOffset = sizeof(MOUNTMGR_MOUNT_POINTS) +
- SymlinkInformation->Name.Length +
- DeviceInformation->UniqueId->UniqueIdLength +
- TotalSize;
- MountPoints->MountPoints[TotalSymLinks].DeviceNameLength = DeviceInformation->DeviceName.Length;
RtlCopyMemory((PWSTR)((ULONG_PTR)MountPoints + MountPoints->MountPoints[TotalSymLinks].SymbolicLinkNameOffset),
SymlinkInformation->Name.Buffer, SymlinkInformation->Name.Length);
- RtlCopyMemory((PWSTR)((ULONG_PTR)MountPoints + MountPoints->MountPoints[TotalSymLinks].UniqueIdOffset),
- DeviceInformation->UniqueId->UniqueId, DeviceInformation->UniqueId->UniqueIdLength);
- RtlCopyMemory((PWSTR)((ULONG_PTR)MountPoints + MountPoints->MountPoints[TotalSymLinks].DeviceNameOffset),
- DeviceInformation->DeviceName.Buffer, DeviceInformation->DeviceName.Length);
/* Update counters */
TotalSymLinks++;
- TotalSize += SymlinkInformation->Name.Length + DeviceInformation->UniqueId->UniqueIdLength +
- DeviceInformation->DeviceName.Length;
+ TotalSize += SymlinkInformation->Name.Length;
}
if (UniqueId || SymbolicName)
}
}
+ if (SymbolicName)
+ {
+ FreePool(DeviceName.Buffer);
+ }
+
return STATUS_SUCCESS;
}
{
DeviceInformation = CONTAINING_RECORD(DeviceEntry, DEVICE_INFORMATION, DeviceListEntry);
- if (RtlEqualUnicodeString(&DeviceName, &(DeviceInformation->DeviceName), TRUE) == 0)
+ if (RtlEqualUnicodeString(&DeviceName, &(DeviceInformation->DeviceName), TRUE))
{
break;
}
/* 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;
}
{
SymlinkInformation = CONTAINING_RECORD(SymlinksEntry, SYMLINK_INFORMATION, SymbolicLinksListEntry);
- if (RtlEqualUnicodeString(SymbolicName, &SymlinkInformation->Name, TRUE) == 0)
+ if (RtlEqualUnicodeString(SymbolicName, &SymlinkInformation->Name, TRUE))
{
break;
}
}
/* Get output buffer */
- Stack = IoGetNextIrpStackLocation(Irp);
+ Stack = IoGetCurrentIrpStackLocation(Irp);
MountPoints = (PMOUNTMGR_MOUNT_POINTS)Irp->AssociatedIrp.SystemBuffer;
/* Compute output length */
/* 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;
}