[BusyBox] DD fix
Gennady Feldman
gfeldman at mail.com
Mon Nov 27 20:51:47 UTC 2000
The attached patch fixes DD:
1. Uses blocksize when doing reading/writing. Was reading the whole
thing and then writing it out. Doesn't work for some devices.
2. Updated usage information (was missing conv=notrunc)
3. Added conv=sync feature.
G.F.
-------------- next part --------------
diff -u usage.orig usage.c
--- usage.orig Mon Nov 27 15:24:07 2000
+++ usage.c Mon Nov 27 15:25:47 2000
@@ -160,7 +160,7 @@
#if defined BB_DD
const char dd_usage[] =
- "dd [if=FILE] [of=FILE] [bs=N] [count=N] [skip=N] [seek=N]\n"
+ "dd [if=FILE] [of=FILE] [bs=N] [count=N] [skip=N] [seek=N] [conv=notrunc|sync]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nCopy a file, converting and formatting according to options\n\n"
"\tif=FILE\tread from FILE instead of stdin\n"
@@ -170,6 +170,7 @@
"\tskip=N\tskip N input blocks\n"
"\tseek=N\tskip N output blocks\n"
"\tconv=notrunc\t dont truncate of at end of write\n"
+ "\tconv=sync\t pad the last block with zeros until blocksize\n"
"\n"
"Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)\n"
#endif
diff -u dd.orig dd.c
--- dd.orig Mon Nov 27 15:24:12 2000
+++ dd.c Mon Nov 27 15:23:23 2000
@@ -49,6 +49,7 @@
int inCc = 0;
int outCc;
int trunc=TRUE;
+ int sync=FALSE;
long blockSize = 512;
uintmax_t skipBlocks = 0;
uintmax_t seekBlocks = 0;
@@ -56,7 +57,7 @@
uintmax_t inTotal = 0;
uintmax_t outTotal = 0;
uintmax_t totalSize;
- uintmax_t readSize;
+
unsigned char buf[BUFSIZ];
char *keyword = NULL;
@@ -98,6 +99,8 @@
keyword = (strchr(*argv, '=') + 1);
if (strcmp(keyword, "notrunc") == 0)
trunc=FALSE;
+ if (strcmp(keyword, "sync") == 0)
+ sync=TRUE;
} else {
goto usage;
}
@@ -137,13 +140,19 @@
lseek(inFd, (off_t) (skipBlocks * blockSize), SEEK_SET);
lseek(outFd, (off_t) (seekBlocks * blockSize), SEEK_SET);
totalSize=count*blockSize;
- while ((readSize = totalSize - inTotal) > 0) {
- if (readSize > BUFSIZ)
- readSize=BUFSIZ;
- inCc = fullRead(inFd, buf, readSize);
+ while (totalSize > inTotal) {
+ inCc = fullRead(inFd, buf, blockSize);
inTotal += inCc;
- if ((outCc = fullWrite(outFd, buf, inCc)) < 1)
+ if ( (sync==TRUE) && (inCc > 0 ))
+ while (inCc<blockSize)
+ buf[inCc++]='\0';
+
+ if ((outCc = fullWrite(outFd, buf, inCc)) < 1){
+ if (outCc < 0 ){
+ perror("Error during write");
+ }
break;
+ }
outTotal += outCc;
}
if (trunc == TRUE) {
More information about the busybox
mailing list