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

NAME

6       sgm_dd  -  copies  data  to and from files and devices. Specialized for
7       devices that understand the SCSI command set  and  does  memory  mapped
8       transfers from sg devices.
9

SYNOPSIS

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

DESCRIPTION

18       Copy data to and from any files. Specialized for "files" that are Linux
19       SCSI generic (sg) devices and raw devices. Uses memory mapped transfers
20       on  sg devices. Similar syntax and semantics to dd(1) but does not per‐
21       form any conversions.
22
23       Will only perform memory mapped transfers when IFILE or OFILE are  SCSI
24       generic  (sg) devices. If both IFILE and OFILE are sg devices then mem‐
25       ory mapped transfers are only performed on IFILE.
26
27       The first group in the synopsis above are "standard" Unix  dd(1)  oper‐
28       ands.  The  second group are extra options added by this utility.  Both
29       groups are defined below.
30

OPTIONS

32       bpt=BPT
33              each IO transaction will be made using BPT blocks  (or  less  if
34              near  the  end of the copy). Default is 128 for block sizes less
35              that 2048 bytes, otherwise the default is 32. So for bs=512  the
36              reads  and  writes  will  each  convey 64 KiB of data by default
37              (less if near the end of the transfer or  memory  restrictions).
38              When  cd/dvd  drives  are  accessed, the block size is typically
39              2048 bytes and bpt defaults to 32 which  again  implies  64  KiB
40              transfers.
41
42       bs=BS  where  BS  must  be  the block size of the physical device. Note
43              that this differs from dd(1) which permits BS to be an  integral
44              multiple.  Default is 512 which is usually correct for disks but
45              incorrect for cdroms (which normally have 2048 byte blocks). For
46              this utility the maximum size of each individual IO operation is
47              BS * BPT bytes.
48
49       cdbsz=6 | 10 | 12 | 16
50              size of SCSI READ and/or WRITE  commands  issued  on  sg  device
51              names.   Default is 10 byte SCSI command blocks (unless calcula‐
52              tions indicate that a 4 byte block number may  be  exceeded,  in
53              which case it defaults to 16 byte SCSI commands).
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 derived
61              (i.e.  not explicitly given) then the derived  count  is  scaled
62              back  so  that the copy will not overrun the device. If the file
63              name is a block device partition and COUNT is not given then the
64              size  of  the partition rather than the size of the whole device
65              is used. If COUNT is not given and cannot  be  derived  then  an
66              error message is issued and no copy takes place.
67
68       dio=0 | 1
69              permits  direct  IO  to  be  selected on the write-side (i.e. on
70              OFILE).  Only allowed when the read-side (i.e. IFILE)  is  a  sg
71              device.  When  1  there  may be a "zero copy" copy (i.e. mmap-ed
72              transfer on the read into the user  space  and  direct  IO  from
73              there  on  the  write,  potentially two DMAs and no data copying
74              from the CPU). Default is 0.
75
76       ibs=BS if given must be the same as BS given to 'bs=' option.
77
78       if=IFILE
79              read from IFILE instead of stdin. If IFILE is '-' then stdin  is
80              read.  Starts  reading  at the beginning of IFILE unless SKIP is
81              given.
82
83       iflag=FLAGS
84              where FLAGS is a comma separated list of one or more flags  out‐
85              lined  below.   These  flags  are  associated with IFILE and are
86              ignored when IFILE is stdin.
87
88       obs=BS if given must be the same as BS given to 'bs=' option.
89
90       of=OFILE
91              write to OFILE instead of stdout. If OFILE is '-' then writes to
92              stdout.  If  OFILE  is  /dev/null then no actual writes are per‐
93              formed.  If OFILE is '.' (period) then it is  treated  the  same
94              way as /dev/null (this is a shorthand notation). If OFILE exists
95              then it is _not_ truncated; it is overwritten from the start  of
96              OFILE unless 'oflag=append' or SEEK is given.
97
98       oflag=FLAGS
99              where  FLAGS is a comma separated list of one or more flags out‐
100              lined below.  These flags are  associated  with  OFILE  and  are
101              ignored when OFILE is /dev/null, '.' (period), or stdout.
102
103       seek=SEEK
104              start  writing  SEEK  bs-sized  blocks  from the start of OFILE.
105              Default is block 0 (i.e. start of file).
106
107       skip=SKIP
108              start reading SKIP bs-sized blocks  from  the  start  of  IFILE.
109              Default is block 0 (i.e. start of file).
110
111       sync=0 | 1
112              when  1,  does  SYNCHRONIZE CACHE command on OFILE at the end of
113              the transfer. Only active when OFILE is a sg device file name.
114
115       time=0 | 1
116              when 1, times transfer and  does  throughput  calculation,  out‐
117              putting  the results (to stderr) at completion. When 0 (default)
118              doesn't perform timing.
119
120       verbose=VERB
121              as VERB increases so does the amount of  debug  output  sent  to
122              stderr.   Default  value is zero which yields the minimum amount
123              of debug output.  A value of 1 reports extra information that is
124              not  repetitive.  A  value 2 reports cdbs and responses for SCSI
125              commands that are not  repetitive  (i.e.  other  that  READ  and
126              WRITE). Error processing is not considered repetitive. Values of
127              3 and 4 yield output for all SCSI commands (and Unix read()  and
128              write() calls) so there can be a lot of output.
129
130       --help outputs usage message and exits.
131
132       --version
133              outputs version number information and exits.
134

