Difference between revisions of "Unit Storage"
Line 210: | Line 210: | ||
</div></div> | </div></div> | ||
<br /> | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''USB storage specific constants''' <code> USB_STORAGE_* </code></div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>USBSTORAGE_DRIVER_NAME = 'USB Mass Storage Driver';</code> | ||
+ | | Name of USB storage driver | ||
+ | |- | ||
+ | |colspan="2"| | ||
+ | |- | ||
+ | |colspan="2"|''CB/CBI (Control/Bulk/Interrupt) Requests'' | ||
+ | |- | ||
+ | | <code>USB_STORAGE_REQUEST_CBI_ADSC = 0;</code> | ||
+ | | | ||
+ | |- | ||
+ | |colspan="2"| | ||
+ | |- | ||
+ | |colspan="2"|''BBB (Bulk Only) Requests'' | ||
+ | |- | ||
+ | | <code>USB_STORAGE_REQUEST_BBB_RESET = $FF;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>USB_STORAGE_REQUEST_BBB_GET_MAX_LUN = $FE;</code> | ||
+ | | | ||
+ | |- | ||
+ | |colspan="2"| | ||
+ | |- | ||
+ | |colspan="2"|''Command Block Wrapper'' | ||
+ | |- | ||
+ | | <code>USB_STORAGE_CBW_SIGNATUR = $43425355;</code> | ||
+ | | | ||
+ | |- | ||
+ | |colspan="2"| | ||
+ | |- | ||
+ | | <code>USB_STORAGE_CBW_FLAGS_OUT = $00;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>USB_STORAGE_CBW_FLAGS_IN = $80;</code> | ||
+ | | | ||
+ | |- | ||
+ | |colspan="2"| | ||
+ | |- | ||
+ | | <code>USB_STORAGE_CBW_CB_LENGTH = 16;</code> | ||
+ | | | ||
+ | |- | ||
+ | |colspan="2"| | ||
+ | |- | ||
+ | | <code>USB_STORAGE_CBW_SIZE = 31;</code> | ||
+ | | | ||
+ | |- | ||
+ | |colspan="2"| | ||
+ | |- | ||
+ | |colspan="2"|''Command Status Wrapper'' | ||
+ | |- | ||
+ | | <code>USB_STORAGE_CSW_SIGNATURE = $53425355;</code> | ||
+ | | | ||
+ | |- | ||
+ | |colspan="2"| | ||
+ | |- | ||
+ | | <code>USB_STORAGE_CSW_STATUS_GOOD = $00;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>USB_STORAGE_CSW_STATUS_FAILED = $01;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>USB_STORAGE_CSW_STATUS_PHASE = $02;</code> | ||
+ | | | ||
+ | |- | ||
+ | |colspan="2"| | ||
+ | |- | ||
+ | | <code>USB_STORAGE_CSW_SIZE = 13;</code> | ||
+ | | | ||
+ | |- | ||
+ | |colspan="2"| | ||
+ | |- | ||
+ | |colspan="2"|''Command Data'' | ||
+ | |- | ||
+ | | <code>USB_STORAGE_COMMAND_MAX_SIZE = 16;</code> | ||
+ | | | ||
+ | |- | ||
+ | |colspan="2"| | ||
+ | |- | ||
+ | |colspan="2"|''Command Retry Counts'' | ||
+ | |- | ||
+ | | <code>USB_STORAGE_READ_RETRIES = 2;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>USB_STORAGE_WRITE_RETRIES = 2;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>USB_STORAGE_STATUS_RETRIES = 2;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>USB_STORAGE_INQUIRY_RETRIES = 5;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>USB_STORAGE_READ_CAPACITY_RETRIES = 3;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>USB_STORAGE_TEST_UNIT_READY_RETRIES = 5;</code> | ||
+ | | 10; TestingRPi | ||
+ | |- | ||
+ | |colspan="2"| | ||
+ | |- | ||
+ | |colspan="2"|''Peripheral Device Types'' | ||
+ | |- | ||
+ | |colspan="2"|''These are a subset of the SCSI Peripheral Device Types'' | ||
+ | |- | ||
+ | | <code>USB_STORAGE_DEVICE_TYPE_DISK = $00;</code> | ||
+ | | SBC Direct-access device (e.g., UHD Floppy disk) | ||
+ | |- | ||
+ | | <code>USB_STORAGE_DEVICE_TYPE_CDROM = $05;</code> | ||
+ | | MMC-5 CD-ROM device | ||
+ | |- | ||
+ | | <code>USB_STORAGE_DEVICE_TYPE_OPTICAL = $07;</code> | ||
+ | | Optical memory device (e.g., Non-CD optical disks) | ||
+ | |- | ||
+ | | <code>USB_STORAGE_DEVICE_TYPE_RBC = $0E;</code> | ||
+ | | RBC Direct-access device (e.g., UHD Floppy disk) | ||
+ | |- | ||
+ | | <code>USB_STORAGE_DEVICE_TYPE_UNKNOWN = $1F;</code> | ||
+ | | Unknown or no device type | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
=== Type definitions === | === Type definitions === |
Revision as of 05:30, 30 December 2016
Return to Unit Reference
Description
Ultibo Storage interface unit
This unit provides both the Storage device interface and the generic USB mass storage driver.
USB Mass Storage Devices
The USB Mass Storage Class Control/Bulk/Interrupt (CBI) Transport specification is approved for use only with full-speed floppy disk drives. CBI shall not be used in high-speed capable devices, or in devices other than floppy disk drives. CBI shall not be used in devices that implement LSDFS. Usage of CBI for any new design is discouraged.
Therefore the majority of USB Mass Storage devices use the Bulk only interface.
USB mass storage class devices normally use the SCSI command set and therefore the USB storage driver consumes the SCSI unit for the protocol and command definitions. USB mass storage devices are registered directly as Storage devices not as SCSI devices.
Constants
STORAGE_*
STORAGE_NAME_PREFIX = 'Storage';
|
Name prefix for Storage Devices |
STORAGE_STATUS_TIMER_INTERVAL = 1000;
|
STORAGE_TYPE_*
STORAGE_TYPE_NONE = 0;
|
|
STORAGE_TYPE_HDD = 1;
|
|
STORAGE_TYPE_FDD = 2;
|
|
STORAGE_TYPE_CDROM = 3;
|
|
STORAGE_TYPE_OPTICAL = 4;
|
|
STORAGE_TYPE_TAPE = 5;
|
|
STORAGE_TYPE_REMOVABLE = 6;
|
|
STORAGE_TYPE_MAX = 6;
|
STORAGE_STATE_*
STORAGE_STATE_EJECTED = 0;
|
|
STORAGE_STATE_EJECTING = 1;
|
|
STORAGE_STATE_INSERTING = 2;
|
|
STORAGE_STATE_INSERTED = 3;
|
|
STORAGE_STATE_MAX = 3;
|
STORAGE_FLAG_*
STORAGE_FLAG_NONE = $00000000;
|
|
STORAGE_FLAG_REMOVABLE = $00000001;
|
|
STORAGE_FLAG_LBA48 = $00000002;
|
|
STORAGE_FLAG_NOT_READY = $00000004;
|
|
STORAGE_FLAG_NO_MEDIA = $00000008;
|
|
STORAGE_FLAG_READ_ONLY = $00000010;
|
|
STORAGE_FLAG_WRITE_ONLY = $00000020;
|
|
STORAGE_FLAG_ERASEABLE = $00000040;
|
|
STORAGE_FLAG_LOCKABLE = $00000080;
|
|
STORAGE_FLAG_LOCKED = $00000100;
|
|
STORAGE_FLAG_EJECTABLE = $00000200;
|
|
STORAGE_FLAG_CHANGABLE = $00000400;
|
STORAGE_CONTROL_*
STORAGE_CONTROL_TEST_READY = 1;
|
Test Unit Ready |
STORAGE_CONTROL_RESET = 2;
|
Reset Device |
STORAGE_CONTROL_TEST_MEDIA = 3;
|
Test No Media |
STORAGE_CONTROL_LOCK = 4;
|
Lock Media |
STORAGE_CONTROL_UNLOCK = 5;
|
Unlock Media |
STORAGE_CONTROL_EJECT = 6;
|
Eject Media |
STORAGE_CONTROL_TEST_LOCKED = 7;
|
Test Media Locked |
STORAGE_CONTROL_TEST_CHANGED = 8;
|
Test Media Changed |
STORAGE_CONTROL_GET_VENDORID = 9;
|
Get Vendor ID |
STORAGE_CONTROL_GET_PRODUCTID = 10;
|
Get Product ID |
STORAGE_CONTROL_GET_SERIAL = 11;
|
Get Serial No |
STORAGE_CONTROL_GET_REVISION = 12;
|
Get Revision No |
STORAGE_CONTROL_GET_PRODUCT = 13;
|
Get Product Name |
STORAGE_CONTROL_GET_MANUFACTURER = 14;
|
Get Manufacturer Name |
STORAGE_LOG_*
STORAGE_LOG_LEVEL_DEBUG = LOG_LEVEL_DEBUG;
|
Storage debugging messages |
STORAGE_LOG_LEVEL_INFO = LOG_LEVEL_INFO;
|
Storage informational messages, such as a device being attached or detached |
STORAGE_LOG_LEVEL_ERROR = LOG_LEVEL_ERROR;
|
Storage error messages |
STORAGE_LOG_LEVEL_NONE = LOG_LEVEL_NONE;
|
No Storage messages |
USB_STORAGE_*
USBSTORAGE_DRIVER_NAME = 'USB Mass Storage Driver';
|
Name of USB storage driver |
CB/CBI (Control/Bulk/Interrupt) Requests | |
USB_STORAGE_REQUEST_CBI_ADSC = 0;
|
|
BBB (Bulk Only) Requests | |
USB_STORAGE_REQUEST_BBB_RESET = $FF;
|
|
USB_STORAGE_REQUEST_BBB_GET_MAX_LUN = $FE;
|
|
Command Block Wrapper | |
USB_STORAGE_CBW_SIGNATUR = $43425355;
|
|
USB_STORAGE_CBW_FLAGS_OUT = $00;
|
|
USB_STORAGE_CBW_FLAGS_IN = $80;
|
|
USB_STORAGE_CBW_CB_LENGTH = 16;
|
|
USB_STORAGE_CBW_SIZE = 31;
|
|
Command Status Wrapper | |
USB_STORAGE_CSW_SIGNATURE = $53425355;
|
|
USB_STORAGE_CSW_STATUS_GOOD = $00;
|
|
USB_STORAGE_CSW_STATUS_FAILED = $01;
|
|
USB_STORAGE_CSW_STATUS_PHASE = $02;
|
|
USB_STORAGE_CSW_SIZE = 13;
|
|
Command Data | |
USB_STORAGE_COMMAND_MAX_SIZE = 16;
|
|
Command Retry Counts | |
USB_STORAGE_READ_RETRIES = 2;
|
|
USB_STORAGE_WRITE_RETRIES = 2;
|
|
USB_STORAGE_STATUS_RETRIES = 2;
|
|
USB_STORAGE_INQUIRY_RETRIES = 5;
|
|
USB_STORAGE_READ_CAPACITY_RETRIES = 3;
|
|
USB_STORAGE_TEST_UNIT_READY_RETRIES = 5;
|
10; TestingRPi |
Peripheral Device Types | |
These are a subset of the SCSI Peripheral Device Types | |
USB_STORAGE_DEVICE_TYPE_DISK = $00;
|
SBC Direct-access device (e.g., UHD Floppy disk) |
USB_STORAGE_DEVICE_TYPE_CDROM = $05;
|
MMC-5 CD-ROM device |
USB_STORAGE_DEVICE_TYPE_OPTICAL = $07;
|
Optical memory device (e.g., Non-CD optical disks) |
USB_STORAGE_DEVICE_TYPE_RBC = $0E;
|
RBC Direct-access device (e.g., UHD Floppy disk) |
USB_STORAGE_DEVICE_TYPE_UNKNOWN = $1F;
|
Unknown or no device type |
Type definitions
To be documented
Public variables
To be documented
Function declarations
Initialization functions
procedure StorageInit;
Note | None documented |
---|
Storage functions
function StorageDeviceRead(Storage:PStorageDevice; const Start,Count:Int64; Buffer:Pointer):LongWord;
Note | None documented |
---|
function StorageDeviceWrite(Storage:PStorageDevice; const Start,Count:Int64; Buffer:Pointer):LongWord;
Note | None documented |
---|
function StorageDeviceErase(Storage:PStorageDevice; const Start,Count:Int64):LongWord;
Note | None documented |
---|
function StorageDeviceControl(Storage:PStorageDevice; Request:Integer; Argument1:LongWord; var Argument2:LongWord):LongWord;
Note | None documented |
---|
function StorageDeviceSetState(Storage:PStorageDevice; State:LongWord):LongWord;
Storage | The storage to set the state for |
---|---|
State | The new state to set and notify |
Return | ERROR_SUCCESS if completed or another error code on failure |
function StorageDeviceStartStatus(Storage:PStorageDevice; Interval:LongWord):LongWord;
Storage | The storage to start status monitoring for |
---|---|
Interval | The status monitoring interval in milliseconds |
Return | ERROR_SUCCESS if completed or another error code on failure |
function StorageDeviceStopStatus(Storage:PStorageDevice):LongWord;
Storage | The storage to stop status monitoring for |
---|---|
Return | ERROR_SUCCESS if completed or another error code on failure |
function StorageDeviceCreate:PStorageDevice;
Return | Pointer to new Storage entry or nil if storage could not be created |
---|
function StorageDeviceCreateEx(Size:LongWord):PStorageDevice;
Size | Size in bytes to allocate for new storage (Including the storage entry) |
---|---|
Return | Pointer to new Storage entry or nil if storage could not be created |
function StorageDeviceDestroy(Storage:PStorageDevice):LongWord;
Note | None documented |
---|
function StorageDeviceRegister(Storage:PStorageDevice):LongWord;
Note | None documented |
---|
function StorageDeviceDeregister(Storage:PStorageDevice):LongWord;
Note | None documented |
---|
function StorageDeviceFind(StorageId:LongWord):PStorageDevice;
Note | None documented |
---|
function StorageDeviceFindByName(const Name:String):PStorageDevice; inline;
Note | None documented |
---|
function StorageDeviceFindByDescription(const Description:String):PStorageDevice; inline;
Note | None documented |
---|
function StorageDeviceEnumerate(Callback:TStorageEnumerate; Data:Pointer):LongWord;
Note | None documented |
---|
function StorageDeviceNotification(Storage:PStorageDevice; Callback:TStorageNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
Note | None documented |
---|
USB storage functions
function USBStorageDeviceRead(Storage:PStorageDevice; const Start,Count:Int64; Buffer:Pointer):LongWord;
Note | According to 3.4 of USB Mass Storage Bulk Only 1.0, requests must be queued one at a time to a device |
---|
function USBStorageDeviceWrite(Storage:PStorageDevice; const Start,Count:Int64; Buffer:Pointer):LongWord;
Note | According to 3.4 of USB Mass Storage Bulk Only 1.0, requests must be queued one at a time to a device |
---|
function USBStorageDeviceControl(Storage:PStorageDevice; Request:Integer; Argument1:LongWord; var Argument2:LongWord):LongWord;
Note | According to 3.4 of USB Mass Storage Bulk Only 1.0, requests must be queued one at a time to a device |
---|
function USBStorageDriverBind(Device:PUSBDevice; Interrface:PUSBInterface):LongWord;
Device | The USB device to attempt to bind to |
---|---|
Interrface | The USB interface to attempt to bind to (or nil for whole device) |
Return | USB_STATUS_SUCCESS if completed, USB_STATUS_DEVICE_UNSUPPORTED if unsupported or another error code on failure |
function USBStorageDriverUnbind(Device:PUSBDevice; Interrface:PUSBInterface):LongWord;
Device | The USB device to unbind from |
---|---|
Interrface | The USB interface to unbind from (or nil for whole device) |
Return | USB_STATUS_SUCCESS if completed or another error code on failure |
procedure USBStorageReadComplete(Request:PUSBRequest);
Request | The USB request which has completed |
---|---|
Note | The thread that submitted the read request will hold the storage lock |
procedure USBStorageWriteComplete(Request:PUSBRequest);
Request | The USB request which has completed |
---|---|
Note | The thread that submitted the write request will hold the storage lock |
procedure USBStorageInterruptComplete(Request:PUSBRequest);
Request | The USB request which has completed |
---|---|
Note | The thread that submitted the interrupt request will hold the storage lock |
Storage helper functions
function StorageGetCount:LongWord; inline;
Note | None documented |
---|
function StorageDeviceCheck(Storage:PStorageDevice):PStorageDevice;
Note | None documented |
---|
function StorageDeviceTypeToString(StorageType:LongWord):String;
Note | None documented |
---|
function StorageDeviceStateToString(StorageState:LongWord):String;
Note | None documented |
---|
function StorageDeviceStateToNotification(State:LongWord):LongWord;
Note | None documented |
---|
procedure StorageLog(Level:LongWord; Storage:PStorageDevice; const AText:String);
Note | None documented |
---|
procedure StorageLogInfo(Storage:PStorageDevice; const AText:String);
Note | None documented |
---|
procedure StorageLogError(Storage:PStorageDevice; const AText:String);
Note | None documented |
---|
procedure StorageLogDebug(Storage:PStorageDevice; const AText:String);
Note | None documented |
---|
procedure StorageStatusTimer(Storage:PStorageDevice);
Note | None documented |
---|
USB storage helper functions
function USBStorageCheckSubclass(Subclass:Byte):Boolean;
Note | None documented |
---|
function USBStorageCheckProtocol(Protocol:Byte):Boolean;
Note | None documented |
---|
function USBStorageBlockSizeToBlockShift(BlockSize:LongWord):LongWord;
Note | None documented |
---|
function USBStoragePatchDevice(Device:PUSBDevice; var Subclass,Protocol:Byte):LongWord;
Note | None documented |
---|
function USBStorageFixupDevice(Device:PUSBDevice; var Vendor,Product:String):LongWord;
Note | None documented |
---|
function USBStorageDeviceLock(Device:PUSBDevice; Storage:PUSBStorageDevice):LongWord;
Note | None documented |
---|
function USBStorageDeviceUnlock(Device:PUSBDevice; Storage:PUSBStorageDevice):LongWord;
Note | None documented |
---|
function USBStorageDeviceLoad(Device:PUSBDevice; Storage:PUSBStorageDevice):LongWord;
Note | None documented |
---|
function USBStorageDeviceEject(Device:PUSBDevice; Storage:PUSBStorageDevice):LongWord;
Note | None documented |
---|
function USBStorageDeviceReset(Device:PUSBDevice; Storage:PUSBStorageDevice):LongWord;
Note | Reset recovery (5.3.4 in USB Mass Storage Bulk Only 1.0) . For Reset Recovery the host shall issue in the following order: a) a Bulk-Only Mass Storage Reset b) a Clear Feature HALT to the Bulk-In endpoint c) a Clear Feature HALT to the Bulk-Out endpoint This is done in 3 steps. If the reset doesn't succeed, the device should be port reset. |
---|
function USBStorageDeviceGetInfo(Device:PUSBDevice; Storage:PUSBStorageDevice):LongWord;
Note | None documented |
---|
function USBStorageDeviceGetStatus(Device:PUSBDevice; Storage:PUSBStorageDevice):LongWord;
Note | Supported by Subclass SCSI/UFI/SFF8070 |
---|
function USBStorageDeviceGetMaxLUN(Device:PUSBDevice; Storage:PUSBStorageDevice; var MaxLUN:Byte):LongWord;
Note | None documented |
---|
function USBStorageDeviceClearStall(Device:PUSBDevice; Storage:PUSBStorageDevice; Endpoint:PUSBEndpointDescriptor):LongWord;
Note | None documented |
---|
function USBStorageDeviceInquiry(Device:PUSBDevice; Storage:PUSBStorageDevice; var DeviceType,DeviceFlags:LongWord;v ar Vendor,Product,Revision:PChar):LongWord;
Note | Supported by Subclass SCSI/UFI/SFF8070 |
---|
function USBStorageDeviceRequestSense(Device:PUSBDevice; Storage:PUSBStorageDevice; var SenseKey,ASC,ASCQ:Byte):LongWord;
Note | Supported by Subclass SCSI/UFI/SFF8070 |
---|
function USBStorageDeviceReadCapacity(Device:PUSBDevice; Storage:PUSBStorageDevice; var BlockSize,BlockShift:LongWord; var BlockCount:Int64):LongWord;
Note | Supported by Subclass SCSI/UFI/SFF8070 |
---|
function USBStorageDeviceTestUnitReady(Device:PUSBDevice; Storage:PUSBStorageDevice; var DeviceFlags:LongWord):LongWord;
Note | Supported by Subclass SCSI/UFI/SFF8070 |
---|
function USBStorageDeviceRead10(Device:PUSBDevice; Storage:PUSBStorageDevice; Start:LongWord;Count:Word; Buffer:Pointer):LongWord;
Note | Supported by Subclass SCSI/UFI/SFF8070. Caller must hold the storage lock. |
---|
function USBStorageDeviceWrite10(Device:PUSBDevice; Storage:PUSBStorageDevice; Start:LongWord; Count:Word; Buffer:Pointer):LongWord;
Note | Supported by Subclass SCSI/UFI/SFF8070. Caller must hold the storage lock. |
---|
function USBStorageDeviceRead16(Device:PUSBDevice; Storage:PUSBStorageDevice; const Start,Count:Int64; Buffer:Pointer):LongWord;
Note | Supported by Subclass SCSI only (Only on devices > 2TB). Caller must hold the storage lock. |
---|
function USBStorageDeviceWrite16(Device:PUSBDevice; Storage:PUSBStorageDevice; const Start,Count:Int64; Buffer:Pointer):LongWord;
Note | Supported by Subclass SCSI only (Only on devices > 2TB). Caller must hold the storage lock. |
---|
function USBStorageDeviceTransport(Device:PUSBDevice; Storage:PUSBStorageDevice; Command:PUSBCommandBlock):LongWord;
Note | Handles Command / Data / Status phases plus endpoint stall, reset and retry as per the specification. Supported by Subclass SCSI/UFI/SFF8070. Caller must hold the storage lock. |
---|
Return to Unit Reference