mirror of
https://git.busybox.net/busybox.git
synced 2024-11-27 15:43:26 +08:00
Apply rev #2 of dd fix from Gennady Feldman.
This commit is contained in:
parent
618e8ed4c4
commit
ddea368dbe
@ -161,7 +161,7 @@ const char dc_usage[] =
|
|||||||
|
|
||||||
#if defined BB_DD
|
#if defined BB_DD
|
||||||
const char dd_usage[] =
|
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
|
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||||
"\nCopy a file, converting and formatting according to options\n\n"
|
"\nCopy a file, converting and formatting according to options\n\n"
|
||||||
"\tif=FILE\tread from FILE instead of stdin\n"
|
"\tif=FILE\tread from FILE instead of stdin\n"
|
||||||
@ -171,6 +171,7 @@ const char dd_usage[] =
|
|||||||
"\tskip=N\tskip N input blocks\n"
|
"\tskip=N\tskip N input blocks\n"
|
||||||
"\tseek=N\tskip N output blocks\n"
|
"\tseek=N\tskip N output blocks\n"
|
||||||
"\tconv=notrunc\t dont truncate of at end of write\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"
|
"\n"
|
||||||
"Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)\n"
|
"Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)\n"
|
||||||
#endif
|
#endif
|
||||||
|
@ -49,14 +49,15 @@ extern int dd_main(int argc, char **argv)
|
|||||||
int inCc = 0;
|
int inCc = 0;
|
||||||
int outCc;
|
int outCc;
|
||||||
int trunc=TRUE;
|
int trunc=TRUE;
|
||||||
long blockSize = 512;
|
int sync=FALSE;
|
||||||
|
long blockSize = 512,ibs;
|
||||||
uintmax_t skipBlocks = 0;
|
uintmax_t skipBlocks = 0;
|
||||||
uintmax_t seekBlocks = 0;
|
uintmax_t seekBlocks = 0;
|
||||||
uintmax_t count = (uintmax_t) - 1;
|
uintmax_t count = (uintmax_t) - 1;
|
||||||
uintmax_t inTotal = 0;
|
uintmax_t inTotal = 0;
|
||||||
uintmax_t outTotal = 0;
|
uintmax_t outTotal = 0;
|
||||||
uintmax_t totalSize;
|
uintmax_t totalSize;
|
||||||
uintmax_t readSize;
|
|
||||||
unsigned char buf[BUFSIZ];
|
unsigned char buf[BUFSIZ];
|
||||||
char *keyword = NULL;
|
char *keyword = NULL;
|
||||||
|
|
||||||
@ -98,6 +99,8 @@ extern int dd_main(int argc, char **argv)
|
|||||||
keyword = (strchr(*argv, '=') + 1);
|
keyword = (strchr(*argv, '=') + 1);
|
||||||
if (strcmp(keyword, "notrunc") == 0)
|
if (strcmp(keyword, "notrunc") == 0)
|
||||||
trunc=FALSE;
|
trunc=FALSE;
|
||||||
|
if (strcmp(keyword, "sync") == 0)
|
||||||
|
sync=TRUE;
|
||||||
} else {
|
} else {
|
||||||
goto usage;
|
goto usage;
|
||||||
}
|
}
|
||||||
@ -137,13 +140,24 @@ extern int dd_main(int argc, char **argv)
|
|||||||
lseek(inFd, (off_t) (skipBlocks * blockSize), SEEK_SET);
|
lseek(inFd, (off_t) (skipBlocks * blockSize), SEEK_SET);
|
||||||
lseek(outFd, (off_t) (seekBlocks * blockSize), SEEK_SET);
|
lseek(outFd, (off_t) (seekBlocks * blockSize), SEEK_SET);
|
||||||
totalSize=count*blockSize;
|
totalSize=count*blockSize;
|
||||||
while ((readSize = totalSize - inTotal) > 0) {
|
|
||||||
if (readSize > BUFSIZ)
|
ibs=blockSize;
|
||||||
readSize=BUFSIZ;
|
if (ibs > BUFSIZ)
|
||||||
inCc = fullRead(inFd, buf, readSize);
|
ibs=BUFSIZ;
|
||||||
|
|
||||||
|
while (totalSize > outTotal) {
|
||||||
|
inCc = fullRead(inFd, buf, ibs);
|
||||||
inTotal += inCc;
|
inTotal += inCc;
|
||||||
if ((outCc = fullWrite(outFd, buf, inCc)) < 1)
|
if ( (sync==TRUE) && (inCc>0) )
|
||||||
|
while (inCc<ibs)
|
||||||
|
buf[inCc++]='\0';
|
||||||
|
|
||||||
|
if ((outCc = fullWrite(outFd, buf, inCc)) < 1){
|
||||||
|
if (outCc < 0 ){
|
||||||
|
perror("Error during write");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
outTotal += outCc;
|
outTotal += outCc;
|
||||||
}
|
}
|
||||||
if (trunc == TRUE) {
|
if (trunc == TRUE) {
|
||||||
|
28
dd.c
28
dd.c
@ -49,14 +49,15 @@ extern int dd_main(int argc, char **argv)
|
|||||||
int inCc = 0;
|
int inCc = 0;
|
||||||
int outCc;
|
int outCc;
|
||||||
int trunc=TRUE;
|
int trunc=TRUE;
|
||||||
long blockSize = 512;
|
int sync=FALSE;
|
||||||
|
long blockSize = 512,ibs;
|
||||||
uintmax_t skipBlocks = 0;
|
uintmax_t skipBlocks = 0;
|
||||||
uintmax_t seekBlocks = 0;
|
uintmax_t seekBlocks = 0;
|
||||||
uintmax_t count = (uintmax_t) - 1;
|
uintmax_t count = (uintmax_t) - 1;
|
||||||
uintmax_t inTotal = 0;
|
uintmax_t inTotal = 0;
|
||||||
uintmax_t outTotal = 0;
|
uintmax_t outTotal = 0;
|
||||||
uintmax_t totalSize;
|
uintmax_t totalSize;
|
||||||
uintmax_t readSize;
|
|
||||||
unsigned char buf[BUFSIZ];
|
unsigned char buf[BUFSIZ];
|
||||||
char *keyword = NULL;
|
char *keyword = NULL;
|
||||||
|
|
||||||
@ -98,6 +99,8 @@ extern int dd_main(int argc, char **argv)
|
|||||||
keyword = (strchr(*argv, '=') + 1);
|
keyword = (strchr(*argv, '=') + 1);
|
||||||
if (strcmp(keyword, "notrunc") == 0)
|
if (strcmp(keyword, "notrunc") == 0)
|
||||||
trunc=FALSE;
|
trunc=FALSE;
|
||||||
|
if (strcmp(keyword, "sync") == 0)
|
||||||
|
sync=TRUE;
|
||||||
} else {
|
} else {
|
||||||
goto usage;
|
goto usage;
|
||||||
}
|
}
|
||||||
@ -137,13 +140,24 @@ extern int dd_main(int argc, char **argv)
|
|||||||
lseek(inFd, (off_t) (skipBlocks * blockSize), SEEK_SET);
|
lseek(inFd, (off_t) (skipBlocks * blockSize), SEEK_SET);
|
||||||
lseek(outFd, (off_t) (seekBlocks * blockSize), SEEK_SET);
|
lseek(outFd, (off_t) (seekBlocks * blockSize), SEEK_SET);
|
||||||
totalSize=count*blockSize;
|
totalSize=count*blockSize;
|
||||||
while ((readSize = totalSize - inTotal) > 0) {
|
|
||||||
if (readSize > BUFSIZ)
|
ibs=blockSize;
|
||||||
readSize=BUFSIZ;
|
if (ibs > BUFSIZ)
|
||||||
inCc = fullRead(inFd, buf, readSize);
|
ibs=BUFSIZ;
|
||||||
|
|
||||||
|
while (totalSize > outTotal) {
|
||||||
|
inCc = fullRead(inFd, buf, ibs);
|
||||||
inTotal += inCc;
|
inTotal += inCc;
|
||||||
if ((outCc = fullWrite(outFd, buf, inCc)) < 1)
|
if ( (sync==TRUE) && (inCc>0) )
|
||||||
|
while (inCc<ibs)
|
||||||
|
buf[inCc++]='\0';
|
||||||
|
|
||||||
|
if ((outCc = fullWrite(outFd, buf, inCc)) < 1){
|
||||||
|
if (outCc < 0 ){
|
||||||
|
perror("Error during write");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
outTotal += outCc;
|
outTotal += outCc;
|
||||||
}
|
}
|
||||||
if (trunc == TRUE) {
|
if (trunc == TRUE) {
|
||||||
|
3
usage.c
3
usage.c
@ -161,7 +161,7 @@ const char dc_usage[] =
|
|||||||
|
|
||||||
#if defined BB_DD
|
#if defined BB_DD
|
||||||
const char dd_usage[] =
|
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
|
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||||
"\nCopy a file, converting and formatting according to options\n\n"
|
"\nCopy a file, converting and formatting according to options\n\n"
|
||||||
"\tif=FILE\tread from FILE instead of stdin\n"
|
"\tif=FILE\tread from FILE instead of stdin\n"
|
||||||
@ -171,6 +171,7 @@ const char dd_usage[] =
|
|||||||
"\tskip=N\tskip N input blocks\n"
|
"\tskip=N\tskip N input blocks\n"
|
||||||
"\tseek=N\tskip N output blocks\n"
|
"\tseek=N\tskip N output blocks\n"
|
||||||
"\tconv=notrunc\t dont truncate of at end of write\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"
|
"\n"
|
||||||
"Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)\n"
|
"Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)\n"
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user