mirror of https://github.com/vitalif/e2fsprogs
e2image: write progress information to stderr
This allows "e2image -rp /dev/sdc1 - | bzip2 > sdc1.img.bz2" to work correctly, so the progress information doesn't corrupt the image being sent to stdout. Also add a diagnostic indicating that the -p option is currently only implemented for raw mode. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>debian-1.42.9
parent
212c994883
commit
c8ee0d60fd
|
@ -169,7 +169,8 @@ static void generic_write(int fd, void *buf, int blocksize, blk64_t block)
|
|||
}
|
||||
if (nop_flag) {
|
||||
printf(_("Writing block %llu\n"), (unsigned long long) block);
|
||||
seek_relative(fd, blocksize);
|
||||
if (fd != 1)
|
||||
seek_relative(fd, blocksize);
|
||||
return;
|
||||
}
|
||||
count = write(fd, buf, blocksize);
|
||||
|
@ -546,7 +547,7 @@ static void sigint_handler(int unused EXT2FS_ATTR((unused)))
|
|||
|
||||
static int print_progress(blk64_t num, blk64_t total)
|
||||
{
|
||||
return printf(_("%llu / %llu blocks (%d%%)"), num, total,
|
||||
return fprintf(stderr, _("%llu / %llu blocks (%d%%)"), num, total,
|
||||
calc_percent(num, total));
|
||||
}
|
||||
|
||||
|
@ -575,9 +576,9 @@ static void output_meta_data_blocks(ext2_filsys fs, int fd, int flags)
|
|||
exit(1);
|
||||
}
|
||||
if (show_progress) {
|
||||
printf(_("Copying "));
|
||||
fprintf(stderr, _("Copying "));
|
||||
bscount = print_progress(total_written, meta_blocks_count);
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
last_update = time(NULL);
|
||||
start_time = time(NULL);
|
||||
}
|
||||
|
@ -608,14 +609,15 @@ more_blocks:
|
|||
kill (getpid(), SIGINT);
|
||||
}
|
||||
if (show_progress)
|
||||
printf ("\r");
|
||||
printf(_("Stopping now will destroy the filesystem, "
|
||||
fputc('\r', stderr);
|
||||
fprintf(stderr,
|
||||
_("Stopping now will destroy the filesystem, "
|
||||
"interrupt again if you are sure\n"));
|
||||
if (show_progress) {
|
||||
printf(_("Copying "));
|
||||
fprintf(stderr, _("Copying "));
|
||||
bscount = print_progress(total_written,
|
||||
meta_blocks_count);
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
got_sigint = 0;
|
||||
|
@ -624,7 +626,7 @@ more_blocks:
|
|||
time_t duration;
|
||||
last_update = time(NULL);
|
||||
while (bscount--)
|
||||
printf("\b");
|
||||
fputc('\b', stderr);
|
||||
bscount = print_progress(total_written,
|
||||
meta_blocks_count);
|
||||
duration = time(NULL) - start_time;
|
||||
|
@ -633,12 +635,13 @@ more_blocks:
|
|||
total_written) - duration;
|
||||
char buff[30];
|
||||
strftime(buff, 30, "%T", gmtime(&est));
|
||||
bscount += printf(_(" %s remaining at %.2f MB/s"),
|
||||
buff, calc_rate(total_written,
|
||||
fs->blocksize,
|
||||
duration));
|
||||
bscount += fprintf(stderr,
|
||||
_(" %s remaining at %.2f MB/s"),
|
||||
buff, calc_rate(total_written,
|
||||
fs->blocksize,
|
||||
duration));
|
||||
}
|
||||
fflush (stdout);
|
||||
fflush (stderr);
|
||||
}
|
||||
if ((blk >= fs->super->s_first_data_block) &&
|
||||
ext2fs_test_block_bitmap2(meta_block_map, blk)) {
|
||||
|
@ -665,7 +668,9 @@ more_blocks:
|
|||
} else {
|
||||
sparse_write:
|
||||
if (fd == 1) {
|
||||
generic_write(fd, zero_buf, fs->blocksize, blk);
|
||||
if (!nop_flag)
|
||||
generic_write(fd, zero_buf,
|
||||
fs->blocksize, blk);
|
||||
continue;
|
||||
}
|
||||
sparse += fs->blocksize;
|
||||
|
@ -696,10 +701,10 @@ more_blocks:
|
|||
time_t duration = time(NULL) - start_time;
|
||||
char buff[30];
|
||||
while (bscount--)
|
||||
printf("\b");
|
||||
fputc('\b', stderr);
|
||||
strftime(buff, 30, "%T", gmtime(&duration));
|
||||
printf(_("\b\b\b\b\b\b\b\bCopied %llu / %llu blocks (%llu%%) "
|
||||
"in %s at %.2f MB/s \n"),
|
||||
fprintf(stderr, _("\b\b\b\b\b\b\b\bCopied %llu / %llu "
|
||||
"blocks (%llu%%) in %s at %.2f MB/s \n"),
|
||||
total_written, meta_blocks_count,
|
||||
calc_percent(total_written, meta_blocks_count), buff,
|
||||
calc_rate(total_written, fs->blocksize, duration));
|
||||
|
@ -1630,7 +1635,11 @@ skip_device:
|
|||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (show_progress && (img_type != E2IMAGE_RAW)) {
|
||||
fprintf(stderr, _("The -p option only supported "
|
||||
"in raw mode\n"));
|
||||
exit(1);
|
||||
}
|
||||
if (img_type)
|
||||
write_raw_image_file(fs, fd, img_type, flags);
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue