The USB mass storage driver is used to communicate with mass storage devices such as flash drives, external hard drives, and other types of removable media connected through USB. The USB mass storage driver is split into two parts.
SCSI block device
The block device implements BlockImplQuery, and BlockImplQueue. It supports read, write, and flush operations. If power is lost between a write operation and a flush operation, changes written to a USB mass storage device may not be persisted to the device. The driver has no mechanism to inform drivers higher up in the stack of when a write has actually been written to physical media. For the purposes of USB mass storage, a write is considered complete when the device acknowledges the write.
The core device serves as the interface between the block device and the USB stack. The core accepts requests from the block device, and converts them into USB requests, which are eventually sent to hardware through the USB stack. For each request, the following steps are performed:
- Request is added to a queue.
- Request is picked up by the worker thread.
- SCSI command stored in the request is sent to the device.
- Request status is read back from the device.
- Completion callback is invoked, informing the block device layer that the request has been completed.
Some USB mass storage devices may have multiple block devices such as an array of disks. In this case, the core driver creates one block device per disk.