#include "usbstor.h"
+#define NDEBUG
+#include <debug.h>
+
//
// driver verifier
//
NTAPI
USBSTOR_SyncForwardIrpCompletionRoutine(
PDEVICE_OBJECT DeviceObject,
- PIRP Irp,
+ PIRP Irp,
PVOID Context)
{
if (Irp->PendingReturned)
{
PURB Urb;
- PUCHAR Buffer;
NTSTATUS Status;
//
return STATUS_INSUFFICIENT_RESOURCES;
}
- //
- // allocate 1-byte buffer
- //
- Buffer = (PUCHAR)AllocateItem(NonPagedPool, sizeof(UCHAR));
- if (!Buffer)
- {
- //
- // no memory
- //
- FreeItem(Buffer);
- return STATUS_INSUFFICIENT_RESOURCES;
- }
-
//
// initialize vendor request
//
DPRINT("MaxLUN: %x\n", *Buffer);
- if (*Buffer > 0xF)
+ if (NT_SUCCESS(Status))
{
- //
- // invalid response documented in usb mass storage specification
- //
- Status = STATUS_DEVICE_DATA_ERROR;
+ if (*Buffer > 0xF)
+ {
+ //
+ // invalid response documented in usb mass storage specification
+ //
+ Status = STATUS_DEVICE_DATA_ERROR;
+ }
+ else
+ {
+ //
+ // store maxlun
+ //
+ DeviceExtension->MaxLUN = *Buffer;
+ }
}
else
{
//
- // store maxlun
+ // "USB Mass Storage Class. Bulk-Only Transport. Revision 1.0"
+ // 3.2 Get Max LUN (class-specific request) :
+ // Devices that do not support multiple LUNs may STALL this command.
//
- DeviceExtension->MaxLUN = *Buffer;
+ USBSTOR_ResetDevice(DeviceExtension->LowerDeviceObject, DeviceExtension);
+
+ DeviceExtension->MaxLUN = 0;
+ Status = STATUS_SUCCESS;
}
//
// execute request
//
Status = USBSTOR_ClassRequest(DeviceObject, DeviceExtension, USB_BULK_RESET_DEVICE, DeviceExtension->InterfaceInformation->InterfaceNumber, USBD_TRANSFER_DIRECTION_OUT, 0, NULL);
- DPRINT1("Status %x\n", Status);
//
// done
return Status;
}
+
+BOOLEAN
+USBSTOR_IsFloppy(
+ IN PUCHAR Buffer,
+ IN ULONG BufferLength,
+ OUT PUCHAR MediumTypeCode)
+{
+ PUFI_CAPACITY_FORMAT_HEADER FormatHeader;
+ PUFI_CAPACITY_DESCRIPTOR Descriptor;
+ ULONG Length, Index, BlockCount, BlockLength;
+
+ //
+ // get format header
+ //
+ FormatHeader = (PUFI_CAPACITY_FORMAT_HEADER)Buffer;
+
+ //
+ // sanity checks
+ //
+ ASSERT(FormatHeader->Reserved1 == 0x00);
+ ASSERT(FormatHeader->Reserved2 == 0x00);
+ ASSERT(FormatHeader->Reserved3 == 0x00);
+
+ //
+ // is there capacity data
+ //
+ if (!FormatHeader->CapacityLength)
+ {
+ //
+ // no data provided
+ //
+ DPRINT1("[USBSTOR] No capacity length\n");
+ return FALSE;
+ }
+
+ //
+ // the format header are always 8 bytes in length
+ //
+ ASSERT((FormatHeader->CapacityLength & 0x7) == 0);
+ DPRINT1("CapacityLength %x\n", FormatHeader->CapacityLength);
+
+ //
+ // grab length and locate first descriptor
+ //
+ Length = FormatHeader->CapacityLength;
+ Descriptor = (PUFI_CAPACITY_DESCRIPTOR)(FormatHeader + 1);
+ for(Index = 0; Index < Length / sizeof(UFI_CAPACITY_DESCRIPTOR); Index++)
+ {
+ //
+ // blocks are little endian format
+ //
+ BlockCount = NTOHL(Descriptor->BlockCount);
+
+ //
+ // get block length
+ //
+ BlockLength = NTOHL((Descriptor->BlockLengthByte0 << 24 | Descriptor->BlockLengthByte1 << 16 | Descriptor->BlockLengthByte2 << 8));
+
+ DPRINT1("BlockCount %x BlockLength %x Code %x\n", BlockCount, BlockLength, Descriptor->Code);
+
+ if (BlockLength == 512 && BlockCount == 1440)
+ {
+ //
+ // 720 KB DD
+ //
+ *MediumTypeCode = 0x1E;
+ return TRUE;
+ }
+ else if (BlockLength == 1024 && BlockCount == 1232)
+ {
+ //
+ // 1,25 MB
+ //
+ *MediumTypeCode = 0x93;
+ return TRUE;
+ }
+ else if (BlockLength == 512 && BlockCount == 2880)
+ {
+ //
+ // 1,44MB KB DD
+ //
+ *MediumTypeCode = 0x94;
+ return TRUE;
+ }
+
+ //
+ // move to next descriptor
+ //
+ Descriptor = (Descriptor + 1);
+ }
+
+ //
+ // no floppy detected
+ //
+ return FALSE;
+}