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

NAME

6       sgp_dd  -  copies  data  to and from files and devices. Specialized for
7       devices that understand the SCSI command set.
8

SYNOPSIS

10       sgp_dd [bs=BS] [count=COUNT] [ibs=BS] [if=IFILE] [iflag=FLAGS] [obs=BS]
11       [of=OFILE] [oflag=FLAGS] [seek=SEEK] [skip=SKIP] [--help] [--version]
12
13       [bpt=BPT]  [coe=0|1] [cdbsz=6|10|12|16] [deb=VERB] [dio=0|1] [sync=0|1]
14       [thr=THR] [time=0|1] [verbose=VERB]
15

DESCRIPTION

17       Copy data to and from any files. Specialised for "files" that are Linux
18       SCSI  generic  (sg)  and  raw  devices. Similar syntax and semantics to
19       dd(1) but does not perform  any  conversions.  Uses  POSIX  threads  to
20       increase the amount of parallelism. This improves speed in some cases.
21
22       The  first  group in the synopsis above are "standard" Unix dd(1) oper‐
23       ands. The second group are extra options added by this  utility.   Both
24       groups are defined below.
25

OPTIONS

27       bpt=BPT
28              each  IO  transaction  will be made using BPT blocks (or less if
29              near the end of the copy). Default is 128 for block  sizes  less
30              that  2048 bytes, otherwise the default is 32. So for bs=512 the
31              reads and writes will each convey 64  KiB  of  data  by  default
32              (less  if  near the end of the transfer or memory restrictions).
33              When cd/dvd drives are accessed, the  block  size  is  typically
34              2048  bytes  and  bpt  defaults to 32 which again implies 64 KiB
35              transfers.
36
37       bs=BS  where BS must be the block size of  the  physical  device.  Note
38              that  this  differs from dd(1) which permits 'bs' to be an inte‐
39              gral multiple of the actual device block size.  Default  is  512
40              which  is  usually  correct  for  disks but incorrect for cdroms
41              (which normally have 2048 byte blocks).
42
43       cdbsz=6 | 10 | 12 | 16
44              size of SCSI READ and/or WRITE  commands  issued  on  sg  device
45              names.   Default is 10 byte SCSI command blocks (unless calcula‐
46              tions indicate that a 4 byte block number may  be  exceeded,  in
47              which case it defaults to 16 byte SCSI commands).
48
49       coe=0 | 1
50              set  to  1  for  continue on error. Only applies to errors on sg
51              devices.  Thus errors on other files will stop  sgp_dd.  Default
52              is  0  which  implies  stop on any error. See the 'coe' flag for
53              more information.
54
55       count=COUNT
56              copy COUNT blocks from IFILE to OFILE. Default  is  the  minimum
57              (of  IFILE  and  OFILE)  number of blocks that sg devices report
58              from SCSI READ CAPACITY commands or that block devices (or their
59              partitions)  report. Normal files are not probed for their size.
60              If skip=SKIP or skip=SEEK are given and  the  count  is  deduced
61              (i.e.   not  explicitly given) then that count is scaled back so
62              that the copy will not overrun the device. If the file name is a
63              block  device  partition and COUNT is not given then the size of
64              the partition rather than the size of the whole device is  used.
65              If  COUNT  is not given and cannot be deduced then an error mes‐
66              sage is issued and no copy takes place.
67
68       deb=VERB
69              outputs debug information. If VERB is 0 (default) then there  is
70              minimal  debug  information  and  as  VERB increases so does the
71              amount of debug (max debug output when VERB is 9).
72
73       dio=0 | 1
74              default is 0 which selects indirect  IO.  Value  of  1  attempts
75              direct IO which, if not available, falls back to indirect IO and
76              notes  this  at  completion.  If  direct  IO  is  selected   and
77              /proc/scsi/sg/allow_dio  has  the  value  of 0 then a warning is
78              issued (and indirect IO is performed)
79
80       ibs=BS if given must be the same as BS given to 'bs=' option.
81
82       if=IFILE
83              read from IFILE instead of stdin. If IFILE is '-' then stdin  is
84              read.  Starts  reading  at the beginning of IFILE unless SKIP is
85              given.
86
87       iflag=FLAGS
88              where FLAGS is a comma separated list of one or more flags  out‐
89              lined  below.   These  flags  are  associated with IFILE and are
90              ignored when IFILE is stdin.
91
92       obs=BS if given must be the same as BS given to 'bs=' option.
93
94       of=OFILE
95              write to OFILE instead of stdout. If OFILE is '-' then writes to
96              stdout.   If  OFILE  is /dev/null then no actual writes are per‐
97              formed.  If OFILE is '.' (period) then it is  treated  the  same
98              way as /dev/null (this is a shorthand notation). If OFILE exists
99              then it is _not_ truncated; it is overwritten from the start  of
100              OFILE unless 'oflag=append' or SEEK is given.
101
102       oflag=FLAGS
103              where  FLAGS is a comma separated list of one or more flags out‐
104              lined below.  These flags are  associated  with  OFILE  and  are
105              ignored when OFILE is /dev/null, '.' (period), or stdout.
106
107       seek=SEEK
108              start  writing  SEEK  bs-sized  blocks  from the start of OFILE.
109              Default is block 0 (i.e. start of file).
110
111       skip=SKIP
112              start reading SKIP bs-sized blocks  from  the  start  of  IFILE.
113              Default is block 0 (i.e. start of file).
114
115       sync=0 | 1
116              when  1,  does  SYNCHRONIZE CACHE command on OFILE at the end of
117              the transfer. Only active when OFILE is a sg device file name.
118
119       thr=THR
120              where THR is the number  or  worker  threads  (default  4)  that
121              attempt to copy in parallel. Minimum is 1 and maximum is 16.
122
123       time=0 | 1
124              when 1, the transfer is timed and throughput calculation is per‐
125              formed, outputting the results (to stderr) at completion. When 0
126              (default) no timing is performed.
127
128       verbose=VERB
129              increase  verbosity.  Same  as deb=VERB. Added for compatibility
130              with sg_dd and sgm_dd.
131
132       --help outputs usage message and exits.
133
134       --version
135              outputs version number information and exits.
136

