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  [--brief]  [--help]  [--hex]  [--lba=LBA]  [--long] [--pmi]
10       [--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       Device  capacity  is  the  product of the number of blocks by the block
25       size.  This utility outputs this figure in bytes,  MiB  (1048576  bytes
26       per MiB) and GB (1000000000 bytes per GB).
27
28       This  utility  supports two command line syntaxes, the preferred one is
29       shown first in the synopsis and explained in this section. A later sec‐
30       tion  on  the  old  command  line  syntax  outlines the second group of
31       options.
32

OPTIONS

34       Arguments to long options are mandatory for short options as well.
35
36       -b, --brief
37              outputs two hex numbers (prefixed with '0x' and space separated)
38              to  stdout.  The first number is the maximum number of blocks on
39              the device (which is one plus the lba  of  the  last  accessible
40              block).  The  second  number  is  the size of each block. If the
41              operation fails then "0x0 0x0" is written to stdout.
42
43       -h, --help
44              print out the usage message then exit.
45
46       -H, --hex
47              output the response to the READ CAPACITY command (either the  10
48              or 16 byte cdb variant) in ASCII hexadecimal on stdout.
49
50       -L, --lba=LBA
51              used  in  conjunction  with  --pmi  option. This variant of READ
52              CAPACITY will yield the last block address after LBA prior to  a
53              delay.  For  a  disk, given a LBA it yields the highest numbered
54              block on the same cylinder (i.e. before the heads need to move).
55              LBA is assumed to be decimal unless prefixed by "0x" or it has a
56              trailing "h". Defaults to 0.
57
58       -l, --long
59              Use the 16 byte cdb variant of the READ  CAPACITY  command.  The
60              default  action  is  to use the 10 byte cdb variant which limits
61              the maximum block address to (2**32 - 2). When  a  10  byte  cdb
62              READ  CAPACITY  command  is  used  on a device whose size is too
63              large then a last block address of 0xffffffff  is  returned  (if
64              the device complies with SBC-2).
65
66       -O, --old
67              switch to older style options.
68
69       -p, --pmi
70              partial  medium  indicator:  for  finding the next block address
71              prior to some delay (e.g. head movement). In the absence of this
72              option,  the  total  number  of blocks and the block size of the
73              device are output.   Used  in  conjunction  with  the  --lba=LBA
74              option.
75
76       -r, --raw
77              output response in binary to stdout.
78
79       -v, --verbose
80              increase level of verbosity. Can be used multiple times.
81
82       -V, --version
83              outputs version string then exits.
84

NOTES

86       If  sg_readcap is called without the --long option then the 10 byte cdb
87       version (i.e. READ CAPACITY (10)) is sent to the DEVICE. If the  number
88       of blocks in the response is reported as 0xffffffff (i.e. (2**32 - 1) )
89       and the --hex option has not been given, then  READ  CAPACITY  (16)  is
90       called and its response is output.
91
92       The  read  capacity(16) response shows additional information not found
93       in the read capacity(10) response. This includes protection information
94       and the number of logical blocks per physical block. So even though the
95       media size may not exceed what READ CAPACITY(10) can show, it may still
96       be useful to examine the response to READ CAPACITY(16).
97
98       In  the  2.4  series of Linux kernels the DEVICE must be a SCSI generic
99       (sg) device. In the 2.6 series block devices (e.g. SCSI disks  and  DVD
100       drives)  can  also  be specified. For example "sg_readcap /dev/sda" and
101       "sg_readcap /dev/hdd" (if /dev/hdd is a ATAPI CD/DVD device) will  work
102       in the 2.6 series kernels.
103

EXIT STATUS

105       The exit status of sg_readcap is 0 when it is successful. Otherwise see
106       the sg3_utils(8) man page.
107

OLDER COMMAND LINE OPTIONS

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

AUTHORS

150       Written by Douglas Gilbert
151
153       Copyright © 1999-2007 Douglas Gilbert
154       This  software is distributed under the GPL version 2. There is NO war‐
155       ranty; not even for MERCHANTABILITY or FITNESS FOR  A  PARTICULAR  PUR‐
156       POSE.
157

SEE ALSO

159       sg_inq(sg3_utils)
160
161
162
163sg3_utils-1.23                   January 2007                    SG_READCAP(8)
Impressum