SG3UTILS SGWRITELONG(1M)
NAME
sgwritelong - send the SCSI WRITE LONG command
SYNOPSIS
sgwritelong [--16] [--cordis] [--help] [--in=IF]
[--lba=LBA] [--pblock] [--verbose] [--version] [--wruncor]
[--xferlen=BTL] DEVICE
DESCRIPTION
Send the SCSI WRITE LONG (10 or 16 byte) command to DEVICE.
The buffer to be written to the DEVICE is filled with 0xff
bytes or read from the IF file. This buffer includes the
logical data (e.g. 512 bytes) and the EC bytes.
This utility can be used to generate a MEDIUM EROR at a
specific logical block address. This can be useful for test-
ing error handling. Prior to such a test, the sgdd utility
could be used to copy the original contents of the logical
block address to some safe location. After the test the
sgdd utility could be used to write back the original con-
tents of the logical block address. An alternate strategy
would be to read the "long" contents of the logical block
address with sgreadlong utility prior to testing and
restore it with this utility after testing.
Take care: If recoverable errors are being injected (e.g.
only one or a few bits changed so that the EC is able to
correct the data) then care should be taken with the set-
tings in the "read write error recovery" mode page. Specif-
ically if the ARE (for reads) and/or AWRE (for writes) are
set then recovered errors will cause the lba to be reas-
signed (and the old location to be added to the grown defect
list (PLIST)). This is not easily reversed and uses (one of
the finite number of) the spare sectors set aside for this
purpose. If in doubt it is probably safest to clear the ARE
and AWRE bits. These bits can be checked and modified with
the sdparm utility. For example: "sdparm -c AWRE,ARE
/dev/sda" will clear the bits until the disk is power
cycled.
OPTIONS
Arguments to long options are mandatory for short options as
well.
-S, --16
send a SCSI WRITE LONG (16) command to DEVICE. The
default action (in the absence of this option) is to
send a SCSI WRITE LONG (10) command.
-c, --cordis
sets the correction disabled (i.e 'CORDIS') bit. This
inhibits various other mechanisms such as automatic
sg3utils-1.26 Last change: December 2007 1
SG3UTILS SGWRITELONG(1M)
block reallocation, error recovery and various informa-
tional exception conditions being triggered. This bit
is relatively new in SBC-3 .
-h, --help
output the usage message then exit.
-i, --in=IF
read data (binary) from file named IF and use it for
the SCSI WRITE LONG command. If IF is "-" then stdin is
read. If this option is not given then 0xff bytes are
used as fill.
-l, --lba=LBA
where LBA is the logical block address of the sector to
overwrite. Defaults to lba 0 which is a dangerous
block to overwrite on a disk that is in use. Assumed to
be in decimal unless prefixed with '0x' or has a tral-
ing 'h'. If LBA is larger than can fit in 32 bits then
the --16 option should be used.
-p, --pblock
sets the physical block (i.e 'PBLOCK') bit. This
instructs DEVICE to use the given data (unless
--wruncor is also given) to write to the physical
block specified by LBA. The default action is to write
to the logical block corresponding to the given lba.
This bit is relatively new in SBC-3 .
-v, --verbose
increase the degree of verbosity (debug messages).
-V, --version
output version string then exit.
-w, --wruncor
sets the "write uncorrected" (i.e 'WRUNCOR') bit. This
instructs the DEVICE to flag the given lba (or the phy-
sical block that contains it if --pblock is also given)
as having an unrecoverable error associated with it.
Note: no data is transferred to DEVICE, other than the
command (i.e. the cdb). In the absence of this option,
the default action is to use the provided data or 0xff
bytes (--xferlen=BTL in length) and write it to DEV-
ICE. This bit is relatively new in SBC-3 .
-x, --xferlen=BTL
where BTL is the byte transfer length (default to 520).
If the given value (or the default) does not match the
"long" block size of the device, nothing is written to
DEVICE and the appropriate xferlen value may be
deduced from the error response which is printed (to
sg3utils-1.26 Last change: December 2007 2
SG3UTILS SGWRITELONG(1M)
stderr).
NOTES
The LBA and BTL (transfer length) arguments may be followed
by the following multiplicative suffixes: c C *1; w W *2; b
B *512; k K KiB *1,024; KB *1,000; m M MiB *1,048,576; MB
*1,000,000; g G GiB *1,073,741,824; and GB *1,000,000,000 .
Also a suffix of the form "x" multiplies the leading
number by .
Alternatively numerical values can be given in hexadecimal
preceded by either "0x" or "0X" (or with a trailing "h" or
"H"). When hex numbers are given, multipliers cannot be
used.
The 10 byte SCSI WRITE LONG command limits the logical block
address to a 32 bit quantity. For larger LBAs use the --16
option for the SCSI WRITE LONG (16) command.
EXAMPLES
This section outlines setting up a block with corrupted
data, checking the error condition, then restoring useful
contents to that sector.
First, if the data in a sector is important, save it with
the sgreadlong utility:
sgreadlong --lba=0x1234 --out=0x12341.img -x BTL
/dev/sda
This utility may need to be executed several time in order
to determine what the correct value for BTL is. Next use
this utility to "corrupt" that sector. That might be done
with:
sgwritelong --lba=0x1234 -x BTL /dev/sda
This will write a sector (and EC data) of 0xff bytes. Some
disks may reject this (at least one of the author's does).
Another approach is to copy the 0x12341.img file (to
0x12342.img in this example) and change some values with a
hex editor. Then write the changed image with:
sgwritelong --lba=0x1234 --in=0x12342.img -x BTL
/dev/sda
Yet another approach is to use the --wruncor option, if
supported:
sgwritelong --lba=0x1234 --wruncor /dev/sda
sg3utils-1.26 Last change: December 2007 3
SG3UTILS SGWRITELONG(1M)
Next we use the sgdd utility to check that the sector is
corrupted. Here is an example:
sgdd if=/dev/sda blksgio=1 skip=0x1234 of=. bs=512
count=1 verbose=4
Notice that the "blksgio=1" option is given. This is to
make sure that the sector is read (and no others) and the
error is fully reported. The "blksgio=1" option causes the
SGIO ioctl to be used by sgdd rather than the block sub-
system.
Finally we should restore sector 0x1234 to a non-corrupted
state. A sector full of zeroes could be written with:
sgdd if=/dev/zero of=/dev/sda blksgio=1 seek=0x1234
bs=512 count=1
This will result in a sector (block) with 512 bytes of 0x0
without a MEDIUM EROR since the EC and associated data
will be regenerated and thus well formed. The 'blksgio=1'
option is even more important in this case as it may stop
the block subsystem doing a read before write (since the
read will most likely fail). Another approach is to write
back the original contents:
sgwritelong --lba=0x1234 --in=0x12341.img -x BTL
/dev/sda
EXIT STATUS
The exit status of sgwritelong is 0 when it is successful.
Otherwise see the sg3utils(1M) man page.
AUTHORS
Written by Saeed Bishara. Further work by Douglas Gilbert.
REPORTING BUGS
Report bugs to .
COPYRIGHT
Copyright O 2004-2007 Douglas Gilbert
This software is distributed under the GPL version 2. There
is NO warranty; not even for MERCHANTABILITY or FITNES FOR
A PARTICULAR PURPOSE.
SEE ALSO
sgreadlong, sgdd (both in sg3utils), sdparm(sdparm)
ATRIBUTES
See attributes(5) for descriptions of the following attri-
butes:
sg3utils-1.26 Last change: December 2007 4
SG3UTILS SGWRITELONG(1M)
ATRIBUTE TYPE ATRIBUTE VALUE
Availability SUNWsg3utilsu
Interface Stability Committed
NOTES
Source for sg3utils is available on http:/opensolaris.org.
sg3utils-1.26 Last change: December 2007 5
|