SDPARM(8)

NAME
sdparm - fetch and potentially change SCSI device attributes. Send commands.

SYNOPSIS
sdparm [--all] [--clear=STR] [--command=CMD] [--dbd] [--defaults] [--dummy] [--flexible] [--get=STR] [--help] [--hex] [--inquiry] [--long] [--page=PG[,SPG]] [--quiet] [--save] [--set=STR] [--six] [--transport=TN] [--vendor=VN] [--verbose] [--version] DEVICE

sdparm --enumerate [--all] [--inquiry] [--long] [--page=PG[,SPG]] [--transport=TN] [--vendor=VN]

sdparm --wscan [--verbose]

DESCRIPTION

This utility fetches and potentially changes SCSI device (e.g. disk) mode pages. Inquiry data including Vital Product Data (VPD) pages can also be displayed. Commands associated with starting and stopping the medium; loading and unloading the medium; and other housekeeping functions may also be performed by this utility.

Of the three invocations shown in the synopsis, the first is the most general. The second variant which uses --enumerate is for dumping information held in sdparm's internal tables. The last variant is for Windows only and lists the available device names; see the OPTIONS entry for --wscan.

If no options (other than DEVICE) are given then a selection of common mode page attributes for that DEVICE are listed. If the --long option is also given then a description of the attributes is placed to the right of each line. If the --all option is given then all known mode page attributes for that DEVICE are listed. Individual attributes can be displayed with the --get=STR option (e.g. '--get=WCE' to fetch the state of the Writeback Cache Enable attribute).

By default this utility shows mode pages that are common to all transport protocols. These are termed as "generic" mode pages in this utility. Transport protocol specific mode pages are selected with the --transport=TN option. See the TRANSPORT section below. Vendo specific mode pages are selected with the --vendor=VN option. See the VENDORS section below.

Although originally for SCSI disks (or storage devices that appear to the OS as SCSI disks) many of the mode pages are for other SCSI device types. These include CD/DVD players that use the ATAPI (or any other) transport, SCSI tapes drives and SCSI enclosures.

When the --inquiry option is given without a page number then the Device Identification VPD page (page number 0x83) is requested and if found it is decoded and output. If no page number is given and the --all option is given then a list of VPD page names (but not their contents) supported by the DEVICE is output. When both the --inquiry and --page=PG options are given then the VPD page can be specified as an abbreviation (e.g. "sp" for the SCSI Ports VPD page) or numerically (e.g. "0x88"). If a VPD page is returned by the DEVICE but sdparm cannot decode it (or the --hex option is given) then the page is output in hex.

OPTIONS
Mandatory arguments to long options are mandatory for short options as well. If an option takes a numeric argument then that argument is assumed to be decimal unless otherwise indicated (e.g. with a leading "0x" or a trailing "h").

-a, --all
    output all recognized attributes for the peripheral device type (e.g. disk) for the DEVICE. Without this option (or the --page=PG[,SPG] option) the default action is to output a relatively small number of commonly used attributes from different pages. When a specific (mode) page number is given with the --page=PG[,SPG] option then all the attributes of that page are output (irrespective of the setting of this option). For this option's action when used together with the --enumerate option see the ENUMERATE section below.

-c, --clear=STR
    The STR contains a comma separated list of attribute acronyms. In the absence of an explicit value argument (e.g. '--clear=WCE=1'), each acronym has its value cleared to zero. Utility completes with exit status 0 if successful. See the PARAMETERS section below.

-C, --command=CMD
    Perform given CMD. See section below on COMMANDS. If successful then the exit status is 0. To enumerate supported commands use '-e -C x' (using any CMD name, valid or otherwise).

-B, --dbd
    disable block descriptors. This is a bit in MODE SENSE cdbs that rarely needs to be set. One known case is a MODE SENSE 6 issued to a Reduced Block Commands (RBC) device where the RBC standard says it shall be set.

-D, --defaults
    sets the given mode page to its default values. Requires the --page=PG[,SPG] option to be given to specify the mode page. To make the default mode page values also the saved mode page values, use the --save option as well.

