flashcp: pad output to BUFSIZE. Hopefully closes 5882
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
bf99807657
commit
243e733001
@ -16,6 +16,7 @@
|
|||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
#include <mtd/mtd-user.h>
|
#include <mtd/mtd-user.h>
|
||||||
|
|
||||||
|
/* If 1, simulates "flashing" by writing to existing regular file */
|
||||||
#define MTD_DEBUG 0
|
#define MTD_DEBUG 0
|
||||||
|
|
||||||
#define OPT_v (1 << 0)
|
#define OPT_v (1 << 0)
|
||||||
@ -32,7 +33,7 @@ static void progress(int mode, uoff_t count, uoff_t total)
|
|||||||
if (total)
|
if (total)
|
||||||
percent = (unsigned) (percent / total);
|
percent = (unsigned) (percent / total);
|
||||||
printf("\r%s: %"OFF_FMT"u/%"OFF_FMT"u (%u%%) ",
|
printf("\r%s: %"OFF_FMT"u/%"OFF_FMT"u (%u%%) ",
|
||||||
(mode == 0) ? "Erasing block" : ((mode == 1) ? "Writing kb" : "Verifying kb"),
|
(mode == -1) ? "Erasing block" : ((mode == 0) ? "Writing kb" : "Verifying kb"),
|
||||||
count, total, (unsigned)percent);
|
count, total, (unsigned)percent);
|
||||||
fflush_all();
|
fflush_all();
|
||||||
}
|
}
|
||||||
@ -97,8 +98,7 @@ int flashcp_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
e.start = 0;
|
e.start = 0;
|
||||||
for (i = 1; i <= erase_count; i++) {
|
for (i = 1; i <= erase_count; i++) {
|
||||||
progress(0, i, erase_count);
|
progress(-1, i, erase_count);
|
||||||
errno = 0;
|
|
||||||
#if !MTD_DEBUG
|
#if !MTD_DEBUG
|
||||||
if (ioctl(fd_d, MEMERASE, &e) < 0) {
|
if (ioctl(fd_d, MEMERASE, &e) < 0) {
|
||||||
bb_perror_msg_and_die("erase error at 0x%llx on %s",
|
bb_perror_msg_and_die("erase error at 0x%llx on %s",
|
||||||
@ -113,7 +113,7 @@ int flashcp_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
|
|
||||||
/* doing this outer loop gives significantly smaller code
|
/* doing this outer loop gives significantly smaller code
|
||||||
* than doing two separate loops for writing and verifying */
|
* than doing two separate loops for writing and verifying */
|
||||||
for (i = 1; i <= 2; i++) {
|
for (i = 0; i <= 1; i++) {
|
||||||
uoff_t done;
|
uoff_t done;
|
||||||
unsigned count;
|
unsigned count;
|
||||||
|
|
||||||
@ -122,25 +122,29 @@ int flashcp_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
done = 0;
|
done = 0;
|
||||||
count = BUFSIZE;
|
count = BUFSIZE;
|
||||||
while (1) {
|
while (1) {
|
||||||
uoff_t rem = statb.st_size - done;
|
uoff_t rem;
|
||||||
|
|
||||||
|
progress(i, done / 1024, (uoff_t)statb.st_size / 1024);
|
||||||
|
rem = statb.st_size - done;
|
||||||
if (rem == 0)
|
if (rem == 0)
|
||||||
break;
|
break;
|
||||||
if (rem < BUFSIZE)
|
if (rem < BUFSIZE)
|
||||||
count = rem;
|
count = rem;
|
||||||
progress(i, done / 1024, (uoff_t)statb.st_size / 1024);
|
|
||||||
xread(fd_f, buf, count);
|
xread(fd_f, buf, count);
|
||||||
if (i == 1) {
|
if (i == 0) {
|
||||||
int ret;
|
int ret;
|
||||||
|
if (count < BUFSIZE)
|
||||||
|
memset((char*)buf + count, 0, BUFSIZE - count);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
ret = full_write(fd_d, buf, count);
|
ret = full_write(fd_d, buf, BUFSIZE);
|
||||||
if (ret != count) {
|
if (ret != BUFSIZE) {
|
||||||
bb_perror_msg_and_die("write error at 0x%"OFF_FMT"x on %s, "
|
bb_perror_msg_and_die("write error at 0x%"OFF_FMT"x on %s, "
|
||||||
"write returned %d",
|
"write returned %d",
|
||||||
done, devicename, ret);
|
done, devicename, ret);
|
||||||
}
|
}
|
||||||
} else { /* i == 2 */
|
} else { /* i == 1 */
|
||||||
xread(fd_d, buf2, count);
|
xread(fd_d, buf2, count);
|
||||||
if (memcmp(buf, buf2, count)) {
|
if (memcmp(buf, buf2, count) != 0) {
|
||||||
bb_error_msg_and_die("verification mismatch at 0x%"OFF_FMT"x", done);
|
bb_error_msg_and_die("verification mismatch at 0x%"OFF_FMT"x", done);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user