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

NAME

6       sg_readcap - sends a 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       thin  provisioning  information,  plus the number of logical blocks per
27       physical block. So even though the media size may not exceed what  READ
28       CAPACITY(10)  can  show, it may still be useful to examine the response
29       to READ CAPACITY(16). Sadly there are horrible SCSI command set  imple‐
30       mentations in the wild that crash when the READ CAPACITY(16) command is
31       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       -b, --brief
52              outputs two hex numbers (prefixed with '0x' and space separated)
53              to stdout. The first number is the maximum number of  blocks  on
54              the  device  (which  is  one plus the lba of the last accessible
55              block). The second number is the size in bytes of each block. If
56              the operation fails then "0x0 0x0" is written to stdout.
57
58       -h, --help
59              print out the usage message then exit.
60
61       -H, --hex
62              output  the response to the READ CAPACITY command (either the 10
63              or 16 byte cdb variant) in ASCII hexadecimal on stdout.
64
65       -L, --lba=LBA
66              used in conjunction with --pmi  option.  This  variant  of  READ
67              CAPACITY  will yield the last block address after LBA prior to a
68              delay. For a disk, given a LBA it yields  the  highest  numbered
69              block on the same cylinder (i.e. before the heads need to move).
70              LBA is assumed to be decimal unless prefixed by "0x" or it has a
71              trailing "h". Defaults to 0.
72
73       -l, --long
74              Use  the  16  byte cdb variant of the READ CAPACITY command. The
75              default action is to use the 10 byte cdb  variant  which  limits
76              the  maximum  block  address  to (2**32 - 2). When a 10 byte cdb
77              READ CAPACITY command is used on a  device  whose  size  is  too
78              large  then  a  last block address of 0xffffffff is returned (if
79              the device complies with SBC-2).
80
81       --16   Use the 16 byte cdb variant of the READ  CAPACITY  command.  See
82              the '--long' option.
83
84       -O, --old
85              switch to older style options.
86
87       -p, --pmi
88              partial  medium  indicator:  for  finding the next block address
89              prior to some delay (e.g. head movement). In the absence of this
90              option,  the  total  number  of blocks and the block size of the
91              device are output.   Used  in  conjunction  with  the  --lba=LBA
92              option.
93
94       -r, --raw
95              output response in binary to stdout.
96
97       -v, --verbose
98              increase level of verbosity. Can be used multiple times.
99
100       -V, --version
101              outputs version string then exits.
102

NOTES

104       In  the  2.4  series of Linux kernels the DEVICE must be a SCSI generic
105       (sg) device. In the 2.6 series block devices (e.g. SCSI disks  and  DVD
106       drives)  can  also  be specified. For example "sg_readcap /dev/sda" and
107       "sg_readcap /dev/hdd" (if /dev/hdd is a ATAPI CD/DVD device) will  work
108       in the 2.6 series kernels.
109

EXIT STATUS

111       The exit status of sg_readcap is 0 when it is successful. Otherwise see
112       the sg3_utils(8) man page.
113

OLDER COMMAND LINE OPTIONS

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

AUTHORS

156       Written by Douglas Gilbert
157
159       Copyright © 1999-2009 Douglas Gilbert
160       This  software is distributed under the GPL version 2. There is NO war‐
161       ranty; not even for MERCHANTABILITY or FITNESS FOR  A  PARTICULAR  PUR‐
162       POSE.
163

SEE ALSO

165       sg_inq(sg3_utils)
166
167
168
169sg3_utils-1.28                  September 2009                   SG_READCAP(8)
Impressum