-d, --dummy
    when set inhibits changes being placed in the DEVICE's mode page. Instead the mode data that would have been sent to a MODE SELECT command, is output in ASCII hex to the console. This option is mainly for testing.

-e, --enumerate
    lists out descriptive information about the pages and attributes known to this utility. Ignores the DEVICE argument and other options apart from the --all, --inquiry, --long, --page=PG[,SPG], --transport=TN and --vendor=VN. If --enumerate is given without other options then the known (generic) mode pages are listed. See the ENUMERATE section below.

-f, --flexible
    Some devices, bridges and/or drivers attempt crude transformations between mode sense 6 and 10 byte commands without correctly rebuilding the response. This will cause the response to be mis-interpreted (usually with an error saying the response is malformed). With this option, the length of the response is checked, and if it looks wrong, various corrections are attempted. This option will also allow mode pages that don't belong to the current device's peripheral type to be listed.

-g, --get=STR
    The STR contains a comma separated list of attribute acronyms whose values are to be fetched. See the PARAMETERS section below. The --long and --hex options effect the output format. Also if a value of "1" is given (e.g. '--get=WCE=1') only the current value is output.

-h, --help
    output the usage message then exit.

-H, --hex
    rather than trying to decode mode (or VPD) pages, print them out in hex. When used with the --get=STR option the corresponding current, changeable, default and saved values are output in hex, prefixed by "0x" and space separated. If a value of "1" is given with the --get=STR option (e.g. '--get=WCE=1') then only the current value is output in hex, prefixed by "0x". If a value of "2" is given with the --get=STR option then only the current value is output as a (signed) integer. This option can be used multiple times (e.g. '-HH'). Useful with the ATA Information VPD page which usually outputs its IDENTIFY (PACKET) DEVICE response in 16 bit hex words; with '-HH' outputs that response in hex bytes; with '-HHH' outputs the same response in a format suitable for 'hdparm --Istdin' to decode.

-i, --inquiry
    output INQUIRY VPD pages. In the absence of this option the default action is to output mode pages. If the --inquiry option is given without the --page=PG[,SPG] option then the device identification VPD page (0x83) is decoded and output. If this option and the --all option are given then the supported VPD pages page (0x0) is decoded and output.

-l, --long
    output extra information. In the case of mode page attributes a description (with units if applicable) is output to the right. If used twice, then for some attributes additional information is provided on one or more following lines, each prefixed by a tab character. For usage with --enumerate see the ENUMERATE section below.

-p, --page=PG[,SPG]
    supply the page number (PG) and optionally the sub page number (SPG) of the mode or VPD page to fetch. These numbers are interpreted as decimal unless prefixed with "0x" or a trailing 'h'. Sub page numbers are only valid for mode pages, not VPD pages. Alternatively an abbreviation for a page can be given (see next entry).

-p, --page=STR
    where STR is an abbreviation for a page name. Known mode page abbreviations are checked first followed by known VPD page abbreviations. For example '--page=ca' matches the caching mode page. If no match is found then an error is issued and a list of possibilities in the current context is given (so '-p x' can be quite useful). If the STR matches a known VPD page abbreviation then the --inquiry option is assumed. For usage with --enumerate see the ENUMERATE section below.

-q, --quiet
    suppress output of the device name followed by the vendor, product and revision strings fetched from an INQUIRY response. Without this option such a line is typically the first line output by sdparm. Reduces output from the device identification VPD page, typically to one line (or none) for each of di_lu, di_port, di_target and di_asis.

-S, --save
    when a mode page is being modified (by using the --clear=STR and/or --set=STR options) then the default action is to modify only the current values mode page. When this option is given then the corresponding value(s) in the saved values mode page is also changed. The next time the device is power cycled (or reset) the saved values mode page becomes (i.e. is copied to) the current values mode page. See the NOTES section below.

-s, --set=STR
    The STR contains a comma separated list of attribute acronyms. In the absence of an explicit value, each acronym has its value set to "all ones" in a binary sense. This means a 16 bit field will be set to 0xffff which is 65535 in decimal. Alternatively each acronym may be followed by "=<n>" where <n> is the value to set that attribute to. This utility exits with process status 0 if successful. See the PARAMETERS section below.

