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] [--verbose] [--version] DEVICE
11
12       sg_readcap [-16] [-b] [-h] [-H] [-lba=LBA] [-pmi] [-r] [-v] [-V] DEVICE
13

DESCRIPTION

15       The normal action of the SCSI READ CAPACITY command  is  to  fetch  the
16       number of blocks (and block size) from the DEVICE.
17
18       The  SCSI  READ  CAPACITY  command  (both 10 and 16 byte cdbs) actually
19       yield the block address of the last block and the block size. The  num‐
20       ber  of blocks is thus one plus the block address of the last block (as
21       blocks are counted origin zero (i.e. starting at block zero)). This  is
22       the source of many "off by one" errors.
23
24       The  READ  CAPACITY(16)  response  provides  additional information not
25       found in the READ CAPACITY(10) response. This includes  protection  and
26       logical  block  provisioning  information,  plus  the number of logical
27       blocks per physical block. So even though the media size may not exceed
28       what  READ CAPACITY(10) can show, it may still be useful to examine the
29       response to READ CAPACITY(16). Sadly there are  horrible  SCSI  command
30       set  implementations  in the wild that crash when the READ CAPACITY(16)
31       command is sent to them.
32
33       Device capacity is the product of the number of  blocks  by  the  block
34       size.   This  utility  outputs this figure in bytes, MiB (1048576 bytes
35       per MiB) and GB (1000000000 bytes per GB).
36
37       If sg_readcap is called without the --long option then the 10 byte  cdb
38       version  (i.e. READ CAPACITY (10)) is sent to the DEVICE. If the number
39       of blocks in the response is reported as 0xffffffff (i.e. (2**32 - 1) )
40       and  the  --hex  option  has not been given, then READ CAPACITY (16) is
41       called and its response is output.
42
43       This utility supports two command line syntaxes, the preferred  one  is
44       shown first in the synopsis and explained in this section. A later sec‐
45       tion on the old command  line  syntax  outlines  the  second  group  of
46       options.
47

OPTIONS

49       Arguments to long options are mandatory for short options as well.
50
51
52       --16   Use the 16 byte cdb variant of the READ CAPACITY command.
53              See the '--long' option.  -b,  --brief  outputs  two  hex
54              numbers  (prefixed with '0x' and space separated) to std‐
55              out. The first number is the maximum number of blocks  on
56              the  device (which is one plus the lba of the last acces‐
57              sible block). The second number is the size in  bytes  of
58              each  block.  If  the  operation  fails then "0x0 0x0" is
59              written to stdout.
60
61       -h, --help
62              print out the usage message then exit.
63
64       -H, --hex
65              output the response to the READ CAPACITY command  (either
66              the  10  or  16 byte cdb variant) in ASCII hexadecimal on
67              stdout.
68
69       -L, --lba=LBA
70              used in conjunction with --pmi option.  This  variant  of
71              READ CAPACITY will yield the last block address after LBA
72              prior to a delay. For a disk, given a LBA it  yields  the
73              highest  numbered block on the same cylinder (i.e. before
74              the heads need to move). LBA is  assumed  to  be  decimal
75              unless  prefixed  by  "0x"  or  it  has  a  trailing "h".
76              Defaults to 0.  This option was made  obsolete  in  SBC-3
77              revision 26.
78
79       -l, --long
80              Use the 16 byte cdb variant of the READ CAPACITY command.
81              The default action is to use  the  10  byte  cdb  variant
82              which  limits  the  maximum block address to (2**32 - 2).
83              When a 10 byte cdb READ CAPACITY command  is  used  on  a
84              device  whose size is too large then a last block address
85              of 0xffffffff is returned (if the  device  complies  with
86              SBC-2 or later).
87
88       -O, --old
89              Switch  to  older  style  options.  Please  use  as first
90              option.
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       -v, --verbose
104              increase level of verbosity. Can be used multiple times.
105
106       -V, --version
107              outputs version string then exits.
108

NOTES

110       In  the  2.4  series  of Linux kernels the DEVICE must be a SCSI
111       generic (sg) device. In the 2.6 series block devices (e.g.  SCSI
112       disks  and  DVD  drives)  can  also  be  specified.  For example
113       "sg_readcap /dev/sda" and "sg_readcap /dev/hdd" (if /dev/hdd  is
114       a ATAPI CD/DVD device) will work in the 2.6 series kernels.
115

EXIT STATUS

117       The exit status of sg_readcap is 0 when it is successful. Other‐
118       wise see the sg3_utils(8) man page.
119

OLDER COMMAND LINE OPTIONS

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

AUTHORS

169       Written by Douglas Gilbert
170
172       Copyright © 1999-2013 Douglas Gilbert
173       This  software  is distributed under the GPL version 2. There is
174       NO warranty; not even for MERCHANTABILITY or FITNESS FOR A  PAR‐
175       TICULAR PURPOSE.
176

SEE ALSO

178       sg_inq(sg3_utils)
179
180
181
182sg3_utils-1.36                     May 2012                      SG_READCAP(8)
Impressum