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

NAME

6       sg_write_long - send SCSI WRITE LONG command
7

SYNOPSIS

9       sg_write_long   [--16]   [--cor_dis]   [--help]  [--in=IF]  [--lba=LBA]
10       [--pblock] [--verbose] [--version] [--wr_uncor] [--xfer_len=BTL] DEVICE
11

DESCRIPTION

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

OPTIONS

41       Arguments to long options are mandatory for short options as well.
42
43       -S, --16
44              send  a  SCSI  WRITE  LONG  (16)  command to DEVICE. The default
45              action (in the absence of this option) is to send a  SCSI  WRITE
46              LONG (10) command.
47
48       -c, --cor_dis
49              sets  the correction disabled (i.e 'COR_DIS') bit. This inhibits
50              various other mechanisms such as automatic  block  reallocation,
51              error  recovery  and  various informational exception conditions
52              being triggered.  This bit is relatively new in SBC-3 .
53
54       -h, --help
55              output the usage message then exit.
56
57       -i, --in=IF
58              read data (binary) from file named IF and use it  for  the  SCSI
59              WRITE  LONG  command.  If  IF is "-" then stdin is read. If this
60              option is not given then 0xff bytes are used as fill.
61
62       -l, --lba=LBA
63              where LBA is the logical block address of the  sector  to  over‐
64              write.   Defaults  to  lba 0 which is a dangerous block to over‐
65              write on a disk that is in use. Assumed to be in decimal  unless
66              prefixed  with '0x' or has a trailing 'h'. If LBA is larger than
67              can fit in 32 bits then the --16 option should be used.
68
69       -p, --pblock
70              sets the physical  block  (i.e  'PBLOCK')  bit.  This  instructs
71              DEVICE  to  use the given data (unless --wr_uncor is also given)
72              to write to the physical block specified  by  LBA.  The  default
73              action  is  to  write  to the logical block corresponding to the
74              given lba.  This bit is relatively new in SBC-3 .
75
76       -v, --verbose
77              increase the degree of verbosity (debug messages).
78
79       -V, --version
80              output version string then exit.
81
82       -w, --wr_uncor
83              sets  the  "write  uncorrected"  (i.e  'WR_UNCOR')   bit.   This
84              instructs  the  DEVICE  to  flag  the given lba (or the physical
85              block that contains it if --pblock is also given) as  having  an
86              unrecoverable  error associated with it. Note: no data is trans‐
87              ferred to DEVICE, other than the command (i.e. the cdb). In  the
88              absence  of  this  option, the default action is to use the pro‐
89              vided data or 0xff bytes (--xfer_len=BTL in length) and write it
90              to DEVICE.  This bit is relatively new in SBC-3 .
91
92       -x, --xfer_len=BTL
93              where  BTL  is the byte transfer length (default to 520). If the
94              given value (or the default) does not  match  the  "long"  block
95              size  of the device, nothing is written to DEVICE and the appro‐
96              priate xfer_len value may be deduced  from  the  error  response
97              which is printed (to stderr).
98

NOTES

100       Various  numeric  arguments  (e.g. LBA) may include multiplicative suf‐
101       fixes or be given in hexadecimal. See the "NUMERIC  ARGUMENTS"  section
102       in the sg3_utils(8) man page.
103
104       The 10 byte SCSI WRITE LONG command limits the logical block address to
105       a 32 bit quantity. For larger LBAs use the --16  option  for  the  SCSI
106       WRITE LONG (16) command.
107

EXAMPLES

109       This  section outlines setting up a block with corrupted data, checking
110       the error condition, then restoring useful contents to that sector.
111
112       First, if the  data  in  a  sector  is  important,  save  it  with  the
113       sg_read_long utility:
114
115         sg_read_long --lba=0x1234 --out=0x1234_1.img -x BTL /dev/sda
116
117       This utility may need to be executed several time in order to determine
118       what the correct value for BTL is.  Next use this utility to  "corrupt"
119       that sector. That might be done with:
120
121         sg_write_long --lba=0x1234 -x BTL /dev/sda
122
123       This  will  write a sector (and ECC data) of 0xff bytes. Some disks may
124       reject this (at least one of the author's does). Another approach is to
125       copy the 0x1234_1.img file (to 0x1234_2.img in this example) and change
126       some values with a hex editor. Then write the changed image with:
127
128         sg_write_long --lba=0x1234 --in=0x1234_2.img -x BTL /dev/sda
129
130       Yet another approach is to use the --wr_uncor option, if supported:
131
132         sg_write_long --lba=0x1234 --wr_uncor /dev/sda
133
134       Next we use the sg_dd utility to check that the  sector  is  corrupted.
135       Here is an example:
136
137         sg_dd  if=/dev/sda  blk_sgio=1  skip=0x1234  of=. bs=512 count=1 ver‐
138       bose=4
139
140       Notice that the "blk_sgio=1" option is given. This is to make sure that
141       the  sector  is  read  (and no others) and the error is fully reported.
142       The "blk_sgio=1" option causes the SG_IO ioctl  to  be  used  by  sg_dd
143       rather than the block subsystem.
144
145       Finally  we  should  restore  sector 0x1234 to a non-corrupted state. A
146       sector full of zeros could be written with:
147
148         sg_dd if=/dev/zero of=/dev/sda blk_sgio=1 seek=0x1234 bs=512 count=1
149
150       This will result in a sector (block) with 512 bytes of  0x0  without  a
151       MEDIUM  ERROR since the ECC and associated data will be regenerated and
152       thus well formed. The 'blk_sgio=1' option is  even  more  important  in
153       this  case as it may stop the block subsystem doing a read before write
154       (since the read will most likely fail).  Another approach is  to  write
155       back the original contents:
156
157         sg_write_long --lba=0x1234 --in=0x1234_1.img -x BTL /dev/sda
158

EXIT STATUS

160       The  exit status of sg_write_long is 0 when it is successful. Otherwise
161       see the sg3_utils(8) man page.
162

AUTHORS

164       Written by Saeed Bishara. Further work by Douglas Gilbert.
165

REPORTING BUGS

167       Report bugs to <dgilbert at interlog dot com>.
168
170       Copyright © 2004-2013 Douglas Gilbert
171       This software is distributed under the GPL version 2. There is NO  war‐
172       ranty;  not  even  for MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR‐
173       POSE.
174

SEE ALSO

176       sg_read_long, sg_dd (both in sg3_utils), sdparm(sdparm)
177
178
179
180sg3_utils-1.36                   February 2013                SG_WRITE_LONG(8)
Impressum