1SG_READCAP(8) SG3_UTILS SG_READCAP(8)
2
3
4
6 sg_readcap - send SCSI READ CAPACITY command
7
9 sg_readcap [--16] [--brief] [--help] [--hex] [--lba=LBA] [--long]
10 [--pmi] [--raw] [--readonly] [--verbose] [--version] DEVICE
11
12 sg_readcap [-16] [-b] [-h] [-H] [-lba=LBA] [-pmi] [-r] [-R] [-v] [-V]
13 DEVICE
14
16 The normal action of the SCSI READ CAPACITY command is to fetch the
17 number of blocks (and block size) from the DEVICE.
18
19 The SCSI READ CAPACITY command (both 10 and 16 byte cdbs) actually
20 yield the block address of the last block and the block size. The num‐
21 ber of blocks is thus one plus the block address of the last block (as
22 blocks are counted origin zero (i.e. starting at block zero)). This is
23 the source of many "off by one" errors.
24
25 The READ CAPACITY(16) response provides additional information not
26 found in the READ CAPACITY(10) response. This includes protection and
27 logical block provisioning information, plus the number of logical
28 blocks per physical block. So even though the media size may not exceed
29 what READ CAPACITY(10) can show, it may still be useful to examine the
30 response to READ CAPACITY(16). Sadly there are horrible SCSI command
31 set implementations in the wild that crash when the READ CAPACITY(16)
32 command is sent to them.
33
34 Device capacity is the product of the number of blocks by the block
35 size. This utility outputs this figure in bytes, MiB (1048576 bytes
36 per MiB), GB (1000000000 bytes per GB) and, if large enough, TB (1000
37 GB).
38
39 If sg_readcap is called without the --long option then the 10 byte cdb
40 version (i.e. READ CAPACITY (10)) is sent to the DEVICE. If the number
41 of blocks in the response is reported as 0xffffffff (i.e. (2**32 - 1) )
42 and the --hex option has not been given, then READ CAPACITY (16) is
43 called and its response is output.
44
45 This utility supports two command line syntaxes, the preferred one is
46 shown first in the synopsis and explained in this section. A later sec‐
47 tion on the old command line syntax outlines the second group of
48 options.
49
51 Arguments to long options are mandatory for short options as well. The
52 options are arranged in alphabetical order based on the long option
53 name.
54
55 --16 Use the 16 byte cdb variant of the READ CAPACITY command. See
56 the '--long' option. -b, --brief outputs two hex numbers (pre‐
57 fixed with '0x' and space separated) to stdout. The first number
58 is the maximum number of blocks on the device (which is one plus
59 the lba of the last accessible block). The second number is the
60 size in bytes of each block. If the operation fails then "0x0
61 0x0" is written to stdout.
62
63 -h, --help
64 print out the usage message then exit.
65
66 -H, --hex
67 output the response to the READ CAPACITY command (either the 10
68 or 16 byte cdb variant) in ASCII hexadecimal on stdout.
69
70 -L, --lba=LBA
71 used in conjunction with --pmi option. This variant of READ
72 CAPACITY will yield the last block address after LBA prior to a
73 delay. For a disk, given a LBA it yields the highest numbered
74 block on the same cylinder (i.e. before the heads need to move).
75 LBA is assumed to be decimal unless prefixed by "0x" or it has a
76 trailing "h". Defaults to 0. This option was made obsolete in
77 SBC-3 revision 26.
78
79 -l, --long
80 Use the 16 byte cdb variant of the READ CAPACITY command. The
81 default action is to use the 10 byte cdb variant which limits
82 the maximum block address to (2**32 - 2). When a 10 byte cdb
83 READ CAPACITY command is used on a device whose size is too
84 large then a last block address of 0xffffffff is returned (if
85 the device complies with SBC-2 or later).
86
87 -O, --old
88 Switch to older style options. Please use as first option.
89
90 -p, --pmi
91 partial medium indicator: for finding the next block address
92 prior to some delay (e.g. head movement). In the absence of this
93 option, the total number of blocks and the block size of the
94 device are output. Used in conjunction with the --lba=LBA
95 option. This option was made obsolete in SBC-3 revision 26.
96
97 -r, --raw
98 output response in binary to stdout.
99
100 -R, --readonly
101 open the DEVICE read-only (e.g. in Unix with the O_RDONLY flag).
102 The default for READ CAPACITY(16) is to open it read-write. The
103 default for READ CAPACITY(10) is to open it read-only so this
104 option does not change anything for this case.
105
106 -v, --verbose
107 increase level of verbosity. Can be used multiple times.
108
109 -V, --version
110 outputs version string then exits.
111
113 The response to READ CAPACITY(16) contains a LBPRZ bit in the SBC-3
114 standard (ANSI INCITS 514-2014). There was also a LBPRZ bit with the
115 same meaning in the Logical block provisioning VPD page (0xb2). Then
116 somewhat confusingly T10 expanded the LBPRZ bit to a 3 bit field in
117 SBC-4 draft revision 7, but only in the LB provisioning VPD page. The
118 reason for the expansion was to report a new "provisioning initializa‐
119 tion pattern" state (when an unmapped logical block is read). The new
120 state has been assigned LBPRZ=2 in the VPD page and it re-uses LBPRZ=0
121 in the READ CAPACITY(16) response. LBPRZ=1 retains the same meaning for
122 both variants, namely that a block of zeroes will be returned when an
123 unmapped logical block is read.
124
126 The exit status of sg_readcap is 0 when it is successful. Otherwise see
127 the sg3_utils(8) man page.
128
130 The options in this section were the only ones available prior to
131 sg3_utils version 1.23 . Since then this utility defaults to the newer
132 command line options which can be overridden by using --old (or -O) as
133 the first option. See the ENVIRONMENT VARIABLES section for another way
134 to force the use of these older command line options.
135
136 -16 Use the 16 byte cdb variant of the READ CAPACITY command.
137 Equivalent to --long in the main description.
138
139 -b utility outputs two hex numbers (prefixed with '0x' and space
140 separated) to stdout. The first number is the maximum number of
141 blocks on the device (which is one plus the lba of the last
142 accessible block). The second number is the size of each block.
143 If the operation fails then "0x0 0x0" is written to stdout.
144 Equivalent to --brief in the main description.
145
146 -h output the usage message then exit. Giving the -? option also
147 outputs the usage message then exits.
148
149 -H output the response to the READ CAPACITY command (either the 10
150 or 16 byte cdb variant) in ASCII hexadecimal on stdout.
151
152 -lba=LBA
153 used in conjunction with -pmi option. This variant of READ
154 CAPACITY will yield the last block address after LBA prior to a
155 delay. Equivalent to --lba=LBA in the main description.
156
157 -N, --new
158 Switch to the newer style options.
159
160 -pmi partial medium indicator: for finding the next block address
161 prior to some delay (e.g. head movement). In the absence of this
162 switch, the total number of blocks and the block size of the
163 device are output. Equivalent to --pmi in the main description.
164
165 -r output response in binary (to stdout).
166
167 -R Equivalent to --readonly in the main description.
168
169 -v verbose: print out cdb of issued commands prior to execution.
170 '-vv' and '-vvv' are also accepted yielding greater verbosity.
171
172 -V outputs version string then exits.
173
175 Since sg3_utils version 1.23 the environment variable
176 SG3_UTILS_OLD_OPTS can be given. When it is present this utility will
177 expect the older command line options. So the presence of this environ‐
178 ment variable is equivalent to using --old (or -O) as the first command
179 line option.
180
182 Written by Douglas Gilbert
183
185 Copyright © 1999-2018 Douglas Gilbert
186 This software is distributed under the GPL version 2. There is NO war‐
187 ranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR‐
188 POSE.
189
191 sg_inq(sg3_utils)
192
193
194
195sg3_utils-1.43 May 2018 SG_READCAP(8)