-6, --six
    The default action of this utility is to issue MODE SENSE and MODE SELECT SCSI commands with 10 byte cdbs. When this option is given the 6 byte cdb variants are used. RBC and old SCSI devices may need this option. This utility outputs a suggestion to use this option if the SCSI status indicates that the 10 byte cdb variant is not supported.

-t, --transport=TN
    Specifies the transport protocol where TN is either a number in the range 0 to 15 (inclusive) or an abbreviation (e.g. "fcp" for the Fibre Channel Protocol). One way to list available transport protocols numbers and their associated abbreviations is to give an invalid transport protocol number such as '-t x'; another way is '-e -l'.

-M, --vendor=VN
    Specifies the vendor (i.e. manufacturer) where VN is either a number or an abbreviation (e.g. "sea" for Seagate disk vendor specific). One wa to list available vendor numbers and their associated abbreviations is to give an invalid vendor number such as '-M x'; another way is '-e -l'.

-v, --verbose
    increase the level of verbosity, (i.e. debug output). In some cases more decoding is done (e.g. fields within a standard INQUIRY response).

-V, --version
    print the version string and then exit.

-w, --wscan
    this option is available in Windows only. It lists the device names that are available. In many cases there is more than one device name for an actual device. This option attempts to group all device names for one device on a single line (exceptions: USB and IEEE 1394 devices). See the "Win32 port" section in the README file.

NOTES
A mode page for which no abbreviation is known (e.g. a vendor specific mode page) can be listed in hexadecimal by using the option combination '--page=PG --hex'.

Numbers input to sdparm (e.g. in the command line arguments) are assumed to be in decimal unless there is a hexadecimal indicator. A hexadecimal indicator is either a leading '0x' or '0X' (i.e. the C language convention) or a trailing 'h' or 'H' (i.e. the convention used at www.t10.org ). In the case of --page= either a string or number is expected, so hex numbers like 'ch' (12) should be prefixed by a zero (e.g. '0ch').

The SPC-4 draft (rev 9) says that devices that implement no distinction between current and saved pages can return an error (ILLEGAL REQUEST, invalid field in cdb) if the SP bit (which corresponds to the --save option) is _not_ set. In such cases the --save option needs to be given.

If the --save option is given but the existing mode page indicates (via its PS bit) that the page is not savable, then this utility generates an error message. That message suggests to try again without the --save option.

Since the device identification VPD page (acronym "di") potentially contains a lot of diverse designators, several associated acronyms are available. They are "di_lu" for designators associated with the addressed logical unit, "di_port" for designators associated with the target port (which the command arrived via) and "di_target" for designators associated with the target device. When "di" is used designators are grouped by lu, then port and then target device. To see all designators decoded in the order that they appear in the VPD page use "di_asis".

In the linux kernel 2.6 series any device node that understands a SCSI command set (e.g. SCSI disks and CD/DVD drives) may be specified. More precisely the driver that "owns" the device node must support the SG_IO ioctl. In the lk 2.4 series only SCSI generic (sg) device nodes support the SG_IO ioctl. However in the lk 2.4 series other SCSI device nodes are mapped within this utility to their corresponding sg device nodes. So if there is a SCSI disk at /dev/sda then 'sdparm /dev/sda' will work in both the lk 2.6 and lk 2.4 series. However if there is an ATAPI cd/dvd drive at /dev/hdc then 'sdparm /dev/hdc' will only work in the lk 2.6 series.

In FreeBSD the "atapicam" device may need to be configured into the kernel in order that sdparm can access (s)ATAPI cd/dvd drives.

PARAMETERS
The --clear=, --get= and --set= options can take a string argument which is a comma separated list of attributes. Each attribute can be either an acronym name or a <start_byte>:<start_bit>:<num_bits> tuple. Either form can optionally be followed by "=<val>". Acronyms (e.g. WCE for "Writeback Cache Enable") that this utility supports can be listed with the --enumerate option. Alternatively, a mode page attribute to be changed can be described in terms of a <start_byte> (origin 0) within the mode page, a <start_bit> (0 to 7 inclusive) and <num_bits> (1 to 64 inclusive). For example, the low level representation of the RCD bit (in the caching mode page) is "2:0:1". The <start_byte> and the <val> can optionally be given in hex (e.g. '--set=0x2:0:1=0x1' or '--set=2h:0:1=1h').

