The mount manager need you to return the exact right error code, if the
buffer is to small to fit the structure you must return
STATUS_INVALID_PARAMETER however if the buffer fits the structure but not
all of the name string you must return STATUS_BUFFER_OVERFLOW and also
set the name lenght in the structure itself to what is needed so the mount
manager can make a new call with a bigger buffer. Make also sure that you
set the IoStatus.Information field to the right value. Note also that all
length’s is in bytes so it is two times the number of unicode characters.
Below is an example that surly works from the popular drivers FileDisk and
HttpDisk:
/Bo Branten
case IOCTL_MOUNTDEV_QUERY_DEVICE_NAME:
{
PMOUNTDEV_NAME name;
if (io_stack->Parameters.DeviceIoControl.OutputBufferLength <
sizeof(MOUNTDEV_NAME))
{
status = STATUS_INVALID_PARAMETER;
Irp->IoStatus.Information = 0;
break;
}
name = (PMOUNTDEV_NAME) Irp->AssociatedIrp.SystemBuffer;
name->NameLength = device_extension->device_name.Length *
sizeof(WCHAR);
if (io_stack->Parameters.DeviceIoControl.OutputBufferLength <
name->NameLength + sizeof(USHORT))
{
status = STATUS_BUFFER_OVERFLOW;
Irp->IoStatus.Information = sizeof(MOUNTDEV_NAME);
break;
}
RtlCopyMemory(name->Name,
device_extension->device_name.Buffer, name->NameLength);
status = STATUS_SUCCESS;
Irp->IoStatus.Information = name->NameLength + sizeof(USHORT);
break;
}