diff options
| author | Eric Andersen <andersen@codepoet.org> | 2000-11-29 22:33:02 +0000 |
|---|---|---|
| committer | Eric Andersen <andersen@codepoet.org> | 2000-11-29 22:33:02 +0000 |
| commit | ddea368dbe50bd9bb3ca129037aa4ca1e28515ed (patch) | |
| tree | 335749b651c96092554e01b9912d14680533bac2 | |
| parent | 618e8ed4c4bdb27875abdd725ddf342c5de19ac2 (diff) | |
| download | busybox-w32-ddea368dbe50bd9bb3ca129037aa4ca1e28515ed.tar.gz busybox-w32-ddea368dbe50bd9bb3ca129037aa4ca1e28515ed.tar.bz2 busybox-w32-ddea368dbe50bd9bb3ca129037aa4ca1e28515ed.zip | |
Apply rev #2 of dd fix from Gennady Feldman.
| -rw-r--r-- | applets/usage.c | 3 | ||||
| -rw-r--r-- | coreutils/dd.c | 28 | ||||
| -rw-r--r-- | dd.c | 28 | ||||
| -rw-r--r-- | usage.c | 3 |
4 files changed, 46 insertions, 16 deletions
diff --git a/applets/usage.c b/applets/usage.c index a919a58f7..bab6d21b3 100644 --- a/applets/usage.c +++ b/applets/usage.c | |||
| @@ -161,7 +161,7 @@ const char dc_usage[] = | |||
| 161 | 161 | ||
| 162 | #if defined BB_DD | 162 | #if defined BB_DD |
| 163 | const char dd_usage[] = | 163 | const char dd_usage[] = |
| 164 | "dd [if=FILE] [of=FILE] [bs=N] [count=N] [skip=N] [seek=N]\n" | 164 | "dd [if=FILE] [of=FILE] [bs=N] [count=N] [skip=N] [seek=N] [conv=notrunc|sync]\n" |
| 165 | #ifndef BB_FEATURE_TRIVIAL_HELP | 165 | #ifndef BB_FEATURE_TRIVIAL_HELP |
| 166 | "\nCopy a file, converting and formatting according to options\n\n" | 166 | "\nCopy a file, converting and formatting according to options\n\n" |
| 167 | "\tif=FILE\tread from FILE instead of stdin\n" | 167 | "\tif=FILE\tread from FILE instead of stdin\n" |
| @@ -171,6 +171,7 @@ const char dd_usage[] = | |||
| 171 | "\tskip=N\tskip N input blocks\n" | 171 | "\tskip=N\tskip N input blocks\n" |
| 172 | "\tseek=N\tskip N output blocks\n" | 172 | "\tseek=N\tskip N output blocks\n" |
| 173 | "\tconv=notrunc\t dont truncate of at end of write\n" | 173 | "\tconv=notrunc\t dont truncate of at end of write\n" |
| 174 | "\tconv=sync\t pad the last block with zeros until blocksize\n" | ||
| 174 | "\n" | 175 | "\n" |
| 175 | "Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)\n" | 176 | "Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)\n" |
| 176 | #endif | 177 | #endif |
diff --git a/coreutils/dd.c b/coreutils/dd.c index 6868a913e..2b77ea6a5 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
| @@ -49,14 +49,15 @@ extern int dd_main(int argc, char **argv) | |||
| 49 | int inCc = 0; | 49 | int inCc = 0; |
| 50 | int outCc; | 50 | int outCc; |
| 51 | int trunc=TRUE; | 51 | int trunc=TRUE; |
| 52 | long blockSize = 512; | 52 | int sync=FALSE; |
| 53 | long blockSize = 512,ibs; | ||
| 53 | uintmax_t skipBlocks = 0; | 54 | uintmax_t skipBlocks = 0; |
| 54 | uintmax_t seekBlocks = 0; | 55 | uintmax_t seekBlocks = 0; |
| 55 | uintmax_t count = (uintmax_t) - 1; | 56 | uintmax_t count = (uintmax_t) - 1; |
| 56 | uintmax_t inTotal = 0; | 57 | uintmax_t inTotal = 0; |
| 57 | uintmax_t outTotal = 0; | 58 | uintmax_t outTotal = 0; |
| 58 | uintmax_t totalSize; | 59 | uintmax_t totalSize; |
| 59 | uintmax_t readSize; | 60 | |
| 60 | unsigned char buf[BUFSIZ]; | 61 | unsigned char buf[BUFSIZ]; |
| 61 | char *keyword = NULL; | 62 | char *keyword = NULL; |
| 62 | 63 | ||
| @@ -98,6 +99,8 @@ extern int dd_main(int argc, char **argv) | |||
| 98 | keyword = (strchr(*argv, '=') + 1); | 99 | keyword = (strchr(*argv, '=') + 1); |
| 99 | if (strcmp(keyword, "notrunc") == 0) | 100 | if (strcmp(keyword, "notrunc") == 0) |
| 100 | trunc=FALSE; | 101 | trunc=FALSE; |
| 102 | if (strcmp(keyword, "sync") == 0) | ||
| 103 | sync=TRUE; | ||
| 101 | } else { | 104 | } else { |
| 102 | goto usage; | 105 | goto usage; |
| 103 | } | 106 | } |
| @@ -137,13 +140,24 @@ extern int dd_main(int argc, char **argv) | |||
| 137 | lseek(inFd, (off_t) (skipBlocks * blockSize), SEEK_SET); | 140 | lseek(inFd, (off_t) (skipBlocks * blockSize), SEEK_SET); |
| 138 | lseek(outFd, (off_t) (seekBlocks * blockSize), SEEK_SET); | 141 | lseek(outFd, (off_t) (seekBlocks * blockSize), SEEK_SET); |
| 139 | totalSize=count*blockSize; | 142 | totalSize=count*blockSize; |
| 140 | while ((readSize = totalSize - inTotal) > 0) { | 143 | |
| 141 | if (readSize > BUFSIZ) | 144 | ibs=blockSize; |
| 142 | readSize=BUFSIZ; | 145 | if (ibs > BUFSIZ) |
| 143 | inCc = fullRead(inFd, buf, readSize); | 146 | ibs=BUFSIZ; |
| 147 | |||
| 148 | while (totalSize > outTotal) { | ||
| 149 | inCc = fullRead(inFd, buf, ibs); | ||
| 144 | inTotal += inCc; | 150 | inTotal += inCc; |
| 145 | if ((outCc = fullWrite(outFd, buf, inCc)) < 1) | 151 | if ( (sync==TRUE) && (inCc>0) ) |
| 152 | while (inCc<ibs) | ||
| 153 | buf[inCc++]='\0'; | ||
| 154 | |||
| 155 | if ((outCc = fullWrite(outFd, buf, inCc)) < 1){ | ||
| 156 | if (outCc < 0 ){ | ||
| 157 | perror("Error during write"); | ||
| 158 | } | ||
| 146 | break; | 159 | break; |
| 160 | } | ||
| 147 | outTotal += outCc; | 161 | outTotal += outCc; |
| 148 | } | 162 | } |
| 149 | if (trunc == TRUE) { | 163 | if (trunc == TRUE) { |
| @@ -49,14 +49,15 @@ extern int dd_main(int argc, char **argv) | |||
| 49 | int inCc = 0; | 49 | int inCc = 0; |
| 50 | int outCc; | 50 | int outCc; |
| 51 | int trunc=TRUE; | 51 | int trunc=TRUE; |
| 52 | long blockSize = 512; | 52 | int sync=FALSE; |
| 53 | long blockSize = 512,ibs; | ||
| 53 | uintmax_t skipBlocks = 0; | 54 | uintmax_t skipBlocks = 0; |
| 54 | uintmax_t seekBlocks = 0; | 55 | uintmax_t seekBlocks = 0; |
| 55 | uintmax_t count = (uintmax_t) - 1; | 56 | uintmax_t count = (uintmax_t) - 1; |
| 56 | uintmax_t inTotal = 0; | 57 | uintmax_t inTotal = 0; |
| 57 | uintmax_t outTotal = 0; | 58 | uintmax_t outTotal = 0; |
| 58 | uintmax_t totalSize; | 59 | uintmax_t totalSize; |
| 59 | uintmax_t readSize; | 60 | |
| 60 | unsigned char buf[BUFSIZ]; | 61 | unsigned char buf[BUFSIZ]; |
| 61 | char *keyword = NULL; | 62 | char *keyword = NULL; |
| 62 | 63 | ||
| @@ -98,6 +99,8 @@ extern int dd_main(int argc, char **argv) | |||
| 98 | keyword = (strchr(*argv, '=') + 1); | 99 | keyword = (strchr(*argv, '=') + 1); |
| 99 | if (strcmp(keyword, "notrunc") == 0) | 100 | if (strcmp(keyword, "notrunc") == 0) |
| 100 | trunc=FALSE; | 101 | trunc=FALSE; |
| 102 | if (strcmp(keyword, "sync") == 0) | ||
| 103 | sync=TRUE; | ||
| 101 | } else { | 104 | } else { |
| 102 | goto usage; | 105 | goto usage; |
| 103 | } | 106 | } |
| @@ -137,13 +140,24 @@ extern int dd_main(int argc, char **argv) | |||
| 137 | lseek(inFd, (off_t) (skipBlocks * blockSize), SEEK_SET); | 140 | lseek(inFd, (off_t) (skipBlocks * blockSize), SEEK_SET); |
| 138 | lseek(outFd, (off_t) (seekBlocks * blockSize), SEEK_SET); | 141 | lseek(outFd, (off_t) (seekBlocks * blockSize), SEEK_SET); |
| 139 | totalSize=count*blockSize; | 142 | totalSize=count*blockSize; |
| 140 | while ((readSize = totalSize - inTotal) > 0) { | 143 | |
| 141 | if (readSize > BUFSIZ) | 144 | ibs=blockSize; |
| 142 | readSize=BUFSIZ; | 145 | if (ibs > BUFSIZ) |
| 143 | inCc = fullRead(inFd, buf, readSize); | 146 | ibs=BUFSIZ; |
| 147 | |||
| 148 | while (totalSize > outTotal) { | ||
| 149 | inCc = fullRead(inFd, buf, ibs); | ||
| 144 | inTotal += inCc; | 150 | inTotal += inCc; |
| 145 | if ((outCc = fullWrite(outFd, buf, inCc)) < 1) | 151 | if ( (sync==TRUE) && (inCc>0) ) |
| 152 | while (inCc<ibs) | ||
| 153 | buf[inCc++]='\0'; | ||
| 154 | |||
| 155 | if ((outCc = fullWrite(outFd, buf, inCc)) < 1){ | ||
| 156 | if (outCc < 0 ){ | ||
| 157 | perror("Error during write"); | ||
| 158 | } | ||
| 146 | break; | 159 | break; |
| 160 | } | ||
| 147 | outTotal += outCc; | 161 | outTotal += outCc; |
| 148 | } | 162 | } |
| 149 | if (trunc == TRUE) { | 163 | if (trunc == TRUE) { |
| @@ -161,7 +161,7 @@ const char dc_usage[] = | |||
| 161 | 161 | ||
| 162 | #if defined BB_DD | 162 | #if defined BB_DD |
| 163 | const char dd_usage[] = | 163 | const char dd_usage[] = |
| 164 | "dd [if=FILE] [of=FILE] [bs=N] [count=N] [skip=N] [seek=N]\n" | 164 | "dd [if=FILE] [of=FILE] [bs=N] [count=N] [skip=N] [seek=N] [conv=notrunc|sync]\n" |
| 165 | #ifndef BB_FEATURE_TRIVIAL_HELP | 165 | #ifndef BB_FEATURE_TRIVIAL_HELP |
| 166 | "\nCopy a file, converting and formatting according to options\n\n" | 166 | "\nCopy a file, converting and formatting according to options\n\n" |
| 167 | "\tif=FILE\tread from FILE instead of stdin\n" | 167 | "\tif=FILE\tread from FILE instead of stdin\n" |
| @@ -171,6 +171,7 @@ const char dd_usage[] = | |||
| 171 | "\tskip=N\tskip N input blocks\n" | 171 | "\tskip=N\tskip N input blocks\n" |
| 172 | "\tseek=N\tskip N output blocks\n" | 172 | "\tseek=N\tskip N output blocks\n" |
| 173 | "\tconv=notrunc\t dont truncate of at end of write\n" | 173 | "\tconv=notrunc\t dont truncate of at end of write\n" |
| 174 | "\tconv=sync\t pad the last block with zeros until blocksize\n" | ||
| 174 | "\n" | 175 | "\n" |
| 175 | "Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)\n" | 176 | "Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)\n" |
| 176 | #endif | 177 | #endif |
