SG_READCAP(8)
π sg_readcap(8) π
okay so welcome to the SG3_UTILS manual page for sg_readcap, bestie. it's a whole thing about the SCSI READ CAPACITY command and i'm gonna walk you through every single bit of it, no cap. grab a snack. π
β¨ NAME β¨
sg_readcap β sends the SCSI READ CAPACITY command. that's it, that's the whole job, and it does it iconically. π
π¦ SYNOPSIS π¦
the preferred glow-up syntax:
sg_readcap [--10] [--16] [--brief] [--help] [--hex] [--inhex=FN]
[--json[=JO]] [--js-file=JFN] [--lba=LBA] [--long] [--pmi] [--raw]
[--readonly] [--verbose] [--version] [--zbc] DEVICE
and the vintage, pre-loved syntax:
sg_readcap [-16] [-b] [-h] [-H] [-lba=LBA] [-pmi] [-r] [-R] [-v] [-V]
[-z] DEVICE
πΈ DESCRIPTION πΈ
so like, the normal everyday action of the SCSI READ CAPACITY command is literally just fetching the number of blocks (and the block size) from the DEVICE. simple. chic. π
but here's the plot twist: the SCSI READ CAPACITY command (both the 10 and 16 byte cdbs) actually hands you the block address of the last block plus the block size. so the number of blocks is one plus the block address of the last block β because blocks are counted origin zero (i.e. starting at block zero). this is the source of so many "off by one" errors, honestly it's giving chaos. π
the READ CAPACITY(16) response serves up extra info that the READ CAPACITY(10) response simply does not have. we're talking protection and logical block provisioning information, plus the number of logical blocks per physical block. so even though the media size may not exceed what READ CAPACITY(10) can show, it may still be useful to peek at the READ CAPACITY(16) response. sadly β and i cannot stress this enough β there are horrible SCSI command set implementations in the wild that straight up crash when the READ CAPACITY(16) command is sent to them. π
device capacity = number of blocks Γ block size. this utility outputs that figure in bytes, in MiB (1048576 bytes per MiB), in GB (1000000000 bytes per GB) and, if it's large enough, in TB (1000 GB). slay.
if sg_readcap is called without the --long option then the 10 byte cdb version (i.e. READ CAPACITY (10)) gets sent to the DEVICE. if the number of blocks in the response comes back as 0xffffffff (i.e. (2**32 - 1)) and the --hex option has not been given, then READ CAPACITY (16) is called and its response is what you get. β¨
this utility supports two command line syntaxes, bestie. the preferred one is shown first in the synopsis and explained in this section. a later section on the old command line syntax outlines the second group of options. iykyk. π«Ά
π₯ OPTIONS π₯
arguments to long options are mandatory for short options as well. the options are arranged in alphabetical order based on the long option name β organised queen behaviour. π
--10β use the 10 byte cdb variant of the READ CAPACITY command. this is currently the default action of this utility. heads up tho: that default may change to the 16 byte variant, especially if T10 deprecates the 10 byte variant. π--16β use the 16 byte cdb variant of the READ CAPACITY command. see the--longoption.-b,--briefβ outputs two hex numbers (prefixed with'0x'and space separated) to stdout. the first number is the maximum number of blocks on the device (which is one plus the lba of the last accessible block). the second number is the size in bytes of each block. if the operation fails then"0x0 0x0"is written to stdout. short, sweet, iconic.-h,--helpβ print out the usage message then exit. classic.-H,--hexβ output the response to the READ CAPACITY command (either the 10 or 16 byte cdb variant) in ASCII hexadecimal on stdout. each line starts with a hexadecimal address or index, starting at0. if this option is given twice, an ASCII rendering of the 16 bytes on each line is appended to the right hand side of each line. if this option is given three times then 16 bytes of ASCII hexadecimal are output in each line with no leading address nor ASCII rendering to the right. this output is suitable for importing into a later invocation of this utility with the file containing the hex given to the--inhex=FNoption. when given four (or more times) this option adds a comment line (starting with'#') describing the command that caused the output. the way it just keeps escalating?? obsessed. π-i,--inhex=FNβ where FN is a file name whose contents are assumed to be ASCII hexadecimal. if DEVICE is also given then DEVICE is ignored, a warning is issued and the utility continues, decoding the file named FN. see the "HEX, BINARY AND JSON FORMATS" section in thesg3_utilsmanpage for more information. if the--rawoption is also given then the contents of FN are treated as binary.-j[=JO],--json[=JO]β output is in JSON format instead of plain text form. note that arguments to the short and long form are themselves optional and if present start with"="and no whitespace is permitted around that"=". see thesg3_utils_jsonmanpage or use'?'for JO to get a summary.-J,--js-file=JFNβ output is in JSON format and it is sent to a file named JFN. if that file exists then it is truncated. by default, the JSON output is sent to stdout. when this option is given, the--json[=JO]option is implied and need not be given. the--json[=JO]option may still be needed to set the JO parameter to non-default values. main character file output energy. π-L,--lba=LBAβ used in conjunction with--pmioption. this variant of READ CAPACITY will yield the last block address after LBA prior to a delay. for a disk, given a LBA it yields the highest numbered block on the same cylinder (i.e. before the heads need to move). LBA is assumed to be decimal unless prefixed by"0x"or it has a trailing"h". defaults to0. this option was made obsolete in SBC-3 revision 26. β οΈ-l,--longβ use the 16 byte cdb variant of the READ CAPACITY command. the default action is to use the 10 byte cdb variant which limits the maximum block address to(2**32 - 2). when a 10 byte cdb READ CAPACITY command is used on a device whose size is too large then a last block address of0xffffffffis returned (if the device complies with SBC-2 or later).-O,--oldβ switch to older style options. please use as first option. π-p,--pmiβ partial medium indicator: for finding the next block address prior to some delay (e.g. head movement). in the absence of this option, the total number of blocks and the block size of the device are output. used in conjunction with the--lba=LBAoption. this option was made obsolete in SBC-3 revision 26. β οΈ-r,--rawβ output response in binary to stdout.-R,--readonlyβ open the DEVICE read-only (e.g. in Unix with theO_RDONLYflag). the default for READ CAPACITY(16) is to open it read-write. the default for READ CAPACITY(10) is to open it read-only so this option does not change anything for this case. nice try tho. π-v,--verboseβ increase level of verbosity. can be used multiple times. go off, stack them.-V,--versionβ outputs version string then exits.-z,--zbcβ additionally prints out the extra ZBC field (RC_BASIS) in the READ CAPACITY response. using the option implicitly sets the--16option.
π§ NOTES π§
okay this part is a little lore-heavy but stay with me. the response to READ CAPACITY(16) contains a LBPRZ bit in the SBC-3 standard (ANSI INCITS 514-2014). there was also a LBPRZ bit with the same meaning in the Logical block provisioning VPD page (0xb2). then, somewhat confusingly, T10 expanded the LBPRZ bit to a 3 bit field in SBC-4 draft revision 7 β but only in the LB provisioning VPD page. the reason for the expansion was to report a new "provisioning initialization pattern" state (when an unmapped logical block is read). the new state has been assigned LBPRZ=2 in the VPD page and it re-uses LBPRZ=0 in the READ CAPACITY(16) response. LBPRZ=1 retains the same meaning for both variants, namely that a block of zeroes will be returned when an unmapped logical block is read. literally the plot of a drama. π
β EXIT STATUS β
the exit status of sg_readcap is 0 when it is successful. otherwise see the sg3_utils(8) man page. simple as that, bestie.
π OLDER COMMAND LINE OPTIONS π
the options in this section were the only ones available prior to sg3_utils version 1.23. since then this utility defaults to the newer command line options which can be overridden by using --old (or -O) as the first option. see the ENVIRONMENT VARIABLES section for another way to force the use of these older command line options. vintage era, but make it functional. π
-16β use the 16 byte cdb variant of the READ CAPACITY command. equivalent to--longin the main description.-bβ utility outputs two hex numbers (prefixed with'0x'and space separated) to stdout. the first number is the maximum number of blocks on the device (which is one plus the lba of the last accessible block). the second number is the size of each block. if the operation fails then"0x0 0x0"is written to stdout. equivalent to--briefin the main description.-hβ output the usage message then exit. giving the-?option also outputs the usage message then exits.-Hβ output the response to the READ CAPACITY command (either the 10 or 16 byte cdb variant) in ASCII hexadecimal on stdout.-lba=LBAβ used in conjunction with-pmioption. this variant of READ CAPACITY will yield the last block address after LBA prior to a delay. equivalent to--lba=LBAin the main description.-N,--newβ switch to the newer style options.-pmiβ partial medium indicator: for finding the next block address prior to some delay (e.g. head movement). in the absence of this switch, the total number of blocks and the block size of the device are output. equivalent to--pmiin the main description.-rβ output response in binary (to stdout).-Rβ equivalent to--readonlyin the main description.-vβ verbose: print out cdb of issued commands prior to execution.'-vv'and'-vvv'are also accepted yielding greater verbosity. the way it just keeps going. π₯-Vβ outputs version string then exits.-zβ equivalent to--zbcin the main description.
π«Ά ENVIRONMENT VARIABLES π«Ά
since sg3_utils version 1.23 the environment variable SG3_UTILS_OLD_OPTS can be given. when it is present this utility will expect the older command line options. so the presence of this environment variable is equivalent to using --old (or -O) as the first command line option. it's giving time travel. π¦
π AUTHORS π
written by Douglas Gilbert. we stan. π
π COPYRIGHT π
copyright Β© 1999-2023 Douglas Gilbert
this software is distributed under the GPL version 2. there is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. (that's the serious bit, please actually read it. π)
πΈ SEE ALSO πΈ
sg_inq(sg3_utils)
okay bestie that's the whole page, every last flag and caveat intact, nothing skipped, no invented lore. this was sg3_utils-1.48, dated June 2023, page SG_READCAP(8) β periodt. π
β¨π¦
π¦ where this page comes from
- arch rolling: sg3_utils 1.49-1 Β· GPL-2.0-or-later AND BSD-2-Clause
- nixpkgs unstable: sg3_utils 1.49
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms