blob: a243f718bcf2f2994283590387503c134fcf0338 [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Eric Andersencc8ed391999-10-05 16:24:54 +00002/*
Eric Andersenc4996011999-10-20 22:08:37 +00003 * Mini dd implementation for busybox
4 *
Matt Kraai3eeab3b2001-12-07 16:27:37 +00005 * Copyright (C) 2000,2001 Matt Kraai
Eric Andersenc4996011999-10-20 22:08:37 +00006 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02007 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Eric Andersencc8ed391999-10-05 16:24:54 +00008 */
Ari Sundholmf22a8382015-02-07 01:41:22 +01009//config:config DD
Denys Vlasenkob097a842018-12-28 03:20:17 +010010//config: bool "dd (7.5 kb)"
Ari Sundholmf22a8382015-02-07 01:41:22 +010011//config: default y
12//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020013//config: dd copies a file (from standard input to standard output,
14//config: by default) using specific input and output blocksizes,
15//config: while optionally performing conversions on it.
Ari Sundholmf22a8382015-02-07 01:41:22 +010016//config:
17//config:config FEATURE_DD_SIGNAL_HANDLING
18//config: bool "Enable signal handling for status reporting"
19//config: default y
20//config: depends on DD
21//config: help
Denys Vlasenko18e781d2017-08-02 14:12:48 +020022//config: Sending a SIGUSR1 signal to a running 'dd' process makes it
Denys Vlasenko72089cf2017-07-21 09:50:55 +020023//config: print to standard error the number of records read and written
24//config: so far, then to resume copying.
Ari Sundholmf22a8382015-02-07 01:41:22 +010025//config:
Denys Vlasenko72089cf2017-07-21 09:50:55 +020026//config: $ dd if=/dev/zero of=/dev/null &
27//config: $ pid=$!; kill -USR1 $pid; sleep 1; kill $pid
28//config: 10899206+0 records in
29//config: 10899206+0 records out
Ari Sundholmf22a8382015-02-07 01:41:22 +010030//config:
31//config:config FEATURE_DD_THIRD_STATUS_LINE
32//config: bool "Enable the third status line upon signal"
33//config: default y
34//config: depends on DD && FEATURE_DD_SIGNAL_HANDLING
35//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020036//config: Displays a coreutils-like third status line with transferred bytes,
37//config: elapsed time and speed.
Ari Sundholmf22a8382015-02-07 01:41:22 +010038//config:
39//config:config FEATURE_DD_IBS_OBS
Rostislav Skudnov3f6a9782018-10-15 10:26:15 +000040//config: bool "Enable ibs, obs, iflag, oflag and conv options"
Ari Sundholmf22a8382015-02-07 01:41:22 +010041//config: default y
42//config: depends on DD
43//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020044//config: Enable support for writing a certain number of bytes in and out,
45//config: at a time, and performing conversions on the data stream.
Ari Sundholmf22a8382015-02-07 01:41:22 +010046//config:
47//config:config FEATURE_DD_STATUS
48//config: bool "Enable status display options"
49//config: default y
50//config: depends on DD
51//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020052//config: Enable support for status=noxfer/none option.
Ari Sundholmf22a8382015-02-07 01:41:22 +010053
Denys Vlasenkoaf3f4202016-11-23 14:46:56 +010054//applet:IF_DD(APPLET_NOEXEC(dd, dd, BB_DIR_BIN, BB_SUID_DROP, dd))
55
56//kbuild:lib-$(CONFIG_DD) += dd.o
57
Pere Orga34425382011-03-31 14:43:25 +020058//usage:#define dd_trivial_usage
Denys Vlasenko9ab5a8d2018-10-30 17:04:52 +010059//usage: "[if=FILE] [of=FILE] [" IF_FEATURE_DD_IBS_OBS("ibs=N obs=N/") "bs=N] [count=N] [skip=N] [seek=N]\n"
60//usage: IF_FEATURE_DD_IBS_OBS(
61//usage: " [conv=notrunc|noerror|sync|fsync]\n"
Rafał Miłecki4eb46e12021-03-24 16:01:42 +010062//usage: " [iflag=skip_bytes|count_bytes|fullblock|direct] [oflag=seek_bytes|append|direct]"
Denys Vlasenko9ab5a8d2018-10-30 17:04:52 +010063//usage: )
Pere Orga34425382011-03-31 14:43:25 +020064//usage:#define dd_full_usage "\n\n"
65//usage: "Copy a file with converting and formatting\n"
Pere Orga34425382011-03-31 14:43:25 +020066//usage: "\n if=FILE Read from FILE instead of stdin"
67//usage: "\n of=FILE Write to FILE instead of stdout"
68//usage: "\n bs=N Read and write N bytes at a time"
69//usage: IF_FEATURE_DD_IBS_OBS(
70//usage: "\n ibs=N Read N bytes at a time"
71//usage: )
72//usage: IF_FEATURE_DD_IBS_OBS(
73//usage: "\n obs=N Write N bytes at a time"
74//usage: )
75//usage: "\n count=N Copy only N input blocks"
76//usage: "\n skip=N Skip N input blocks"
77//usage: "\n seek=N Skip N output blocks"
78//usage: IF_FEATURE_DD_IBS_OBS(
79//usage: "\n conv=notrunc Don't truncate output file"
80//usage: "\n conv=noerror Continue after read errors"
81//usage: "\n conv=sync Pad blocks with zeros"
82//usage: "\n conv=fsync Physically write data out before finishing"
Denys Vlasenkob9413162013-08-19 09:01:39 +020083//usage: "\n conv=swab Swap every pair of bytes"
Rafał Miłeckic30a5b12016-02-01 02:17:28 +010084//usage: "\n iflag=skip_bytes skip=N is in bytes"
Rafał Miłecki4eb46e12021-03-24 16:01:42 +010085//usage: "\n iflag=count_bytes count=N is in bytes"
Rostislav Skudnov3f6a9782018-10-15 10:26:15 +000086//usage: "\n oflag=seek_bytes seek=N is in bytes"
Denys Vlasenko2aaacc12020-12-14 20:27:57 +010087//usage: "\n iflag=direct O_DIRECT input"
88//usage: "\n oflag=direct O_DIRECT output"
89//usage: "\n iflag=fullblock Read full blocks"
90//usage: "\n oflag=append Open output in append mode"
Pere Orga34425382011-03-31 14:43:25 +020091//usage: )
Ari Sundholmf22a8382015-02-07 01:41:22 +010092//usage: IF_FEATURE_DD_STATUS(
93//usage: "\n status=noxfer Suppress rate output"
94//usage: "\n status=none Suppress all output"
95//usage: )
Pere Orga34425382011-03-31 14:43:25 +020096//usage: "\n"
Ari Sundholmf22a8382015-02-07 01:41:22 +010097//usage: "\nN may be suffixed by c (1), w (2), b (512), kB (1000), k (1024), MB, M, GB, G"
Pere Orga34425382011-03-31 14:43:25 +020098//usage:
99//usage:#define dd_example_usage
100//usage: "$ dd if=/dev/zero of=/dev/ram1 bs=1M count=4\n"
101//usage: "4+0 records in\n"
102//usage: "4+0 records out\n"
103
Denis Vlasenkob6adbf12007-05-26 19:00:18 +0000104#include "libbb.h"
Denys Vlasenkoe6a2f4c2016-04-21 16:26:30 +0200105#include "common_bufsiz.h"
Denis Vlasenko99912ca2007-04-10 15:43:37 +0000106
107/* This is a NOEXEC applet. Be very careful! */
108
Eric Andersencbe31da2001-02-20 06:14:08 +0000109
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000110enum {
111 ifd = STDIN_FILENO,
112 ofd = STDOUT_FILENO,
113};
114
Bernhard Reutner-Fischer2a47dea2007-04-04 14:01:23 +0000115struct globals {
116 off_t out_full, out_part, in_full, in_part;
Gabor Heja4e5b07b2009-10-14 00:29:28 +0200117#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
118 unsigned long long total_bytes;
119 unsigned long long begin_time_us;
120#endif
Ari Sundholmf22a8382015-02-07 01:41:22 +0100121 int flags;
Denys Vlasenko98a4c7c2010-02-04 15:00:15 +0100122} FIX_ALIASING;
Denys Vlasenkoe6a2f4c2016-04-21 16:26:30 +0200123#define G (*(struct globals*)bb_common_bufsiz1)
Denys Vlasenko1b34d4f2009-09-30 02:39:57 +0200124#define INIT_G() do { \
Denys Vlasenko47cfbf32016-04-21 18:18:48 +0200125 setup_common_bufsiz(); \
Denys Vlasenko1b34d4f2009-09-30 02:39:57 +0200126 /* we have to zero it out because of NOEXEC */ \
127 memset(&G, 0, sizeof(G)); \
128} while (0)
Denis Vlasenko75878702007-07-27 15:02:00 +0000129
Ari Sundholmf22a8382015-02-07 01:41:22 +0100130enum {
131 /* Must be in the same order as OP_conv_XXX! */
132 /* (see "flags |= (1 << what)" below) */
133 FLAG_NOTRUNC = (1 << 0) * ENABLE_FEATURE_DD_IBS_OBS,
134 FLAG_SYNC = (1 << 1) * ENABLE_FEATURE_DD_IBS_OBS,
135 FLAG_NOERROR = (1 << 2) * ENABLE_FEATURE_DD_IBS_OBS,
136 FLAG_FSYNC = (1 << 3) * ENABLE_FEATURE_DD_IBS_OBS,
137 FLAG_SWAB = (1 << 4) * ENABLE_FEATURE_DD_IBS_OBS,
138 /* end of conv flags */
Rafał Miłeckic30a5b12016-02-01 02:17:28 +0100139 /* start of input flags */
Rafał Miłecki4eb46e12021-03-24 16:01:42 +0100140 FLAG_IFLAG_SHIFT = 5,
141 FLAG_SKIP_BYTES = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS,
142 FLAG_COUNT_BYTES = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS,
143 FLAG_FULLBLOCK = (1 << 7) * ENABLE_FEATURE_DD_IBS_OBS,
144 FLAG_IDIRECT = (1 << 8) * ENABLE_FEATURE_DD_IBS_OBS,
Rafał Miłeckic30a5b12016-02-01 02:17:28 +0100145 /* end of input flags */
Rostislav Skudnov3f6a9782018-10-15 10:26:15 +0000146 /* start of output flags */
Rafał Miłecki4eb46e12021-03-24 16:01:42 +0100147 FLAG_OFLAG_SHIFT = 9,
148 FLAG_SEEK_BYTES = (1 << 9) * ENABLE_FEATURE_DD_IBS_OBS,
149 FLAG_APPEND = (1 << 10) * ENABLE_FEATURE_DD_IBS_OBS,
150 FLAG_ODIRECT = (1 << 11) * ENABLE_FEATURE_DD_IBS_OBS,
Rostislav Skudnov3f6a9782018-10-15 10:26:15 +0000151 /* end of output flags */
Rafał Miłecki4eb46e12021-03-24 16:01:42 +0100152 FLAG_TWOBUFS = (1 << 12) * ENABLE_FEATURE_DD_IBS_OBS,
153 FLAG_COUNT = 1 << 13,
154 FLAG_STATUS_NONE = 1 << 14,
155 FLAG_STATUS_NOXFER = 1 << 15,
Ari Sundholmf22a8382015-02-07 01:41:22 +0100156};
Rob Landleyc5598172006-05-02 22:44:04 +0000157
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000158static void dd_output_status(int UNUSED_PARAM cur_signal)
Rob Landleyc5598172006-05-02 22:44:04 +0000159{
Gabor Heja4e5b07b2009-10-14 00:29:28 +0200160#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
Denys Vlasenko7eabffa2009-10-14 17:43:41 +0200161 double seconds;
162 unsigned long long bytes_sec;
163 unsigned long long now_us = monotonic_us(); /* before fprintf */
Gabor Heja4e5b07b2009-10-14 00:29:28 +0200164#endif
165
Denis Vlasenko980864d2007-07-30 10:58:09 +0000166 /* Deliberately using %u, not %d */
167 fprintf(stderr, "%"OFF_FMT"u+%"OFF_FMT"u records in\n"
168 "%"OFF_FMT"u+%"OFF_FMT"u records out\n",
Bernhard Reutner-Fischer2a47dea2007-04-04 14:01:23 +0000169 G.in_full, G.in_part,
170 G.out_full, G.out_part);
Gabor Heja4e5b07b2009-10-14 00:29:28 +0200171
172#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
Ari Sundholmf22a8382015-02-07 01:41:22 +0100173# if ENABLE_FEATURE_DD_STATUS
174 if (G.flags & FLAG_STATUS_NOXFER) /* status=noxfer active? */
175 return;
176 //TODO: should status=none make dd stop reacting to USR1 entirely?
177 //So far we react to it (we print the stats),
178 //status=none only suppresses final, non-USR1 generated status message.
179# endif
Rafał Miłecki4eb46e12021-03-24 16:01:42 +0100180 fprintf(stderr, /*G.total_bytes < 1024
181 ? "%llu bytes copied, " : */ "%llu bytes (%sB) copied, "
182 , G.total_bytes,
Gabor Heja4e5b07b2009-10-14 00:29:28 +0200183 /* show fractional digit, use suffixes */
184 make_human_readable_str(G.total_bytes, 1, 0)
185 );
186 /* Corner cases:
187 * ./busybox dd </dev/null >/dev/null
188 * ./busybox dd bs=1M count=2000 </dev/zero >/dev/null
189 * (echo DONE) | ./busybox dd >/dev/null
190 * (sleep 1; echo DONE) | ./busybox dd >/dev/null
191 */
Denys Vlasenko7eabffa2009-10-14 17:43:41 +0200192 seconds = (now_us - G.begin_time_us) / 1000000.0;
193 bytes_sec = G.total_bytes / seconds;
Gabor Heja4e5b07b2009-10-14 00:29:28 +0200194 fprintf(stderr, "%f seconds, %sB/s\n",
Denys Vlasenko7eabffa2009-10-14 17:43:41 +0200195 seconds,
Gabor Heja4e5b07b2009-10-14 00:29:28 +0200196 /* show fractional digit, use suffixes */
Denys Vlasenko7eabffa2009-10-14 17:43:41 +0200197 make_human_readable_str(bytes_sec, 1, 0)
Gabor Heja4e5b07b2009-10-14 00:29:28 +0200198 );
199#endif
Rob Landleyc5598172006-05-02 22:44:04 +0000200}
201
Denys Vlasenko2aaacc12020-12-14 20:27:57 +0100202#if ENABLE_FEATURE_DD_IBS_OBS
203static int clear_O_DIRECT(int fd)
204{
205 if (errno == EINVAL) {
206 int fl = fcntl(fd, F_GETFL);
207 if (fl & O_DIRECT) {
208 fcntl(fd, F_SETFL, fl & ~O_DIRECT);
209 return 1;
210 }
211 }
212 return 0;
213}
214#endif
215
216static ssize_t dd_read(void *ibuf, size_t ibs)
217{
218 ssize_t n;
219
220#if ENABLE_FEATURE_DD_IBS_OBS
221 read_again:
222 if (G.flags & FLAG_FULLBLOCK)
223 n = full_read(ifd, ibuf, ibs);
224 else
225#endif
226 n = safe_read(ifd, ibuf, ibs);
227#if ENABLE_FEATURE_DD_IBS_OBS
228 if (n < 0 && (G.flags & FLAG_IDIRECT) && clear_O_DIRECT(ifd))
229 goto read_again;
230#endif
231 return n;
232}
233
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000234static bool write_and_stats(const void *buf, size_t len, size_t obs,
Denis Vlasenko990d0f62007-07-24 15:54:42 +0000235 const char *filename)
Bernhard Reutner-Fischer2a47dea2007-04-04 14:01:23 +0000236{
Denys Vlasenko875ce092019-05-14 17:46:18 +0200237 ssize_t n;
238
Denys Vlasenko2aaacc12020-12-14 20:27:57 +0100239 IF_FEATURE_DD_IBS_OBS(write_again:)
Denys Vlasenko875ce092019-05-14 17:46:18 +0200240 n = full_write(ofd, buf, len);
Denys Vlasenko2aaacc12020-12-14 20:27:57 +0100241#if ENABLE_FEATURE_DD_IBS_OBS
242 if (n < 0 && (G.flags & FLAG_ODIRECT) && clear_O_DIRECT(ofd))
243 goto write_again;
244#endif
245
Gabor Heja4e5b07b2009-10-14 00:29:28 +0200246#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
Denys Vlasenko875ce092019-05-14 17:46:18 +0200247 if (n > 0)
248 G.total_bytes += n;
Gabor Heja4e5b07b2009-10-14 00:29:28 +0200249#endif
Denys Vlasenko5afd63a2018-01-10 10:58:55 +0100250 if ((size_t)n == obs) {
251 G.out_full++;
252 return 0;
253 }
Denys Vlasenko2c876772018-01-10 11:04:09 +0100254 if ((size_t)n == len) {
Denys Vlasenko5afd63a2018-01-10 10:58:55 +0100255 G.out_part++;
Denys Vlasenko2c876772018-01-10 11:04:09 +0100256 return 0;
257 }
Denys Vlasenko875ce092019-05-14 17:46:18 +0200258 /* n is < len (and possibly is -1).
259 * Even if n >= 0, errno is usually set correctly.
260 * For example, if writing to block device and getting ENOSPC,
261 * full_write() first sees a short write, then tries to write
262 * the remainder and gets errno set to ENOSPC.
263 * It returns n > 0 (the amount which it did write).
264 */
265 bb_perror_msg("error writing '%s'", filename);
Denys Vlasenko5afd63a2018-01-10 10:58:55 +0100266 return 1;
Bernhard Reutner-Fischer2a47dea2007-04-04 14:01:23 +0000267}
268
Denis Vlasenko5dd27b12006-11-25 14:46:21 +0000269#if ENABLE_LFS
Gabor Heja4e5b07b2009-10-14 00:29:28 +0200270# define XATOU_SFX xatoull_sfx
Denis Vlasenko5dd27b12006-11-25 14:46:21 +0000271#else
Gabor Heja4e5b07b2009-10-14 00:29:28 +0200272# define XATOU_SFX xatoul_sfx
Denis Vlasenko5dd27b12006-11-25 14:46:21 +0000273#endif
274
Rafał Miłeckic30a5b12016-02-01 02:17:28 +0100275#if ENABLE_FEATURE_DD_IBS_OBS
276static int parse_comma_flags(char *val, const char *words, const char *error_in)
277{
278 int flags = 0;
279 while (1) {
280 int n;
281 char *arg;
282 /* find ',', replace them with NUL so we can use val for
283 * index_in_strings() without copying.
284 * We rely on val being non-null, else strchr would fault.
285 */
286 arg = strchr(val, ',');
287 if (arg)
288 *arg = '\0';
289 n = index_in_strings(words, val);
290 if (n < 0)
291 bb_error_msg_and_die(bb_msg_invalid_arg_to, val, error_in);
292 flags |= (1 << n);
293 if (!arg) /* no ',' left, so this was the last specifier */
294 break;
295 *arg = ','; /* to preserve ps listing */
296 val = arg + 1; /* skip this keyword and ',' */
297 }
298 return flags;
299}
300#endif
301
Denys Vlasenko2aaacc12020-12-14 20:27:57 +0100302static void *alloc_buf(size_t size)
303{
304 /* Important for "{i,o}flag=direct" - buffers must be page aligned */
305 if (size >= bb_getpagesize())
306 return xmmap_anon(size);
307 return xmalloc(size);
308}
309
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000310int dd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000311int dd_main(int argc UNUSED_PARAM, char **argv)
Eric Andersen3cf52d11999-10-12 22:26:06 +0000312{
Denis Vlasenko6ca409e2007-08-12 20:58:27 +0000313 static const char keywords[] ALIGN1 =
Ari Sundholmf22a8382015-02-07 01:41:22 +0100314 "bs\0""count\0""seek\0""skip\0""if\0""of\0"IF_FEATURE_DD_STATUS("status\0")
Bernhard Reutner-Fischer2a47dea2007-04-04 14:01:23 +0000315#if ENABLE_FEATURE_DD_IBS_OBS
Rostislav Skudnov3f6a9782018-10-15 10:26:15 +0000316 "ibs\0""obs\0""conv\0""iflag\0""oflag\0"
Bernhard Reutner-Fischer2a47dea2007-04-04 14:01:23 +0000317#endif
Denis Vlasenko990d0f62007-07-24 15:54:42 +0000318 ;
Denis Vlasenko7b6d9d62008-04-02 21:20:35 +0000319#if ENABLE_FEATURE_DD_IBS_OBS
320 static const char conv_words[] ALIGN1 =
Denys Vlasenkob9413162013-08-19 09:01:39 +0200321 "notrunc\0""sync\0""noerror\0""fsync\0""swab\0";
Rafał Miłeckic30a5b12016-02-01 02:17:28 +0100322 static const char iflag_words[] ALIGN1 =
Rafał Miłecki4eb46e12021-03-24 16:01:42 +0100323 "skip_bytes\0""count_bytes\0""fullblock\0""direct\0";
Rostislav Skudnov3f6a9782018-10-15 10:26:15 +0000324 static const char oflag_words[] ALIGN1 =
Denys Vlasenko2aaacc12020-12-14 20:27:57 +0100325 "seek_bytes\0append\0""direct\0";
Denis Vlasenko7b6d9d62008-04-02 21:20:35 +0000326#endif
Ari Sundholmf22a8382015-02-07 01:41:22 +0100327#if ENABLE_FEATURE_DD_STATUS
328 static const char status_words[] ALIGN1 =
329 "none\0""noxfer\0";
330#endif
Bernhard Reutner-Fischer99003b82007-04-10 19:30:50 +0000331 enum {
Denis Vlasenko7b6d9d62008-04-02 21:20:35 +0000332 OP_bs = 0,
Bernhard Reutner-Fischer99003b82007-04-10 19:30:50 +0000333 OP_count,
334 OP_seek,
335 OP_skip,
336 OP_if,
337 OP_of,
Ari Sundholmf22a8382015-02-07 01:41:22 +0100338 IF_FEATURE_DD_STATUS(OP_status,)
Bernhard Reutner-Fischere468ef22007-04-16 12:21:05 +0000339#if ENABLE_FEATURE_DD_IBS_OBS
Bernhard Reutner-Fischer99003b82007-04-10 19:30:50 +0000340 OP_ibs,
341 OP_obs,
342 OP_conv,
Rafał Miłeckic30a5b12016-02-01 02:17:28 +0100343 OP_iflag,
Rostislav Skudnov3f6a9782018-10-15 10:26:15 +0000344 OP_oflag,
Denis Vlasenko7b6d9d62008-04-02 21:20:35 +0000345 /* Must be in the same order as FLAG_XXX! */
346 OP_conv_notrunc = 0,
Bernhard Reutner-Fischer99003b82007-04-10 19:30:50 +0000347 OP_conv_sync,
Denis Vlasenkof6250a32007-04-19 20:16:14 +0000348 OP_conv_noerror,
Denis Vlasenko7b6d9d62008-04-02 21:20:35 +0000349 OP_conv_fsync,
Denys Vlasenkob9413162013-08-19 09:01:39 +0200350 OP_conv_swab,
Denis Vlasenko7b6d9d62008-04-02 21:20:35 +0000351 /* Unimplemented conv=XXX: */
352 //nocreat do not create the output file
353 //excl fail if the output file already exists
354 //fdatasync physically write output file data before finishing
Denis Vlasenko7b6d9d62008-04-02 21:20:35 +0000355 //lcase change upper case to lower case
356 //ucase change lower case to upper case
357 //block pad newline-terminated records with spaces to cbs-size
358 //unblock replace trailing spaces in cbs-size records with newline
359 //ascii from EBCDIC to ASCII
360 //ebcdic from ASCII to EBCDIC
361 //ibm from ASCII to alternate EBCDIC
Denys Vlasenkob9413162013-08-19 09:01:39 +0200362 /* Partially implemented: */
363 //swab swap every pair of input bytes: will abort on non-even reads
Rafał Miłeckic30a5b12016-02-01 02:17:28 +0100364 OP_iflag_skip_bytes,
Rafał Miłecki4eb46e12021-03-24 16:01:42 +0100365 OP_iflag_count_bytes,
Nicholas Clark77a66782018-01-25 19:00:19 +0100366 OP_iflag_fullblock,
Denys Vlasenko2aaacc12020-12-14 20:27:57 +0100367 OP_iflag_direct,
Rostislav Skudnov3f6a9782018-10-15 10:26:15 +0000368 OP_oflag_seek_bytes,
Denys Vlasenko2aaacc12020-12-14 20:27:57 +0100369 OP_oflag_direct,
Bernhard Reutner-Fischere468ef22007-04-16 12:21:05 +0000370#endif
Bernhard Reutner-Fischer99003b82007-04-10 19:30:50 +0000371 };
Denys Vlasenko5b9910f2013-08-20 02:50:49 +0200372 smallint exitcode = EXIT_FAILURE;
Denys Vlasenko4b1896c2013-08-19 09:00:08 +0200373 int i;
Denys Vlasenko4502bb12013-08-20 12:08:46 +0200374 size_t ibs = 512;
375 char *ibuf;
376#if ENABLE_FEATURE_DD_IBS_OBS
377 size_t obs = 512;
378 char *obuf;
379#else
380# define obs ibs
381# define obuf ibuf
382#endif
383 /* These are all zeroed at once! */
Denis Vlasenko75878702007-07-27 15:02:00 +0000384 struct {
Denys Vlasenko9ab5a8d2018-10-30 17:04:52 +0100385 IF_FEATURE_DD_IBS_OBS(size_t ocount;)
Denys Vlasenko5b9910f2013-08-20 02:50:49 +0200386 ssize_t prev_read_size; /* for detecting swab failure */
Denis Vlasenko75878702007-07-27 15:02:00 +0000387 off_t count;
388 off_t seek, skip;
389 const char *infile, *outfile;
Denis Vlasenko75878702007-07-27 15:02:00 +0000390 } Z;
Denys Vlasenko9ab5a8d2018-10-30 17:04:52 +0100391#define ocount (Z.ocount )
Denys Vlasenko5b9910f2013-08-20 02:50:49 +0200392#define prev_read_size (Z.prev_read_size)
Denis Vlasenko75878702007-07-27 15:02:00 +0000393#define count (Z.count )
394#define seek (Z.seek )
395#define skip (Z.skip )
396#define infile (Z.infile )
397#define outfile (Z.outfile)
Eric Andersenddea3682000-11-29 22:33:02 +0000398
Denis Vlasenko75878702007-07-27 15:02:00 +0000399 memset(&Z, 0, sizeof(Z));
400 INIT_G();
Denys Vlasenko8131eea2009-11-02 14:19:51 +0100401 //fflush_all(); - is this needed because of NOEXEC?
Denis Vlasenkof6250a32007-04-19 20:16:14 +0000402
Denys Vlasenko4b1896c2013-08-19 09:00:08 +0200403 for (i = 1; argv[i]; i++) {
Denis Vlasenko7b6d9d62008-04-02 21:20:35 +0000404 int what;
405 char *val;
Denys Vlasenko4b1896c2013-08-19 09:00:08 +0200406 char *arg = argv[i];
Denis Vlasenko3b8ff682006-10-31 15:55:56 +0000407
Denis Vlasenko7b6d9d62008-04-02 21:20:35 +0000408#if ENABLE_DESKTOP
409 /* "dd --". NB: coreutils 6.9 will complain if they see
410 * more than one of them. We wouldn't. */
411 if (arg[0] == '-' && arg[1] == '-' && arg[2] == '\0')
412 continue;
413#endif
414 val = strchr(arg, '=');
415 if (val == NULL)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000416 bb_show_usage();
Denis Vlasenko7b6d9d62008-04-02 21:20:35 +0000417 *val = '\0';
418 what = index_in_strings(keywords, arg);
419 if (what < 0)
Bernhard Reutner-Fischer2a47dea2007-04-04 14:01:23 +0000420 bb_show_usage();
Denis Vlasenko7b6d9d62008-04-02 21:20:35 +0000421 /* *val = '='; - to preserve ps listing? */
422 val++;
Bernhard Reutner-Fischere468ef22007-04-16 12:21:05 +0000423#if ENABLE_FEATURE_DD_IBS_OBS
Denis Vlasenko400d8bb2008-02-24 13:36:01 +0000424 if (what == OP_ibs) {
425 /* Must fit into positive ssize_t */
Ari Sundholm88930232015-03-04 18:46:48 +0200426 ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes);
Denis Vlasenko7b6d9d62008-04-02 21:20:35 +0000427 /*continue;*/
Denis Vlasenko400d8bb2008-02-24 13:36:01 +0000428 }
429 if (what == OP_obs) {
Ari Sundholm88930232015-03-04 18:46:48 +0200430 obs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes);
Denis Vlasenko7b6d9d62008-04-02 21:20:35 +0000431 /*continue;*/
Denis Vlasenko400d8bb2008-02-24 13:36:01 +0000432 }
433 if (what == OP_conv) {
Rafał Miłeckic30a5b12016-02-01 02:17:28 +0100434 G.flags |= parse_comma_flags(val, conv_words, "conv");
435 /*continue;*/
436 }
437 if (what == OP_iflag) {
438 G.flags |= parse_comma_flags(val, iflag_words, "iflag") << FLAG_IFLAG_SHIFT;
Denys Vlasenko4502bb12013-08-20 12:08:46 +0200439 /*continue;*/
Denis Vlasenko400d8bb2008-02-24 13:36:01 +0000440 }
Rostislav Skudnov3f6a9782018-10-15 10:26:15 +0000441 if (what == OP_oflag) {
442 G.flags |= parse_comma_flags(val, oflag_words, "oflag") << FLAG_OFLAG_SHIFT;
443 /*continue;*/
444 }
Bernhard Reutner-Fischere468ef22007-04-16 12:21:05 +0000445#endif
Bernhard Reutner-Fischer2a47dea2007-04-04 14:01:23 +0000446 if (what == OP_bs) {
Ari Sundholm88930232015-03-04 18:46:48 +0200447 ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes);
Denys Vlasenko4502bb12013-08-20 12:08:46 +0200448 obs = ibs;
Denis Vlasenko7b6d9d62008-04-02 21:20:35 +0000449 /*continue;*/
Bernhard Reutner-Fischer2a47dea2007-04-04 14:01:23 +0000450 }
451 /* These can be large: */
452 if (what == OP_count) {
Ari Sundholmf22a8382015-02-07 01:41:22 +0100453 G.flags |= FLAG_COUNT;
Ari Sundholm88930232015-03-04 18:46:48 +0200454 count = XATOU_SFX(val, cwbkMG_suffixes);
Denis Vlasenko7b6d9d62008-04-02 21:20:35 +0000455 /*continue;*/
Bernhard Reutner-Fischer2a47dea2007-04-04 14:01:23 +0000456 }
457 if (what == OP_seek) {
Ari Sundholm88930232015-03-04 18:46:48 +0200458 seek = XATOU_SFX(val, cwbkMG_suffixes);
Denis Vlasenko7b6d9d62008-04-02 21:20:35 +0000459 /*continue;*/
Bernhard Reutner-Fischer2a47dea2007-04-04 14:01:23 +0000460 }
Denis Vlasenkod1801a42007-04-19 20:08:19 +0000461 if (what == OP_skip) {
Ari Sundholm88930232015-03-04 18:46:48 +0200462 skip = XATOU_SFX(val, cwbkMG_suffixes);
Denis Vlasenko7b6d9d62008-04-02 21:20:35 +0000463 /*continue;*/
Bernhard Reutner-Fischer2a47dea2007-04-04 14:01:23 +0000464 }
465 if (what == OP_if) {
Denis Vlasenko7b6d9d62008-04-02 21:20:35 +0000466 infile = val;
467 /*continue;*/
Bernhard Reutner-Fischer2a47dea2007-04-04 14:01:23 +0000468 }
Denis Vlasenko7b6d9d62008-04-02 21:20:35 +0000469 if (what == OP_of) {
470 outfile = val;
471 /*continue;*/
472 }
Ari Sundholmf22a8382015-02-07 01:41:22 +0100473#if ENABLE_FEATURE_DD_STATUS
474 if (what == OP_status) {
475 int n;
476 n = index_in_strings(status_words, val);
477 if (n < 0)
Denys Vlasenko0f296a32015-10-14 13:21:01 +0200478 bb_error_msg_and_die(bb_msg_invalid_arg_to, val, "status");
Denys Vlasenkod5b98e22017-07-14 13:44:30 +0200479 G.flags |= FLAG_STATUS_NONE << n;
Ari Sundholmf22a8382015-02-07 01:41:22 +0100480 /*continue;*/
481 }
482#endif
Denys Vlasenko4b1896c2013-08-19 09:00:08 +0200483 } /* end of "for (argv[i])" */
Denis Vlasenko7b6d9d62008-04-02 21:20:35 +0000484
Denys Vlasenko2aaacc12020-12-14 20:27:57 +0100485 ibuf = alloc_buf(ibs);
Denys Vlasenko4502bb12013-08-20 12:08:46 +0200486 obuf = ibuf;
487#if ENABLE_FEATURE_DD_IBS_OBS
Denis Vlasenko3b8ff682006-10-31 15:55:56 +0000488 if (ibs != obs) {
Ari Sundholmf22a8382015-02-07 01:41:22 +0100489 G.flags |= FLAG_TWOBUFS;
Denys Vlasenko2aaacc12020-12-14 20:27:57 +0100490 obuf = alloc_buf(obs);
Denis Vlasenko3b8ff682006-10-31 15:55:56 +0000491 }
Denys Vlasenko4502bb12013-08-20 12:08:46 +0200492#endif
Gabor Heja4e5b07b2009-10-14 00:29:28 +0200493
494#if ENABLE_FEATURE_DD_SIGNAL_HANDLING
495 signal_SA_RESTART_empty_mask(SIGUSR1, dd_output_status);
496#endif
497#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
498 G.begin_time_us = monotonic_us();
499#endif
500
Denys Vlasenko4502bb12013-08-20 12:08:46 +0200501 if (infile) {
Denys Vlasenko2aaacc12020-12-14 20:27:57 +0100502 int iflag = O_RDONLY;
503#if ENABLE_FEATURE_DD_IBS_OBS
504 if (G.flags & FLAG_IDIRECT)
505 iflag |= O_DIRECT;
506#endif
507 xmove_fd(xopen(infile, iflag), ifd);
Denys Vlasenko4502bb12013-08-20 12:08:46 +0200508 } else {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000509 infile = bb_msg_standard_input;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000510 }
Denys Vlasenko4502bb12013-08-20 12:08:46 +0200511 if (outfile) {
Bernhard Reutner-Fischer2a47dea2007-04-04 14:01:23 +0000512 int oflag = O_WRONLY | O_CREAT;
Matt Kraaic9acf8c2001-01-17 00:21:05 +0000513
Ari Sundholmf22a8382015-02-07 01:41:22 +0100514 if (!seek && !(G.flags & FLAG_NOTRUNC))
Matt Kraaic9acf8c2001-01-17 00:21:05 +0000515 oflag |= O_TRUNC;
Rostislav Skudnovd712edc2019-02-06 11:57:15 +0000516 if (G.flags & FLAG_APPEND)
517 oflag |= O_APPEND;
Denys Vlasenko2aaacc12020-12-14 20:27:57 +0100518#if ENABLE_FEATURE_DD_IBS_OBS
519 if (G.flags & FLAG_ODIRECT)
520 oflag |= O_DIRECT;
521#endif
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000522 xmove_fd(xopen(outfile, oflag), ofd);
Matt Kraaic9acf8c2001-01-17 00:21:05 +0000523
Ari Sundholmf22a8382015-02-07 01:41:22 +0100524 if (seek && !(G.flags & FLAG_NOTRUNC)) {
Rostislav Skudnov3f6a9782018-10-15 10:26:15 +0000525 size_t blocksz = (G.flags & FLAG_SEEK_BYTES) ? 1 : obs;
526 if (ftruncate(ofd, seek * blocksz) < 0) {
Matt Kraaieb834782002-02-05 15:28:54 +0000527 struct stat st;
528
Denys Vlasenko6b9f1632010-01-28 02:24:24 +0100529 if (fstat(ofd, &st) < 0
530 || S_ISREG(st.st_mode)
531 || S_ISDIR(st.st_mode)
532 ) {
Bernhard Reutner-Fischer73561cc2006-08-28 23:31:54 +0000533 goto die_outfile;
Denys Vlasenko6b9f1632010-01-28 02:24:24 +0100534 }
Matt Kraaieb834782002-02-05 15:28:54 +0000535 }
Matt Kraaic9acf8c2001-01-17 00:21:05 +0000536 }
Matt Kraai24ac0172000-12-18 21:38:57 +0000537 } else {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000538 outfile = bb_msg_standard_output;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000539 }
Matt Kraai24ac0172000-12-18 21:38:57 +0000540 if (skip) {
Rafał Miłeckic30a5b12016-02-01 02:17:28 +0100541 size_t blocksz = (G.flags & FLAG_SKIP_BYTES) ? 1 : ibs;
542 if (lseek(ifd, skip * blocksz, SEEK_CUR) < 0) {
Denys Vlasenko1b57fe12013-08-20 12:45:05 +0200543 do {
Denys Vlasenko2aaacc12020-12-14 20:27:57 +0100544 ssize_t n = dd_read(ibuf, blocksz);
Rob Landley2686d3b2006-05-16 16:52:12 +0000545 if (n < 0)
Bernhard Reutner-Fischer2a47dea2007-04-04 14:01:23 +0000546 goto die_infile;
Rob Landley2686d3b2006-05-16 16:52:12 +0000547 if (n == 0)
548 break;
Denys Vlasenko1b57fe12013-08-20 12:45:05 +0200549 } while (--skip != 0);
Glenn L McGratheaed78a2002-11-28 11:05:28 +0000550 }
Matt Kraai24ac0172000-12-18 21:38:57 +0000551 }
Matt Kraai24ac0172000-12-18 21:38:57 +0000552 if (seek) {
Rostislav Skudnov3f6a9782018-10-15 10:26:15 +0000553 size_t blocksz = (G.flags & FLAG_SEEK_BYTES) ? 1 : obs;
554 if (lseek(ofd, seek * blocksz, SEEK_CUR) < 0)
Bernhard Reutner-Fischer73561cc2006-08-28 23:31:54 +0000555 goto die_outfile;
Matt Kraai24ac0172000-12-18 21:38:57 +0000556 }
Eric Andersenddea3682000-11-29 22:33:02 +0000557
Rafał Miłecki4eb46e12021-03-24 16:01:42 +0100558 while (1) {
559 ssize_t n = ibs;
560
561 if (G.flags & FLAG_COUNT) {
562 if (count == 0)
563 break;
564 if ((G.flags & FLAG_COUNT_BYTES) && count < ibs)
565 n = count;
566 }
567
568 n = dd_read(ibuf, n);
Bernhard Reutner-Fischer73561cc2006-08-28 23:31:54 +0000569 if (n == 0)
Rob Landley2686d3b2006-05-16 16:52:12 +0000570 break;
Eric Andersenef38b392002-04-27 01:31:43 +0000571 if (n < 0) {
Denys Vlasenkof00cfdf2009-09-18 20:49:36 +0200572 /* "Bad block" */
Ari Sundholmf22a8382015-02-07 01:41:22 +0100573 if (!(G.flags & FLAG_NOERROR))
Bernhard Reutner-Fischer2a47dea2007-04-04 14:01:23 +0000574 goto die_infile;
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000575 bb_simple_perror_msg(infile);
Denys Vlasenkof00cfdf2009-09-18 20:49:36 +0200576 /* GNU dd with conv=noerror skips over bad blocks */
Denys Vlasenko334fcc82009-08-05 23:16:27 +0200577 xlseek(ifd, ibs, SEEK_CUR);
Denys Vlasenkof00cfdf2009-09-18 20:49:36 +0200578 /* conv=noerror,sync writes NULs,
579 * conv=noerror just ignores input bad blocks */
580 n = 0;
Eric Andersenef38b392002-04-27 01:31:43 +0000581 }
Ari Sundholmf22a8382015-02-07 01:41:22 +0100582 if (G.flags & FLAG_SWAB) {
Denys Vlasenko0ff0b322013-08-20 12:49:28 +0200583 uint16_t *p16;
584 ssize_t n2;
Denys Vlasenko5b9910f2013-08-20 02:50:49 +0200585
586 /* Our code allows only last read to be odd-sized */
587 if (prev_read_size & 1)
588 bb_error_msg_and_die("can't swab %lu byte buffer",
589 (unsigned long)prev_read_size);
590 prev_read_size = n;
591
Denys Vlasenko90e9cfd2013-08-20 12:27:19 +0200592 /* If n is odd, last byte is not swapped:
Denys Vlasenko8395bd32013-08-19 10:30:55 +0200593 * echo -n "qwe" | dd conv=swab
Denys Vlasenkob9413162013-08-19 09:01:39 +0200594 * prints "wqe".
Denys Vlasenkob9413162013-08-19 09:01:39 +0200595 */
Denys Vlasenko5b9910f2013-08-20 02:50:49 +0200596 p16 = (void*) ibuf;
Denys Vlasenko0ff0b322013-08-20 12:49:28 +0200597 n2 = (n >> 1);
598 while (--n2 >= 0) {
Denys Vlasenkob9413162013-08-19 09:01:39 +0200599 *p16 = bswap_16(*p16);
600 p16++;
601 }
602 }
Rafał Miłecki4eb46e12021-03-24 16:01:42 +0100603 count -= (G.flags & FLAG_COUNT_BYTES) ? n : 1;
Bernhard Reutner-Fischer73561cc2006-08-28 23:31:54 +0000604 if ((size_t)n == ibs)
Bernhard Reutner-Fischer2a47dea2007-04-04 14:01:23 +0000605 G.in_full++;
Bernhard Reutner-Fischer73561cc2006-08-28 23:31:54 +0000606 else {
Bernhard Reutner-Fischer2a47dea2007-04-04 14:01:23 +0000607 G.in_part++;
Ari Sundholmf22a8382015-02-07 01:41:22 +0100608 if (G.flags & FLAG_SYNC) {
Denys Vlasenkof00cfdf2009-09-18 20:49:36 +0200609 memset(ibuf + n, 0, ibs - n);
Rob Landley2686d3b2006-05-16 16:52:12 +0000610 n = ibs;
611 }
Glenn L McGratheaed78a2002-11-28 11:05:28 +0000612 }
Denys Vlasenko9ab5a8d2018-10-30 17:04:52 +0100613#if ENABLE_FEATURE_DD_IBS_OBS
Ari Sundholmf22a8382015-02-07 01:41:22 +0100614 if (G.flags & FLAG_TWOBUFS) {
Rob Landley2686d3b2006-05-16 16:52:12 +0000615 char *tmp = ibuf;
616 while (n) {
Denys Vlasenko9ab5a8d2018-10-30 17:04:52 +0100617 size_t d = obs - ocount;
Denis Vlasenko77ad97f2008-05-13 02:27:31 +0000618 if (d > (size_t)n)
Bernhard Reutner-Fischer73561cc2006-08-28 23:31:54 +0000619 d = n;
Denys Vlasenko9ab5a8d2018-10-30 17:04:52 +0100620 memcpy(obuf + ocount, tmp, d);
Rob Landley2686d3b2006-05-16 16:52:12 +0000621 n -= d;
622 tmp += d;
Denys Vlasenko9ab5a8d2018-10-30 17:04:52 +0100623 ocount += d;
624 if (ocount == obs) {
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000625 if (write_and_stats(obuf, obs, obs, outfile))
Bernhard Reutner-Fischer2a47dea2007-04-04 14:01:23 +0000626 goto out_status;
Denys Vlasenko9ab5a8d2018-10-30 17:04:52 +0100627 ocount = 0;
Rob Landley2686d3b2006-05-16 16:52:12 +0000628 }
629 }
Denys Vlasenko9ab5a8d2018-10-30 17:04:52 +0100630 } else
631#endif
632 {
Denys Vlasenkof3114a32013-08-20 12:40:29 +0200633 if (write_and_stats(ibuf, n, obs, outfile))
634 goto out_status;
635 }
Rostislav Skudnovdba0dc12017-03-16 20:54:35 +0100636 }
Denis Vlasenko7b6d9d62008-04-02 21:20:35 +0000637
Rostislav Skudnovdba0dc12017-03-16 20:54:35 +0100638 if (G.flags & FLAG_FSYNC) {
639 if (fsync(ofd) < 0)
640 goto die_outfile;
Glenn L McGrathf0b073f2000-09-11 00:32:13 +0000641 }
Denis Vlasenko9213a9e2006-09-17 16:28:10 +0000642
Denys Vlasenko9ab5a8d2018-10-30 17:04:52 +0100643#if ENABLE_FEATURE_DD_IBS_OBS
644 if (ocount != 0) {
645 if (write_and_stats(obuf, ocount, obs, outfile))
Denys Vlasenkof3114a32013-08-20 12:40:29 +0200646 goto out_status;
Rob Landley2686d3b2006-05-16 16:52:12 +0000647 }
Denys Vlasenko9ab5a8d2018-10-30 17:04:52 +0100648#endif
Denis Vlasenko3b8ff682006-10-31 15:55:56 +0000649 if (close(ifd) < 0) {
Denis Vlasenko990d0f62007-07-24 15:54:42 +0000650 die_infile:
Denis Vlasenko0c97c9d2007-10-01 11:58:38 +0000651 bb_simple_perror_msg_and_die(infile);
Glenn L McGratheaed78a2002-11-28 11:05:28 +0000652 }
Matt Kraai3eeab3b2001-12-07 16:27:37 +0000653
Denis Vlasenko3b8ff682006-10-31 15:55:56 +0000654 if (close(ofd) < 0) {
Denis Vlasenko990d0f62007-07-24 15:54:42 +0000655 die_outfile:
Denis Vlasenko0c97c9d2007-10-01 11:58:38 +0000656 bb_simple_perror_msg_and_die(outfile);
Glenn L McGratheaed78a2002-11-28 11:05:28 +0000657 }
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000658
659 exitcode = EXIT_SUCCESS;
Denis Vlasenko990d0f62007-07-24 15:54:42 +0000660 out_status:
Ari Sundholmf22a8382015-02-07 01:41:22 +0100661 if (!ENABLE_FEATURE_DD_STATUS || !(G.flags & FLAG_STATUS_NONE))
662 dd_output_status(0);
Matt Kraai24ac0172000-12-18 21:38:57 +0000663
Denys Vlasenko2aaacc12020-12-14 20:27:57 +0100664#if 0 /* can't just free(), they can be mmap()ed */
Alexey Solovievf9221542011-03-16 10:39:46 +0300665 if (ENABLE_FEATURE_CLEAN_UP) {
666 free(obuf);
Ari Sundholmf22a8382015-02-07 01:41:22 +0100667 if (G.flags & FLAG_TWOBUFS)
Alexey Solovievf9221542011-03-16 10:39:46 +0300668 free(ibuf);
669 }
Denys Vlasenko2aaacc12020-12-14 20:27:57 +0100670#endif
Alexey Solovievf9221542011-03-16 10:39:46 +0300671
Denis Vlasenkoe2532ab2007-12-02 01:44:42 +0000672 return exitcode;
Eric Andersen3cf52d11999-10-12 22:26:06 +0000673}