diff options
author | Mattias Andrée <maandree@kth.se> | 2024-09-17 19:46:11 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2024-09-17 19:46:11 +0200 |
commit | d7c65eea85590f0c5ba7f78e912529f66764cbcc (patch) | |
tree | c778c24a627fc8a47709ba47c039adaa27ca2c66 | |
parent | Use rand(3) when stdin is a TTY (diff) | |
download | deadshred-d7c65eea85590f0c5ba7f78e912529f66764cbcc.tar.gz deadshred-d7c65eea85590f0c5ba7f78e912529f66764cbcc.tar.bz2 deadshred-d7c65eea85590f0c5ba7f78e912529f66764cbcc.tar.xz |
Print exact byte count
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r-- | TODO | 1 | ||||
-rw-r--r-- | deadshred.c | 12 |
2 files changed, 9 insertions, 4 deletions
@@ -2,6 +2,5 @@ Add `-n iterations` Add shred map for continuing later (print to stdout on SIGTERM) Enhance progress printout with: - exact bytes count bad sections (count, bytes) shredded bytes per seconds diff --git a/deadshred.c b/deadshred.c index 5f8f36b..84a5184 100644 --- a/deadshred.c +++ b/deadshred.c @@ -152,10 +152,11 @@ print_progress(int done) char subbuf2[256]; sprintf(i == 0 ? buf1 : buf2, - "%.2lf %% (%s, %s) of %s (%s) shredded\033[K\n%s", - 100. * (double)shredded / (double)total_size, + "%ji bytes (%s, %s, %.2lf %%) of %s (%s) shredded\033[K\n%s", + (intmax_t)shredded, humansize1000(shredded, subbuf1), humansize1024(shredded, subbuf2), + 100. * (double)shredded / (double)total_size, total_size_1000, total_size_1024, done ? "" : "\033[A"); @@ -174,9 +175,13 @@ shredspan(int fd, const struct span *span, const char *fname) { off_t off; ssize_t r; + int update_progress_delay = 0; for (off = span->start; off < span->end;) { - print_progress(0); + if (!update_progress_delay--) { + update_progress_delay = 1000; /* TOOD use half a second instead */ + print_progress(0); + } if (lseek(fd, off, SEEK_SET) < 0) eprintf("lseek %s %ji SEEK_SET\n", fname, (intmax_t)off); ensure_random(span->blocksize); @@ -184,6 +189,7 @@ shredspan(int fd, const struct span *span, const char *fname) if (r < 0) { if (errno != EINTR) off = add_span(off, span->end, span->blocksize == 1U ? 1U : span->blocksize); + update_progress_delay = 0; continue; } off += (off_t)r; |