When the attribute(s) following --clear= is not given an explicit '=<val>' then the value defaults to zero. When the attribute(s) following --set= is not given an explicit '=<val>' then the value defaults to "all ones" in a binary sense (i.e. as many as <num_bits> permits). For example '--clear=WCE' and '--clear=WCE=0' have the same meaning: clear Writeback Cache Enable or, put more simply: turn off the writeback cache.

When an attribute acronym is given then the mode page is imputed from that acronym (e.g. sdparm knows that 'WCE' is in the caching mode page). When only the start_byte:start_bit:num_bits form is used then the --page= option must be given to establish which mode page is to be used. A restriction placed on --clear= and --set= is that if multiple parameters are given, they must all be in the same mode page. Hence each invocation of this utility can only modify one mode page.

ENUMERATE
The --enumerate option essentially dumps out static information held by this utility. A list of --enumerate variants and their actions follows. For brevity subsequent examples of options are shown in their shorter form.

    --enumerate list generic mode page information
    -e --all list generic mode page contents
                        (i.e. parameters)
    -e --page=rw list contents of read write error
                        recovery mode page
    -e --inquiry list VPD pages this utility can decode
    -e --long list generic mode pages, transport
                        protocols, mode pages for each
                        supported transport protocol and
                        supported commands
    -e -l --all additionally list the contents of
                        each mode page
    -e --transport=fcp list mode pages for the fcp
                        transport protocol
    -e -t fcp --all additionally list the contents of
                        each mode page
    -e --vendor=sea list vendor specific mode pages for
                        "sea" (Seagate)
    -e -M sea --all additionally list the contents of vendor
                        specific mode pages for "sea" (Seagate)

When known mode pages are listed (via the --enumerate option) each line starts with a two or three letter abbreviation. This is followed by the page number (in hex prefixed by "0x") optionally followed by a comma and the subpage number. Finally the descriptive name of the mode page (e.g. as found in SPC-4) is output.

When known parameters (fields) of a mode page are listed, each line starts with an acronym (indented a few spaces). This will match (or be an acronym for) the description for that field found in the (draft) standards. Next are three numbers, separated by colons, surrounded by brackets. These are the start byte (in hex, prefixed by "0x") of the beginning of the field within the mode page; the starting bit (0 through 7 inclusive) and then the number of bits. The descriptive name of the parameter (field) is then given. If appropriate the descriptive name includes units (e.g. "(ms)" means the units are milliseconds). Adding the '-ll' option will list information about possible field values for the selected mode page parameters.

Mode parameters for which the num_bits is greater than 1 can be viewed as unsigned integers. Often 16 and 32 bit fields are set to 0xffff and 0xffffffff respectively (i.e. "all ones" in a binary sense). This utility outputs such values as "-1" to save space (rather than their unsigned integer equivalents). "-1" can also be given as the value to a mode page field acronym (e.g. '--set=INTT=-1' sets the interval timer field in the Informational Exceptions control mode page to 0xffffffff).

TRANSPORTS
SCSI transport protocols are a relatively specialized area that can be safely ignored by the majority of users.

Some transport protocols have protocol specific mode pages. These are usually the disconnect-reconnect (0x2), the protocol specific logical unit (0x18) and the protocol specific port (0x19) mode pages. In some cases the latter mode page has several subpages. The most common transport protocol abbreviations likely to be used are "fcp", "spi" and "sas".

Many of the field names are re-used in the same position so the acronym namespaces have been divided between generic mode pages (i.e. when the --transport= option is _not_ given) and a namespace for each transport protocol. A LUPID field from the protocol specific logical unit (0x18) mode page and the PPID field from protocol specific port (0x19) mode page are included in the generic modes pages; this is so the respective (transport) protocol identifiers can be seen. In most cases the user will know what the "port" transport is (i.e. the same transport as the HBA in the computer). Note that a logical unit's transport could be different from the HBA's transport if a bridge is present.