FLAGS

138       Here is a list of flags and their meanings:
139
140       append causes the O_APPEND flag to be added to the open of  OFILE.  For
141              normal  files  this will lead to data appended to the end of any
142              existing data.  Cannot  be  used  together  with  the  seek=SEEK
143              option  as they conflict.  The default action of this utility is
144              to overwrite any existing data from the beginning  of  the  file
145              or, if SEEK is given, starting at block SEEK. Note that attempt‐
146              ing to 'append' to a device file (e.g.  a disk) will usually  be
147              ignored or may cause an error to be reported.
148
149       coe    continue  on  error.  When given with 'iflag=', an error that is
150              detected in a single SCSI command (typically  'bpt'  blocks)  is
151              noted  (by an error message sent to stderr), then zeros are sub‐
152              stituted into the buffer for the corresponding  write  operation
153              and  the  copy  continues.  Note  that the sg_dd utility is more
154              sophisticated in such error situations when  'iflag=coe'.   When
155              given  with 'oflag=', any error reported by a SCSI WRITE command
156              is reported to stderr and the copy continues (as if nothing went
157              wrong).
158
159       direct causes the O_DIRECT flag to be added to the open of IFILE and/or
160              OFILE. This flag requires some memory  alignment  on  IO.  Hence
161              user  memory buffers are aligned to the page size. Has no effect
162              on sg, normal or raw files.
163
164       dpo    set the DPO bit (disable page out) in SCSI READ and  WRITE  com‐
165              mands.  Not supported for 6 byte cdb variants of READ and WRITE.
166              Indicates that data is unlikely to be required to stay in device
167              (e.g.  disk)  cache.   May speed media copy and/or cause a media
168              copy to have less impact on other device users.
169
170       dsync  causes the O_SYNC flag to be added to the open of  IFILE  and/or
171              OFILE.  The  'd'  is  prepended  to  lower  confusion  with  the
172              'sync=0|1' option which has another action (i.e. a  synchronisa‐
173              tion to media at the end of the transfer).
174
175       excl   causes  the  O_EXCL flag to be added to the open of IFILE and/or
176              OFILE.
177
178       fua    causes the FUA (force unit access) bit to be set  in  SCSI  READ
179              and/or WRITE commands. This only has effect with sg devices. The
180              6 byte variants of the SCSI READ and WRITE commands do not  sup‐
181              port the FUA bit.  Only active for sg device file names.
182

RETIRED OPTIONS

184       Here are some retired options that are still present:
185
186       coe=0 | 1
187              continue  on  error  is  0 (off) by default. When it is 1, it is
188              equivalent to 'iflag=coe oflag=coe' described in the FLAGS  sec‐
189              tion above.  Similar to 'conv=noerror' in dd(1) utility. Default
190              is 0 which implies stop on error. More advanced coe=1 processing
191              on reads is performed by the sg_dd utility.
192
193
194       fua=0 | 1 | 2 | 3
195              force  unit  access bit. When 3, fua is set on both IFILE
196              and OFILE; when 2, fua is set on IFILE;, when 1,  fua  is
197              set  on  OFILE; when 0 (default), fua is cleared on both.
198              See the 'fua' flag.
199

NOTES

