1SG_READCAP(8)                      SG3_UTILS                     SG_READCAP(8)
2
3
4

NAME

6       sg_readcap - send SCSI READ CAPACITY command
7

SYNOPSIS

9       sg_readcap  [--16]  [--brief]  [--help]  [--hex]  [--lba=LBA]  [--long]
10       [--pmi] [--raw] [--readonly] [--verbose] [--version] [--zbc] DEVICE
11
12       sg_readcap [-16] [-b] [-h] [-H] [-lba=LBA] [-pmi] [-r] [-R]  [-v]  [-V]
13       [-z] DEVICE
14

DESCRIPTION

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

OPTIONS

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
112       -z, --zbc
113              additionally prints out the extra ZBC field  (RC_BASIS)  in  the
114              READ  CAPACITY  response.  Using  the option implicitly sets the
115              --16 option.
116

NOTES

118       The response to READ CAPACITY(16) contains a LBPRZ  bit  in  the  SBC-3
119       standard  (ANSI  INCITS  514-2014). There was also a LBPRZ bit with the
120       same meaning in the Logical block provisioning VPD  page  (0xb2).  Then
121       somewhat  confusingly  T10  expanded  the LBPRZ bit to a 3 bit field in
122       SBC-4 draft revision 7, but only in the LB provisioning VPD  page.  The
123       reason  for the expansion was to report a new "provisioning initializa‐
124       tion pattern" state (when an unmapped logical block is read).  The  new
125       state  has been assigned LBPRZ=2 in the VPD page and it re-uses LBPRZ=0
126       in the READ CAPACITY(16) response. LBPRZ=1 retains the same meaning for
127       both  variants,  namely that a block of zeroes will be returned when an
128       unmapped logical block is read.
129

EXIT STATUS

131       The exit status of sg_readcap is 0 when it is successful. Otherwise see
132       the sg3_utils(8) man page.
133

OLDER COMMAND LINE OPTIONS

135       The  options  in  this  section  were  the only ones available prior to
136       sg3_utils version 1.23 . Since then this utility defaults to the  newer
137       command  line options which can be overridden by using --old (or -O) as
138       the first option. See the ENVIRONMENT VARIABLES section for another way
139       to force the use of these older command line options.
140
141       -16    Use  the  16  byte  cdb  variant  of  the READ CAPACITY command.
142              Equivalent to --long in the main description.
143
144       -b     utility outputs two hex numbers (prefixed with  '0x'  and  space
145              separated)  to stdout. The first number is the maximum number of
146              blocks on the device (which is one plus  the  lba  of  the  last
147              accessible  block). The second number is the size of each block.
148              If the operation fails then "0x0  0x0"  is  written  to  stdout.
149              Equivalent to --brief in the main description.
150
151       -h     output  the  usage  message then exit. Giving the -? option also
152              outputs the usage message then exits.
153
154       -H     output the response to the READ CAPACITY command (either the  10
155              or 16 byte cdb variant) in ASCII hexadecimal on stdout.
156
157       -lba=LBA
158              used  in  conjunction  with  -pmi  option.  This variant of READ
159              CAPACITY will yield the last block address after LBA prior to  a
160              delay.  Equivalent to --lba=LBA in the main description.
161
162       -N, --new
163              Switch to the newer style options.
164
165       -pmi   partial  medium  indicator:  for  finding the next block address
166              prior to some delay (e.g. head movement). In the absence of this
167              switch,  the  total  number  of blocks and the block size of the
168              device are output.  Equivalent to --pmi in the main description.
169
170       -r     output response in binary (to stdout).
171
172       -R     Equivalent to --readonly in the main description.
173
174       -v     verbose: print out cdb of issued commands  prior  to  execution.
175              '-vv' and '-vvv' are also accepted yielding greater verbosity.
176
177       -V     outputs version string then exits.
178
179       -R     Equivalent to --zbc in the main description.
180

ENVIRONMENT VARIABLES

182       Since    sg3_utils    version    1.23    the    environment    variable
183       SG3_UTILS_OLD_OPTS can be given. When it is present this  utility  will
184       expect the older command line options. So the presence of this environ‐
185       ment variable is equivalent to using --old (or -O) as the first command
186       line option.
187

AUTHORS

189       Written by Douglas Gilbert
190
192       Copyright © 1999-2020 Douglas Gilbert
193       This  software is distributed under the GPL version 2. There is NO war‐
194       ranty; not even for MERCHANTABILITY or FITNESS FOR  A  PARTICULAR  PUR‐
195       POSE.
196

SEE ALSO

198       sg_inq(sg3_utils)
199
200
201
202sg3_utils-1.45                   January 2020                    SG_READCAP(8)
Impressum