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

NAME

6       sg_write_same - send the SCSI WRITE SAME command
7

SYNOPSIS

9       sg_write_same    [--16]   [--32]   [--grpnum=GN]   [--help]   [--in=IF]
10       [--lba=LBA] [--lbdata] [--num=NUM] [--pbdata] [--timeout=TO]  [--unmap]
11       [--verbose] [--version] [--wrprotect=WPR] [--xferlen=LEN] DEVICE
12

DESCRIPTION

14       Send  the  SCSI  WRITE SAME (10, 16 or 32 byte) command to DEVICE. This
15       command writes the given block NUM times to consecutive blocks  on  the
16       DEVICE starting at logical block address LBA.
17
18       The  length  of the block to be written multiple times is obtained from
19       the LEN argument, the length of the given input file IF, or by  calling
20       READ  CAPACITY(16)  on  DEVICE. The contents of the block to be written
21       are obtained from the input file IF or zeroes are used. If READ  CAPAC‐
22       ITY(16)  is called (which implies IF was not given) and the PROT_EN bit
23       is set then the last 8 bytes are set to 0xff.
24
25       By default WRITE SAME(10) is sent unless  LBA  (plus  NUM)  exceeds  32
26       bits,  NUM exceeds 65535 or the --unmap option is given. In these cases
27       WRITE SAME(16) is sent.
28
29       Take care: The WRITE SAME(10, 16 and 32) commands interpret  a  NUM  of
30       zero  as  write  to the end of DEVICE. This utility defaults NUM to 1 .
31       The WRITE SAME commands have no IMMED bit so if NUM is large (or  zero)
32       then  an invocation of this utility could take a long time, potentially
33       as long as a FORMAT UNIT command. In such situations the command  time‐
34       out value TO may need to be increased from its default value of 60 sec‐
35       onds.
36
37       As a precaution against an  accidental  'sg_write_same  /dev/sda'  (for
38       example) overwriting LBA 0 on /dev/sda with zeroes, at least one of the
39       --in=IF, --lba=LBA or --num=NUM options must be given.  Obviously  this
40       utility can destroy a lot of user data so check the options carefully.
41
42       This   utility   is   based   SBC-3   draft   revision   19   found  at
43       http://www.t10.org .
44

OPTIONS

46       Arguments to long options are mandatory for short options as well.
47
48       -S, --16
49              send a SCSI WRITE SAME  (16)  command  to  DEVICE.  The  default
50              action (in the absence of this option and the --32 option) is to
51              send a SCSI WRITE SAME (10) command.
52
53       -T, --32
54              send a SCSI WRITE SAME  (32)  command  to  DEVICE.  The  default
55              action (in the absence of this option and the --16 option) is to
56              send a SCSI WRITE SAME (10) command.
57
58       -g, --grpnum=GN
59              sets the 'Group number' field to GN.  Defaults  to  a  value  of
60              zero.  GN should be a value between 0 and 31.
61
62       -h, --help
63              output the usage message then exit.
64
65       -i, --in=IF
66              read data (binary) from file named IF and use it as the data out
67              buffer for the SCSI WRITE SAME command. The length of  the  data
68              out buffer is --xferlen=LEN or, if that is not given, the length
69              of the IF file. If IF is "-" then stdin is read. If this  option
70              is not given then 0x00 bytes are used as fill with the length of
71              the data out buffer obtained from --xferlen=LEN  or  by  calling
72              READ  CAPACITY(16). If the response to READ CAPACITY(16) has the
73              PROT_EN bit set then data out buffer size  is  modified  accord‐
74              ingly with the last 8 bytes set to 0xff.
75
76       -l, --lba=LBA
77              where  LBA  is the logical block address to start the WRITE SAME
78              command.  Defaults to lba 0 which is a dangerous block to  over‐
79              write  on a disk that is in use. Assumed to be in decimal unless
80              prefixed with '0x' or has a trailing 'h'.
81
82       -L, --lbdata
83              sets the LBDATA bit in the WRITE SAME cdb.
84
85       -n, --num=NUM
86              where NUM is the number of blocks, starting at LBA, to write the
87              data  out  buffer  to. The default value for NUM is 1. The value
88              corresponds to the 'Number of logical blocks' field in the WRITE
89              SAME  cdb. Note that a value of 0 in NUM is interpreted as write
90              the data out buffer on every block starting at LBA to the end of
91              the DEVICE.
92
93       -P, --pbdata
94              sets the PBDATA bit in the WRITE SAME cdb.
95
96       -t, --timeout=TO
97              where  TO  is  the command timeout value in seconds. The default
98              value is 60 seconds. If NUM is large (or zero) a WRITE SAME com‐
99              mand  may require considerably more time than 60 seconds to com‐
100              plete.
101
102       -U, --unmap
103              sets the UNMAP bit in the WRITE SAME(16 and 32) cdb.  When  this
104              option is given the default command becomes WRITE SAME(16) since
105              the WRITE SAME(10) command does not offer  this  bit  (in  SBC-3
106              draft revision 19). See UNMAP section below.
107
108       -v, --verbose
109              increase the degree of verbosity (debug messages).
110
111       -V, --version
112              output version string then exit.
113
114       -w, --wrprotect=WPR
115              sets the "Write protect" field in the WRITE SAME cdb to WPR. The
116              default value is zero. WPR should be a value between 0 and 7.
117
118       -x, --xferlen=LEN
119              where LEN is the data out buffer length. Defaults to the  length
120              of  the  IF  file or, if that is not given, then the READ CAPAC‐
121              ITY(16) command is called on the DEVICE and the  'Logical  block
122              length in bytes' and the PROT_EN bit in the response are used to
123              determine the data out buffer length. If both  this  option  and
124              the  IF  option  are  given and LEN exceeds the length of the IF
125              file then LEN is the data out buffer length with zeroes used  as
126              pad bytes.
127

