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

UNMAP

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

NOTES

169       Various  numeric  arguments  (e.g. LBA) may include multiplicative suf‐
170       fixes or be given in hexadecimal. See the "NUMERIC  ARGUMENTS"  section
171       in the sg3_utils(8) man page.
172

EXIT STATUS

174       The  exit status of sg_write_same is 0 when it is successful. Otherwise
175       see the sg3_utils(8) man page.
176

AUTHORS

178       Written by Douglas Gilbert.
179

REPORTING BUGS

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

SEE ALSO

190       sg_format,sg_get_lba_status,sg_readcap,sg_unmap(sg3_utils)
191
192
193
194sg3_utils-1.29                    March 2010                  SG_WRITE_SAME(8)
Impressum