man sg_readcap (Administration système) - calls a READ CAPACITY command on a SCSI device

NAME

sg_readcap - calls a READ CAPACITY command on a SCSI device

SYNOPSIS

sg_readcap [-16] [-h] [-lba=<block>] [-pmi] [-v] [-V] <device>

DESCRIPTION

The normal usage is to find the number of blocks (and block size) of the given device and output them.

The SCSI READ CAPACITY command (both 10 and 16 byte cdbs) actually yield the block address of the last block and the block size. The number of blocks is thus one plus the block address of the last block (as blocks are counted origin zero (i.e. starting at block zero)). This is the source of many "off by one" errors which are often seen as medium or out of range errors when the reported last block is read.

Device capacity is the product of the number of blocks and block size. This utility outputs this figure in bytes, MiB (1048576 bytes per MiB) and GB (1000000000 bytes per GB).

-16
Use the 16 byte cdb variant of the READ CAPACITY command. The default action is to use the 10 byte cdb variant which limits the maximum block address to (2**32 - 2). When a 10 byte cdb READ CAPACITY command is used on a device whose size is too large then a last block address of 0xffffffff is returned (if the device complies with SBC-2).
-b
utility outputs two hex numbers (prefixed with '0x' and space separated) to stdout. The first number is the maximum number of blocks on the device (which is one plus the lba of the last accessible block). The second number is the size of each block. If the operation fails then "0x0 0x0" is writtent to stdout.
-h
output the usage message then exit.
-lba=<block>
used in conjunction with "-pmi" option. This variant of READ CAPACITY will yield the last block address after "<block>" prior to a delay. For a disk, given a "<block>" address it yields the highest numbered block on the same cylinder (i.e. before the heads need to move). "<block>" is in hex (from 0 to ffffffff) and defaults to zero.
-pmi
partial medium indicator: for finding the next block address prior to some delay (e.g. head movement). In the absence of this switch, the total number of blocks and the block size of the device are output.
-v
verbose: print out cdb of issued commands prior to execution. '-vv' and '-vvv' are also accepted yielding greater verbosity.
-V
outputs version string then exits.

On exit this utility returns 0 if it succeeded otherwise a process status value of 1 is returned.

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

AUTHORS

Written by Douglas Gilbert

COPYRIGHT

Copyright © 1999-2005 Douglas Gilbert

This software is distributed under the GPL version 2. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.