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] DEVICE
11
12       sg_readcap [-16] [-b] [-h] [-H] [-lba=LBA] [-pmi] [-r] [-R]  [-v]  [-V]
13       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) and GB (1000000000 bytes per GB).
37
38       If  sg_readcap is called without the --long option then the 10 byte cdb
39       version (i.e. READ CAPACITY (10)) is sent to the DEVICE. If the  number
40       of blocks in the response is reported as 0xffffffff (i.e. (2**32 - 1) )
41       and the --hex option has not been given, then  READ  CAPACITY  (16)  is
42       called and its response is output.
43
44       This  utility  supports two command line syntaxes, the preferred one is
45       shown first in the synopsis and explained in this section. A later sec‐
46       tion  on  the  old  command  line  syntax  outlines the second group of
47       options.
48

OPTIONS

50       Arguments to long options are mandatory for short options as well.
51
52
53       --16   Use the 16 byte cdb variant of the READ CAPACITY command.
54              See  the  '--long'  option.   -b, --brief outputs two hex
55              numbers (prefixed with '0x' and space separated) to  std‐
56              out.  The first number is the maximum number of blocks on
57              the device (which is one plus the lba of the last  acces‐
58              sible  block).  The second number is the size in bytes of
59              each block. If the operation  fails  then  "0x0  0x0"  is
60              written to stdout.
61
62       -h, --help
63              print out the usage message then exit.
64
65       -H, --hex
66              output  the response to the READ CAPACITY command (either
67              the 10 or 16 byte cdb variant) in  ASCII  hexadecimal  on
68              stdout.
69
70       -L, --lba=LBA
71              used  in  conjunction  with --pmi option. This variant of
72              READ CAPACITY will yield the last block address after LBA
73              prior  to  a delay. For a disk, given a LBA it yields the
74              highest numbered block on the same cylinder (i.e.  before
75              the  heads  need  to  move). LBA is assumed to be decimal
76              unless prefixed  by  "0x"  or  it  has  a  trailing  "h".
77              Defaults  to  0.   This option was made obsolete in SBC-3
78              revision 26.
79
80       -l, --long
81              Use the 16 byte cdb variant of the READ CAPACITY command.
82              The  default  action  is  to  use the 10 byte cdb variant
83              which limits the maximum block address to  (2**32  -  2).
84              When  a  10  byte  cdb READ CAPACITY command is used on a
85              device whose size is too large then a last block  address
86              of  0xffffffff  is  returned (if the device complies with
87              SBC-2 or later).
88
89       -O, --old
90              switch to older style options.
91
92       -p, --pmi
93              partial medium indicator:  for  finding  the  next  block
94              address  prior to some delay (e.g. head movement). In the
95              absence of this option, the total number  of  blocks  and
96              the  block  size  of the device are output.  Used in con‐
97              junction with the --lba=LBA option. This option was  made
98              obsolete in SBC-3 revision 26.
99
100       -r, --raw
101              output response in binary to stdout.
102
103       -R, --readonly
104              open the DEVICE read-only (e.g. in Unix with the O_RDONLY
105              flag).  The default for READ CAPACITY(16) is to  open  it
106              read-write.  The default for READ CAPACITY(10) is to open
107              it read-only so this option does not change anything  for
108              this case.
109
110       -v, --verbose
111              increase level of verbosity. Can be used multiple times.
112
113       -V, --version
114              outputs version string then exits.
115

NOTES

117       In  the  2.4  series  of Linux kernels the DEVICE must be a SCSI
118       generic (sg) device. In the 2.6 series block devices (e.g.  SCSI
119       disks  and  DVD  drives)  can  also  be  specified.  For example
120       "sg_readcap /dev/sda" and "sg_readcap /dev/hdd" (if /dev/hdd  is
121       a ATAPI CD/DVD device) will work in the 2.6 series kernels.
122

EXIT STATUS

124       The exit status of sg_readcap is 0 when it is successful. Other‐
125       wise see the sg3_utils(8) man page.
126

OLDER COMMAND LINE OPTIONS

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

AUTHORS

177       Written by Douglas Gilbert
178
180       Copyright © 1999-2014 Douglas Gilbert
181       This  software  is distributed under the GPL version 2. There is
182       NO warranty; not even for MERCHANTABILITY or FITNESS FOR A  PAR‐
183       TICULAR PURPOSE.
184

SEE ALSO

186       sg_inq(sg3_utils)
187
188
189
190sg3_utils-1.39                     May 2014                      SG_READCAP(8)
Impressum