The logic in sdparm requires acronyms to be unique within a namespace. This becomes difficult if a mode page has multiple descriptors each of which has the same set of acronyms. The SAS "phy control and discover" mode page is an example of this. The current solution is to prepend "2_" to the second set of acronyms.

VENDORS
SCSI leaves a lot of space for vendor specific information. Often this is described in product manuals. The --vendor=VN (or -M=VN) option allows known vendor specific mode pages to be examined and/or modified by acronym.

In this utility the syntax and semantics of vendor specific mode pages is very similar to those of transport protocol specific mode pages. Both cannot be specified together. Vendor specific modes pages can still be accessed numerically (as shown at the end of the EXAMPLES section).

COMMANDS
The --command=CMD option sends the SCSI command indicated by CMD to the DEVICE. If the command fails then this is reflected in the non-zero exit status. To obtain more information about the error use the -v option.

When CMD is 'capacity' a READ CAPACITY command (valid for disks and cd/dvd media) is sent. If successful yields "blocks: " [the number of blocks], "block_length: " [typically either 512 or 2048] and "capacity_mib: " [capacity in MibiBytes (1048576 byte units)].

When CMD is 'eject' a SCSI command which stops the medium and ejects it is sent. Note that ejection (by command or button) may be prevented in which case the 'unlock' command may be useful in extreme cases. Typically only appropriate for cd/dvd drives and disk drives with removable media. Objects if sent to another peripheral device type (but objection can be overridden with '-f' option).

When CMD is 'load' a SCSI command which loads the medium and starts it (i.e. spins it up). See 'eject' command for supported device types.

When CMD is 'ready' a TEST UNIT READY command is sent. No error is reported if the device will respond to data requests (e.g. READ) in a reasonable timescale. For example, if a disk is stopped then it will report "not ready". All devices should respond to this command.

When CMD is 'sense' a REQUEST SENSE command is sent. It reports a hardware threshold exceeded, warning or low power condition if flagged. If a progress indication is present (e.g. during a format) then it will be output as a percentage. Yields a process status of 0 if the command succeeds and the sense key is 0. The --quiet option can be used to lessen output, and --hex to output sense data in hex.

When CMD is 'start' a SCSI command which starts the medium (i.e. spins it up) is sent. Harmless if medium has already been started. See 'eject' command for supported device types.

When CMD is 'stop' a SCSI command which stops the medium (i.e. spins it down) is sent. Harmless if medium has already been stopped. See 'eject' command for supported device types.

When CMD is 'sync' a SYNCHRONIZE CACHE command is sent. The DEVICE should flush any data held in its (volatile) buffers to the media.

When CMD is 'unlock' a SCSI command which tells the DEVICE to allow medium removal is sent. It uses the SCSI PREVENT ALLOW MEDIUM REMOVAL command. This is desperation stuff, possibly overriding a prevention applied by the OS on a mounted file system. The "eject" utility (from the "eject" package) is more graceful and should be tried first. This command is only appropriate for devices with removable media.

For loading and ejecting tapes the mt utility should be used (i.e. not these commands). The 'ready' command is valid for tape devices.

EXAMPLES
To list the common (generic) mode parameters of a disk:

   sdparm /dev/sda

To list the designators within the device identification VPD page of a disk:

   sdparm --inquiry /dev/sda

To see all parameters for the caching mode page:

   sdparm --page=ca /dev/sda

To see all parameters for the caching mode page with parameter descriptions to the right:

   sdparm --page=ca --long /dev/sda

To get the WCE values (current changeable default and saved) in hex:

   sdparm -g WCE -H /dev/sda
0x01 0x00 0x01 0x01

To get the WCE current value in hex:

   sdparm -g WCE=1 -H /dev/sda
0x01

To set the "Writeback Cache Enable" bit in the current values page:

   sdparm --set=WCE /dev/sda

To set the "Writeback Cache Enable" bit in the current and saved values page:

   sdparm --set=WCE --save /dev/sda

