[USBSTOR] Improve handling of IRP_MN_QUERY_DEVICE_TEXT for PDOs

CORE-15883
This commit is contained in:
Victor Perevertkin 2019-06-11 01:40:43 +03:00
parent 40b25634ff
commit 126abaf88f

View file

@ -119,6 +119,7 @@ USBSTOR_GetGenericType(
} }
} }
static
ULONG ULONG
CopyField( CopyField(
IN PUCHAR Name, IN PUCHAR Name,
@ -144,50 +145,89 @@ CopyField(
return MaxLength; 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 NTSTATUS
USBSTOR_PdoHandleQueryDeviceText( USBSTOR_PdoHandleQueryDeviceText(
IN PDEVICE_OBJECT DeviceObject, IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp) IN PIRP Irp)
{ {
PPDO_DEVICE_EXTENSION DeviceExtension;
PIO_STACK_LOCATION IoStack; PIO_STACK_LOCATION IoStack;
LPWSTR Buffer; CHAR LocalBuffer[26];
static WCHAR DeviceText[] = L"USB Mass Storage Device"; UINT32 Offset = 0;
PINQUIRYDATA InquiryData;
ANSI_STRING AnsiString;
UNICODE_STRING DeviceDescription;
IoStack = IoGetCurrentIrpStackLocation(Irp); IoStack = IoGetCurrentIrpStackLocation(Irp);
if (IoStack->Parameters.QueryDeviceText.DeviceTextType == DeviceTextDescription) DeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
{ ASSERT(DeviceExtension->InquiryData);
DPRINT("USBSTOR_PdoHandleQueryDeviceText DeviceTextDescription\n"); InquiryData = DeviceExtension->InquiryData;
Buffer = (LPWSTR)AllocateItem(PagedPool, sizeof(DeviceText)); switch (IoStack->Parameters.QueryDeviceText.DeviceTextType)
if (!Buffer) {
case DeviceTextDescription:
case DeviceTextLocationInformation:
{
DPRINT("USBSTOR_PdoHandleQueryDeviceText\n");
Offset += CopyFieldTruncate(InquiryData->VendorId, &LocalBuffer[Offset], sizeof(InquiryData->VendorId));
LocalBuffer[Offset++] = ' ';
Offset += CopyFieldTruncate(InquiryData->ProductId, &LocalBuffer[Offset], sizeof(InquiryData->ProductId));
LocalBuffer[Offset++] = '\0';
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;
}
RtlAnsiStringToUnicodeString(&DeviceDescription, &AnsiString, FALSE);
Irp->IoStatus.Information = (ULONG_PTR)DeviceDescription.Buffer;
return STATUS_SUCCESS;
}
default:
{ {
Irp->IoStatus.Information = 0; Irp->IoStatus.Information = 0;
return STATUS_INSUFFICIENT_RESOURCES; return Irp->IoStatus.Status;
} }
wcscpy(Buffer, DeviceText);
Irp->IoStatus.Information = (ULONG_PTR)Buffer;
return STATUS_SUCCESS;
} }
else
{
DPRINT("USBSTOR_PdoHandleQueryDeviceText DeviceTextLocationInformation\n");
Buffer = (LPWSTR)AllocateItem(PagedPool, sizeof(DeviceText));
if (!Buffer)
{
Irp->IoStatus.Information = 0;
return STATUS_INSUFFICIENT_RESOURCES;
}
wcscpy(Buffer, DeviceText);
Irp->IoStatus.Information = (ULONG_PTR)Buffer;
return STATUS_SUCCESS;
}
} }
NTSTATUS NTSTATUS