https://git.reactos.org/?p=reactos.git;a=commitdiff;h=126abaf88f58ec3dd3da9…
commit 126abaf88f58ec3dd3da9d6631d5b6a554a852ae
Author: Victor Perevertkin <victor(a)perevertkin.ru>
AuthorDate: Tue Jun 11 01:40:43 2019 +0300
Commit: Victor Perevertkin <victor(a)perevertkin.ru>
CommitDate: Tue Jun 11 04:39:43 2019 +0300
[USBSTOR] Improve handling of IRP_MN_QUERY_DEVICE_TEXT for PDOs
CORE-15883
---
drivers/usb/usbstor/pdo.c | 92 +++++++++++++++++++++++++++++++++--------------
1 file changed, 66 insertions(+), 26 deletions(-)
diff --git a/drivers/usb/usbstor/pdo.c b/drivers/usb/usbstor/pdo.c
index 9a84483b701..ef9a4fb4511 100644
--- a/drivers/usb/usbstor/pdo.c
+++ b/drivers/usb/usbstor/pdo.c
@@ -119,6 +119,7 @@ USBSTOR_GetGenericType(
}
}
+static
ULONG
CopyField(
IN PUCHAR Name,
@@ -144,50 +145,89 @@ CopyField(
return MaxLength;
}
+static
+ULONG
+CopyFieldTruncate(
+ IN PUCHAR Name,
+ IN PCHAR Buffer,
+ IN ULONG MaxLength)
+{
+ ULONG Index;
+
+ for (Index = 0; Index < MaxLength; Index++)
+ {
+ if (Name[Index] == '\0')
+ {
+ break;
+ }
+ else if (Name[Index] <= ' ' || Name[Index] >= 0x7F /* last
printable ascii character */ || Name[Index] == ',')
+ {
+ // convert to underscore
+ Buffer[Index] = ' ';
+ }
+ else
+ {
+ // just copy character
+ Buffer[Index] = Name[Index];
+ }
+ }
+
+ return Index;
+}
+
NTSTATUS
USBSTOR_PdoHandleQueryDeviceText(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp)
{
+ PPDO_DEVICE_EXTENSION DeviceExtension;
PIO_STACK_LOCATION IoStack;
- LPWSTR Buffer;
- static WCHAR DeviceText[] = L"USB Mass Storage Device";
+ CHAR LocalBuffer[26];
+ UINT32 Offset = 0;
+ PINQUIRYDATA InquiryData;
+ ANSI_STRING AnsiString;
+ UNICODE_STRING DeviceDescription;
IoStack = IoGetCurrentIrpStackLocation(Irp);
- if (IoStack->Parameters.QueryDeviceText.DeviceTextType == DeviceTextDescription)
- {
- DPRINT("USBSTOR_PdoHandleQueryDeviceText DeviceTextDescription\n");
+ DeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+ ASSERT(DeviceExtension->InquiryData);
+ InquiryData = DeviceExtension->InquiryData;
- Buffer = (LPWSTR)AllocateItem(PagedPool, sizeof(DeviceText));
- if (!Buffer)
+ switch (IoStack->Parameters.QueryDeviceText.DeviceTextType)
+ {
+ case DeviceTextDescription:
+ case DeviceTextLocationInformation:
{
- Irp->IoStatus.Information = 0;
- return STATUS_INSUFFICIENT_RESOURCES;
- }
+ DPRINT("USBSTOR_PdoHandleQueryDeviceText\n");
- wcscpy(Buffer, DeviceText);
+ Offset += CopyFieldTruncate(InquiryData->VendorId,
&LocalBuffer[Offset], sizeof(InquiryData->VendorId));
+ LocalBuffer[Offset++] = ' ';
+ Offset += CopyFieldTruncate(InquiryData->ProductId,
&LocalBuffer[Offset], sizeof(InquiryData->ProductId));
+ LocalBuffer[Offset++] = '\0';
- Irp->IoStatus.Information = (ULONG_PTR)Buffer;
- return STATUS_SUCCESS;
- }
- else
- {
- DPRINT("USBSTOR_PdoHandleQueryDeviceText
DeviceTextLocationInformation\n");
+ RtlInitAnsiString(&AnsiString, (PCSZ)&LocalBuffer);
+
+ DeviceDescription.Length = 0;
+ DeviceDescription.MaximumLength = (USHORT)(Offset * sizeof(WCHAR));
+ DeviceDescription.Buffer = (LPWSTR)AllocateItem(PagedPool,
DeviceDescription.MaximumLength);
+ if (!DeviceDescription.Buffer)
+ {
+ Irp->IoStatus.Information = 0;
+ return STATUS_INSUFFICIENT_RESOURCES;
+ }
- Buffer = (LPWSTR)AllocateItem(PagedPool, sizeof(DeviceText));
- if (!Buffer)
+ RtlAnsiStringToUnicodeString(&DeviceDescription, &AnsiString,
FALSE);
+
+ Irp->IoStatus.Information = (ULONG_PTR)DeviceDescription.Buffer;
+ return STATUS_SUCCESS;
+ }
+ default:
{
Irp->IoStatus.Information = 0;
- return STATUS_INSUFFICIENT_RESOURCES;
+ return Irp->IoStatus.Status;
}
-
- wcscpy(Buffer, DeviceText);
-
- Irp->IoStatus.Information = (ULONG_PTR)Buffer;
- return STATUS_SUCCESS;
}
-
}
NTSTATUS