To set the "Writeback Cache Enable" and clear "Read Cache Disable":

   sdparm --set=WCE --clear=RCD --save /dev/sda

The previous example can also by written as:

   sdparm -s WCE=1,RCD=0 -S /dev/sda

To re-establish the manufacturer's defaults in the current and saved values of the caching mode page:

   sdparm --page=ca --defaults --save /dev/sda

If an ATAPI cd/dvd drive is at /dev/hdc then its common (mode) parameters could be listed in the lk 2.6 series with:

   sdparm /dev/hdc

If there is a DVD in the drive at /dev/hdc then it could be ejected in the lk 2.6 series with:

   sdparm --command=eject /dev/hdc

If the ejection is being prevented by software then that can be overridden with:

   sdparm --command=unlock /dev/hdc

One disk vendor has a "Performance Mode" bit (PM) in the vendor specific unit attention mode page [0x0,0x0]. PM=0 is server mode (the default) while PM=1 is desktop mode. Desktop mode can be set (both current and saved values) with:

   sdparm --page=0 --set=2:7:1=1 --save /dev/sda

The resultant change can be viewed in hex with the --hex option as there are no acronyms in the generic mode pages. The PM bit is now covered by vendor specific mode pages and the above can also be accomplished with:

   sdparm --vendor=sea --set=PM --save /dev/sda

EXIT STATUS
To aid scripts that call these utilities, the exit status is set to indicate success (0) or failure (1 or more). Note that some of the lower values correspond to the SCSI sense key values to which they correspond. The exit status values are:

0   success

1   syntax error. Either illegal command line options, options with bad arguments or a combination of options that is not permitted.

2   the DEVICE reports that it is not ready for the operation requested. The device may be in the process of becoming ready (e.g. spinning up but not at speed) so the utility may work after a wait.

3   the DEVICE reports a medium or hardware error (or a blank check). For example an attempt to read a corrupted block on a disk will yield this value.

5   the DEVICE reports an "illegal request" with an additional sense code other than "invalid operation code". This is often a supported command with a field set requesting an unsupported capability. For commands that require a "service action" field this value can indicate that the command is not supported.

6   the DEVICE reports a "unit attention" condition. This usually indicates that something unrelated to the requested command has occurred (e.g. a device reset) potentially before the current SCSI command was sent. The requested command has not been executed by the device. Note that unit attention conditions are usually only reported once by a device.

9   the DEVICE reports an illegal request with an additional sense code of "invalid operation code" which means that it doesn't support the requested command.

11  the DEVICE reports an aborted command. In some cases aborted commands can be retried immediately (e.g. if the transport aborted the command due to congestion).

15  the utility is unable to open, close or use the given DEVICE. The given file name could be incorrect or there may be permission problems. Adding the -v option may give more information.

20  the DEVICE reports it has a check condition but "no sense". Some polling commands (e.g. REQUEST SENSE) can react this way. It is unlikely that this value will occur as an exit status.

21  the DEVICE reports a "recovered error". The requested command was successful. Most likely a utility will report a recovered error to stderr and continue, probably leaving the utility with an exit status of 0 .

33  the command sent to DEVICE has timed out. This occurs in Linux only; in other ports a command timeout will appear as a transport (or OS) error.

97  the response to a SCSI command failed sanity checks.

98  the DEVICE reports it has a check condition but the error doesn't fit into any of the above categories.

99  any errors that can't be categorized into values 1 to 98 may yield this value. This includes transport and operating system errors after the command has been sent to the device.

Most of the error conditions reported above will be repeatable (an example of one that is not is "unit attention") so the utility can be run again with the -v option (or several) to obtain more information.

AUTHORS
Written by Douglas Gilbert.

REPORTING BUGS
Report bugs to <dgilbert at interlog dot com>.

COPYRIGHT
Copyright © 2005-2007 Douglas Gilbert
This software is distributed under a FreeBSD license. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

SEE ALSO
sg_modes(8), sg_wr_mode(8), sginfo(8), sg_inq(8) sg_vpd(8) [all in sg3_utils], hdparm(8), smartmontools(smartmontools.sourceforge.net), mt, eject(1)