UNMAP

129       Thin  provisioning  is the sophisticated term used in SBC-3 revision 19
130       for the ability to mark blocks as unused. It is closely related to  the
131       ATA  DATA  SET  MANAGEMENT  command  with the "Trim" bit set. For large
132       storage arrays, it is a way to provision less physical storage than the
133       READ CAPACITY command reports is available, potentially allocating more
134       physical storage when WRITE commands require it. For flash memory it is
135       a  way of potentially saving power (and perhaps access time) when it is
136       known large sections (or almost all) of the flash memory is not in use.
137
138       Support for thin provisioning is indicated by the TPE bit being set  in
139       the  READ  CAPACITY(16)  command response. That implies at least one of
140       the UNMAP or WRITE SAME(16) commands is implemented. If the UNMAP  com‐
141       mand  is  implemented  then  the "Maximum unmap LBA count" and "Maximum
142       unmap block descriptor count" fields  in  the  Block  Limits  VPD  page
143       should  both  be  greater  than  zero.  The  READ  CAPACITY(16) command
144       response also contains a TPRZ bit which if set means that  if  unmapped
145       blocks  are read then zeroes will be returned for the data (and if pro‐
146       tection information is active, 0xff bytes are returned for that).
147
148       In the cases of WRITE SAME(16) and WRITE SAME(32) when the Unmap bit is
149       set  in the cdb then the data out buffer is also sent. Additionally the
150       data section of that data out buffer should be full of 0x0 bytes  while
151       the data protection block, 8 bytes at the end if present, should be set
152       to 0xff bytes. If these conditions are not met and the TPRZ bit is  set
153       then the Unmap bit is ignored and the data out buffer is written to the
154       DEVICE as if the Unmap bit was zero. In  the  absence  of  the  --in=IF
155       option,  this  utility  will attempt build a data out buffer that meets
156       the requirements for the Unmap bit in the cdb to be  acted  on  by  the
157       DEVICE.
158
159       Logical  blocks  may also be unmapped by the SCSI UNMAP and FORMAT UNIT
160       commands (see the sg_unmap and sg_format utilities). Support  for  thin
161       provisioning  is  indicated  by the TPE bit in the response to the SCSI
162       READ CAPACITY (16) command (see the sg_readcap utility).
163

NOTES

165       Various numeric arguments (e.g. LBA) may  include  multiplicative  suf‐
166       fixes  or  be given in hexadecimal. See the "NUMERIC ARGUMENTS" section
167       in the sg3_utils(8) man page.
168

EXIT STATUS

170       The exit status of sg_write_same is 0 when it is successful.  Otherwise
171       see the sg3_utils(8) man page.
172

AUTHORS

174       Written by Douglas Gilbert.
175

REPORTING BUGS

177       Report bugs to <dgilbert at interlog dot com>.
178
180       Copyright © 2009 Douglas Gilbert
181       This  software is distributed under a FreeBSD license. There is NO war‐
182       ranty; not even for MERCHANTABILITY or FITNESS FOR  A  PARTICULAR  PUR‐
183       POSE.
184

SEE ALSO

186       sg_format,sg_readcap,sg_unmap(sg3_utils)
187
188
189
190sg3_utils-1.28                     June 2009                  SG_WRITE_SAME(8)
Impressum