A host can use the MODE SELECT command to specify parameters relating to the storage media, a logical unit, or the device itself. The information is in structures called block descriptors and mode pages. There are two commands that differ in the size and format of the mode-parameter header that precedes any block descriptors and mode pages being sent. MODE SELECT(6) has a 4-byte header, and MODE SELECT(10) has an 8-byte header. Support for MODE SELECT is optional unless the device also supports
MODE SENSE as explained below.
Mode page 08h is the caching mode page. The Windows mass-storage driver attempts to read the page and if supported, send a page to disable caching unless the user has selected optimize for performance for the volume in Device Manager > Properties > Policies.
The MODE SENSE commands are the complements to the MODE SELECT commands. A host can use MODE SENSE to request parameters relating to the storage media, a logical unit, or the device itself. As with MODE SELECT, there are two commands that differ in the size and format of the mode-parameter header that precedes any block descriptors and mode pages being returned. MODE SENSE(6) has a 4-byte header, and MODE SENSE(10) has an 8-byte header.
The SPC specification says that a device that supports a MODE SENSE command should support the corresponding MODE SELECT command, and a device that supports a MODE SELECT command should support the corresponding MODE SENSE command. The MODE SENSE command is optional for many SBC devices, but Windows and other hosts use this command to request information from devices. Bootable devices must support MODE SENSE(10).
Each MODE SENSE command block contains a page code and a subpage code that together specify what information the host is requesting. The SBC specification defines a variety of mode pages. When SUBPAGE CODE = 00h, the mode page uses the page_0 format. The page includes fields for the page code, page length, and mode parameters. For other subpage codes, the mode page uses the subpage format, which adds a field for a subpage code.
When communicating with direct-access block devices (PDT = 00h), the Windows mass-storage driver and other hosts commonly request these mode pages:
PAGE CODE = 3Fh requests all supported mode pages.
PAGE CODE = 1Ch requests the informational exceptions control mode page. This page contains information about how the device reports exception conditions due to vendor-specific events and conditions that result from scans or self-tests a device performs in the background (using no bus bandwidth).
PAGE CODE = 08h requests the caching mode page, which defines parameters that relate to a device’s use of its cache.
PAGE CODE = 05h is the flexible disk mode page (FDMP), which contains parameters needed to convert between LBA and CHS addressing. Some hosts refuse to try booting from devices that lack this page, possibly because the boot code uses CHS addressing. The USB bootability specification requires support for this page in all bootable devices with a PDT other than 05h (CD/DVD drive). The bootability specification redefines mode page 05h as a simplified version of the page defined in the original SBC
specification. (Note that the mode page is listed as obsolete in SBC-2 and later but the USB version of the page is required for bootable USB devices.)
A response to a MODE SENSE command begins with a mode parameter header (Table 6-5). Note that in byte 2, bit 7, an SBC device informs the host whether the media is write-protected.
Following the header, an SBC device may send a mode parameter block descriptor that specifies the number of logical blocks in the media and the block size. A response can also contain one or more mode pages and/or mode subpages.
On receiving a MODE SENSE command for an unsupported mode page, a device should fail the command and return SENSE KEY = ILLEGAL REQUEST and ADDITIONAL SENSE CODE = INVALID FIELD IN COMMAND PACKET. Some devices with no data to send respond by sending just the header. In response to a MODE SENSE(6) command, a device with no data to return can return the header with MODE DATA LENGTH = 3 and BLOCK DESCRIPTER LENGTH = 0.
Table 6-5: The data-transport phase in a MODE SENSE(6) command begins with this header.
The MSDModeSenseHandler function prepares a response to a MODE SENSE(6) command, writing data to return into msd_buffer and setting fields in the command’s CSW:
// Set values to return, from SPC spec, section 7.4.3 and SBC spec, section 6.3.1.
msd_buffer = 0×03; // The number of bytes that follow.
msd_buffer = 0×00; // The media type is SBC.
msd_buffer = 0×00; // Not write-protected, no cache-control-bit support.
msd_buffer = 0×00; // No mode-parameter block descriptors.