201       A raw device must be bound to a  block  device  prior  to  using
202       sgp_dd.   See  raw(8)  for  more  information  about binding raw
203       devices. To be safe, the sg device mapping to SCSI block devices
204       should be checked with 'cat /proc/scsi/scsi' before use.
205
206       Raw  device  partition  information  can  often  be  found  with
207       fdisk(8) [the "-ul" argument is useful in this respect].
208
209       COUNT, SKIP, SEEK, BPT and BS may include one  of  these  multi‐
210       plicative suffixes: c C *1; w W *2; b B *512; k K KiB *1,024; KB
211       *1,000; m M MiB *1,048,576; MB *1,000,000 . This pattern contin‐
212       ues  for  "G",  "T" and "P". The latter two suffixes can only be
213       used for COUNT, SKIP and SEEK.  Also a suffix of the form "x<n>"
214       multiplies the leading number by <n>.  These multiplicative suf‐
215       fixes are compatible with GNU's dd command  (since  2002)  which
216       claims compliance with SI and with IEC 60027-2.
217
218       Alternatively  numerical values can be given in hexadecimal pre‐
219       ceded by either "0x" or "0X". When hex numbers are given, multi‐
220       pliers cannot be used.
221
222       The  COUNT, SKIP and SEEK arguments can take 64 bit values (i.e.
223       very big numbers). Other values are limited to what can fit in a
224       signed 32 bit number.
225
226       Data  usually gets to the user space in a 2 stage process: first
227       the SCSI adapter DMAs into kernel buffers and then the sg driver
228       copies this data into user memory (write operations reverse this
229       sequence).  This is called "indirect IO" and there  is  a  'dio'
230       option  to  select "direct IO" which will DMA directly into user
231       memory. Due to some issues "direct IO" is  disabled  in  the  sg
232       driver and needs a configuration change to activate it.
233
234       All  informative,  warning and error output is sent to stderr so
235       that dd's output file can be stdout and remain unpolluted. If no
236       options  are given, then the usage message is output and nothing
237       else happens.
238
239       Why use sgp_dd? Because in some cases it is twice as fast as  dd
240       (mainly  with  sg  devices,  raw devices give some improvement).
241       Another reason is that big copies fill the block  device  caches
242       which has a negative impact on other machine activity.
243

SIGNALS

245       The  signal  handling has been borrowed from dd: SIGINT, SIGQUIT
246       and SIGPIPE output the number of remaining blocks to  be  trans‐
247       ferred  and  the  records  in + out counts; then they have their
248       default action.  SIGUSR1 causes the same information to be  out‐
249       put  yet  the  copy  continues.  All output caused by signals is
250       sent to stderr.
251

EXAMPLES

253       Looks quite similar in usage to dd:
254
255          sgp_dd if=/dev/sg0 of=t bs=512 count=1MB
256
257       This will copy 1 million 512 byte blocks from the device associ‐
258       ated with /dev/sg0 (which should have 512 byte blocks) to a file
259       called t.  Assuming /dev/sda and /dev/sg0 are  the  same  device
260       then the above is equivalent to:
261
262          dd if=/dev/sda of=t bs=512 count=1000000
263
264       although  dd's  speed may improve if bs was larger and count was
265       correspondingly scaled. Using a raw device to do something simi‐
266       lar on a ATA disk:
267
268          raw /dev/raw/raw1 /dev/hda
269          sgp_dd if=/dev/raw/raw1 of=t bs=512 count=1MB
270
271       To copy a SCSI disk partition to an ATA disk partition:
272
273          raw /dev/raw/raw2 /dev/hda3
274          sgp_dd if=/dev/sg0 skip=10123456 of=/dev/raw/raw2 bs=512
275
276       This  assumes a valid partition is found on the SCSI disk at the
277       given skip block address (past the 5 GB point of that disk)  and
278       that the partition goes to the end of the SCSI disk. An explicit
279       count is probably a safer option.
280
281       To do a fast copy from one SCSI disk to another one with similar
282       geometry (stepping over errors on the source disk):
283
284          sgp_dd if=/dev/sg0 of=/dev/sg1 bs=512 coe=1
285

EXIT STATUS

287       The  exit status of sgp_dd is 0 when it is successful. Otherwise
288       see the sg3_utils(8) man page. Since this  utility  works  at  a
289       higher  level  than individual commands, and there are 'coe' and
290       'retries' flags, individual SCSI command failures do not  neces‐
291       sary cause the process to exit.
292

AUTHORS

294       Written by Doug Gilbert and Peter Allworth.
295

REPORTING BUGS

297       Report bugs to <dgilbert at interlog dot com>.
298
300       Copyright © 2000-2007 Douglas Gilbert
301       This  software  is distributed under the GPL version 2. There is
302       NO warranty; not even for MERCHANTABILITY or FITNESS FOR A  PAR‐
303       TICULAR PURPOSE.
304

SEE ALSO

306       A  simpler,  non-threaded  version of this utility but with more
307       advanced "continue on error" logic is called sg_dd and  is  also
308       found  in  the  sg3_utils  package. The lmbench package contains
309       lmdd which is also interesting.  raw(8), dd(1)
310
311
312
313sg3_utils-1.23                   January 2007                        SGP_DD(8)
Impressum