1SG_WRITE_LONG(8) SG3_UTILS SG_WRITE_LONG(8)
2
3
4
6 sg_write_long - send SCSI WRITE LONG command
7
9 sg_write_long [--16] [--cor_dis] [--help] [--in=IF] [--lba=LBA]
10 [--pblock] [--verbose] [--version] [--wr_uncor] [--xfer_len=BTL] DEVICE
11
13 Send the SCSI WRITE LONG (10 or 16 byte) command to DEVICE. The buffer
14 to be written to the DEVICE is filled with 0xff bytes or read from the
15 IF file. This buffer includes the logical data (e.g. 512 bytes) and the
16 ECC bytes.
17
18 This utility can be used to generate a MEDIUM ERROR at a specific logi‐
19 cal block address. This can be useful for testing error handling. Prior
20 to such a test, the sg_dd utility could be used to copy the original
21 contents of the logical block address to some safe location. After the
22 test the sg_dd utility could be used to write back the original con‐
23 tents of the logical block address. An alternate strategy would be to
24 read the "long" contents of the logical block address with sg_read_long
25 utility prior to testing and restore it with this utility after test‐
26 ing.
27
28 Take care: If recoverable errors are being injected (e.g. only one or a
29 few bits changed so that the ECC is able to correct the data) then care
30 should be taken with the settings in the "read write error recovery"
31 mode page. Specifically if the ARRE (for reads) and/or AWRE (for
32 writes) are set then recovered errors will cause the lba to be reas‐
33 signed (and the old location to be added to the grown defect list
34 (PLIST)). This is not easily reversed and uses (one of the finite num‐
35 ber of) the spare sectors set aside for this purpose. If in doubt it is
36 probably safest to clear the ARRE and AWRE bits. These bits can be
37 checked and modified with the sdparm utility. For example: "sdparm -c
38 AWRE,ARRE /dev/sda" will clear the bits until the disk is power cycled.
39
40 In SBC-4 revision 7 all uses of SCSI WRITE LONG (10 and 16 byte) com‐
41 mands were made obsolete apart from the case in which the WR_UNCOR bit
42 is set. The SCSI READ LONG (10 and 16 byte) commands were made obso‐
43 lete in the same revision.
44
46 Arguments to long options are mandatory for short options as well.
47
48 -S, --16
49 send a SCSI WRITE LONG (16) command to DEVICE. The default
50 action (in the absence of this option) is to send a SCSI WRITE
51 LONG (10) command.
52
53 -c, --cor_dis
54 sets the correction disabled (i.e 'COR_DIS') bit. This inhibits
55 various other mechanisms such as automatic block reallocation,
56 error recovery and various informational exception conditions
57 being triggered. This bit is relatively new in SBC-3 .
58
59 -h, --help
60 output the usage message then exit.
61
62 -i, --in=IF
63 read data (binary) from file named IF and use it for the SCSI
64 WRITE LONG command. If IF is "-" then stdin is read. If this
65 option is not given then 0xff bytes are used as fill.
66
67 -l, --lba=LBA
68 where LBA is the logical block address of the sector to over‐
69 write. Defaults to lba 0 which is a dangerous block to over‐
70 write on a disk that is in use. Assumed to be in decimal unless
71 prefixed with '0x' or has a trailing 'h'. If LBA is larger than
72 can fit in 32 bits then the --16 option should be used.
73
74 -p, --pblock
75 sets the physical block (i.e 'PBLOCK') bit. This instructs
76 DEVICE to use the given data (unless --wr_uncor is also given)
77 to write to the physical block specified by LBA. The default
78 action is to write to the logical block corresponding to the
79 given lba. This bit is relatively new in SBC-3 .
80
81 -v, --verbose
82 increase the degree of verbosity (debug messages).
83
84 -V, --version
85 output version string then exit.
86
87 -w, --wr_uncor
88 sets the "write uncorrected" (i.e 'WR_UNCOR') bit. This
89 instructs the DEVICE to flag the given lba (or the physical
90 block that contains it if --pblock is also given) as having an
91 unrecoverable error associated with it. Note: no data is trans‐
92 ferred to DEVICE, other than the command (i.e. the cdb). In the
93 absence of this option, the default action is to use the pro‐
94 vided data or 0xff bytes (--xfer_len=BTL in length) and write it
95 to DEVICE. This bit is relatively new in SBC-3 .
96
97 -x, --xfer_len=BTL
98 where BTL is the byte transfer length (default to 520). If the
99 given value (or the default) does not match the "long" block
100 size of the device, nothing is written to DEVICE and the appro‐
101 priate xfer_len value may be deduced from the error response
102 which is printed (to stderr).
103
105 Various numeric arguments (e.g. LBA) may include multiplicative suf‐
106 fixes or be given in hexadecimal. See the "NUMERIC ARGUMENTS" section
107 in the sg3_utils(8) man page.
108
109 The 10 byte SCSI WRITE LONG command limits the logical block address to
110 a 32 bit quantity. For larger LBAs use the --16 option for the SCSI
111 WRITE LONG (16) command.
112
114 This section outlines setting up a block with corrupted data, checking
115 the error condition, then restoring useful contents to that sector.
116
117 First, if the data in a sector is important, save it with the
118 sg_read_long utility:
119
120 sg_read_long --lba=0x1234 --out=0x1234_1.img -x BTL /dev/sda
121
122 This utility may need to be executed several time in order to determine
123 what the correct value for BTL is. Next use this utility to "corrupt"
124 that sector. That might be done with:
125
126 sg_write_long --lba=0x1234 -x BTL /dev/sda
127
128 This will write a sector (and ECC data) of 0xff bytes. Some disks may
129 reject this (at least one of the author's does). Another approach is to
130 copy the 0x1234_1.img file (to 0x1234_2.img in this example) and change
131 some values with a hex editor. Then write the changed image with:
132
133 sg_write_long --lba=0x1234 --in=0x1234_2.img -x BTL /dev/sda
134
135 Yet another approach is to use the --wr_uncor option, if supported:
136
137 sg_write_long --lba=0x1234 --wr_uncor /dev/sda
138
139 Next we use the sg_dd utility to check that the sector is corrupted.
140 Here is an example:
141
142 sg_dd if=/dev/sda blk_sgio=1 skip=0x1234 of=. bs=512 count=1 ver‐
143 bose=4
144
145 Notice that the "blk_sgio=1" option is given. This is to make sure that
146 the sector is read (and no others) and the error is fully reported.
147 The "blk_sgio=1" option causes the SG_IO ioctl to be used by sg_dd
148 rather than the block subsystem.
149
150 Finally we should restore sector 0x1234 to a non-corrupted state. A
151 sector full of zeros could be written with:
152
153 sg_dd if=/dev/zero of=/dev/sda blk_sgio=1 seek=0x1234 bs=512 count=1
154
155 This will result in a sector (block) with 512 bytes of 0x0 without a
156 MEDIUM ERROR since the ECC and associated data will be regenerated and
157 thus well formed. The 'blk_sgio=1' option is even more important in
158 this case as it may stop the block subsystem doing a read before write
159 (since the read will most likely fail). Another approach is to write
160 back the original contents:
161
162 sg_write_long --lba=0x1234 --in=0x1234_1.img -x BTL /dev/sda
163
165 The exit status of sg_write_long is 0 when it is successful. Otherwise
166 see the sg3_utils(8) man page.
167
169 Written by Saeed Bishara. Further work by Douglas Gilbert.
170
172 Report bugs to <dgilbert at interlog dot com>.
173
175 Copyright © 2004-2016 Douglas Gilbert
176 This software is distributed under the GPL version 2. There is NO war‐
177 ranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR‐
178 POSE.
179
181 sg_read_long, sg_dd (both in sg3_utils), sdparm(sdparm)
182
183
184
185sg3_utils-1.42 January 2016 SG_WRITE_LONG(8)