FLAGS

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

RETIRED OPTIONS

172       Here are some retired options that are still present:
173
174       fua=0 | 1 | 2 | 3
175              force unit access bit. When 3, fua is  set  on  both  IFILE  and
176              OFILE; when 2, fua is set on IFILE; when 1, fua is set on OFILE;
177              when 0 (default), fua is cleared on both. See the 'fua' flag.
178

NOTES

180       A raw device must be bound to a block device  prior  to  using  sgm_dd.
181       See  raw(8) for more information about binding raw devices. To be safe,
182       the sg device mapping to SCSI block devices should be checked with 'cat
183       /proc/scsi/scsi' before use.
184
185       Raw  device partition information can often be found with fdisk(8) [the
186       "-ul" argument is useful in this respect].
187
188       COUNT, SKIP, SEEK, BPT and BS may include one of  these  multiplicative
189       suffixes:  c C *1; w W *2; b B *512; k K KiB *1,024; KB *1,000; m M MiB
190       *1,048,576; MB *1,000,000 . This pattern continues  for  "G",  "T"  and
191       "P". The latter two suffixes can only be used for COUNT, SKIP and SEEK.
192       Also a suffix of the form "x<n>" multiplies the leading number by  <n>.
193       These  multiplicative  suffixes  are  compatible  with GNU's dd command
194       (since 2002) which claims compliance with SI and with IEC 60027-2.
195
196       Alternatively numerical values can be given in hexadecimal preceded  by
197       either  "0x"  or "0X" (or with a trailing "h" or "H"). When hex numbers
198       are given, multipliers cannot be used.
199
200       The count, skip and seek parameters can take 64 bit values  (i.e.  very
201       big  numbers).  Other values are limited to what can fit in a signed 32
202       bit number.
203
204       Data usually gets to the user space in a 2  stage  process:  first  the
205       SCSI  adapter  DMAs  into  kernel buffers and then the sg driver copies
206       this data into user memory (write operations  reverse  this  sequence).
207       With  memory  mapped transfers a kernel buffer reserved by sg is memory
208       mapped (see the mmap(2) system call) into the user space. When this  is
209       done  the  second (redundant) copy from kernel buffers to user space is
210       not needed. Hence the transfer is faster and requires less "grunt" from
211       the CPU.
212
213       All  informative,  warning  and  error output is sent to stderr so that
214       dd's output file can be stdout and remain unpolluted. If no options are
215       given, then the usage message is output and nothing else happens.
216
217       For  sg  devices this utility issues SCSI READ and WRITE (SBC) commands
218       which are appropriate for disks and reading from CD/DVD  drives.  Those
219       commands  are not formatted correctly for tape devices so sgm_dd should
220       not be used on tape devices.
221
222       This utility stops the copy if  any  error  is  encountered.  For  more
223       advanced  "copy  on  error"  logic see the sg_dd utility (and its 'coe'
224       flag).
225

EXAMPLES

227       See the examples given in the man page for sg_dd(8).
228

SIGNALS

230       The signal handling has been borrowed from dd: SIGINT, SIGQUIT and SIG‐
231       PIPE  output  the  number of remaining blocks to be transferred and the
232       records in + out counts; then they have their default action.   SIGUSR1
233       causes  the  same information to be output yet the copy continues.  All
234       output caused by signals is sent to stderr.
235

EXIT STATUS

237       The exit status of sgm_dd is 0 when it is successful. Otherwise see the
238       sg3_utils(8)  man page. Since this utility works at a higher level than
239       individual commands, and there are 'coe' and 'retries' flags,  individ‐
240       ual SCSI command failures do not necessary cause the process to exit.
241

AUTHORS

243       Written by Doug Gilbert and Peter Allworth.
244

REPORTING BUGS

246       Report bugs to <dgilbert at interlog dot com>.
247
249       Copyright © 2000-2007 Douglas Gilbert
250       This  software is distributed under the GPL version 2. There is NO war‐
251       ranty; not even for MERCHANTABILITY or FITNESS FOR  A  PARTICULAR  PUR‐
252       POSE.
253

SEE ALSO

255       The  simplest variant of this utility is called sg_dd.  A POSIX threads
256       version of this utility called sgp_dd is in the sg3_utils package.  The
257       lmbench package contains lmdd which is also interesting.  raw(8), dd(1)
258
259
260
261sg3_utils-1.23                   January 2007                        SGM_DD(8)
Impressum