From e854bea3b6837b22e9b6a69acbb28b4c8b470c81 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 19 Sep 2024 19:22:54 +0200 Subject: misc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- common.h | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'common.h') diff --git a/common.h b/common.h index 875375c..c1dbcfc 100644 --- a/common.h +++ b/common.h @@ -12,6 +12,9 @@ #define WHOLE_SECOND DECISECONDS(10) +#define WRAVG_STEPS 5 + + enum direction { FORWARDS = 0, BACKWARDS = 1 @@ -24,10 +27,32 @@ struct span { size_t blocksize; }; +struct status { + struct timespec now; + off_t shredded; + off_t bad_bytes; + uintmax_t bad_writes; + uintmax_t bad_sections; + uintmax_t pass_nr; + struct timespec last_success; + enum direction direction; + + int write_average_i; + struct timespec write_average_begin_times[WRAVG_STEPS]; + off_t write_average_amounts[WRAVG_STEPS]; +}; +#define STATUS_INIT {.pass_nr = 1, .last_success = {-1, 0}, .direction = FORWARDS} + + +/* deadshred.c */ +extern struct status status; +extern _Atomic volatile sig_atomic_t exiting; + /* io.c */ off_t filesize(int fd, const char *fname); + /* fmt.c */ const char *humansize1000(off_t s, char *buf); const char *humansize1024(off_t s, char *buf); @@ -38,14 +63,17 @@ off_t unhumansize(const char *s, char flag); const char *durationstr(const struct timespec *dur, char *buf, int second_decimals); const char *humanbytespersecond(double bytes_per_second, char *buf); + /* text.c */ int have_micro_symbol(void); + /* avg.c */ -void wravg_init(const struct timespec *start_time); -void wravg_update_write(ssize_t amount); -void wravg_update_time(const struct timespec *now); -const char *wravg_get(const struct timespec *now); +void wravg_init(const struct timespec *start_time, struct status *s); +void wravg_update_write(ssize_t amount, struct status *s); +void wravg_update_time(struct status *s); +const char *wravg_get(struct status *s); + /* rnd.c */ #if defined(__GNUC__) @@ -55,3 +83,9 @@ size_t max_blksize(void); void init_random(int fd, const char *fname); const char *get_random(size_t needed); void used_random(ssize_t amount); + + +/* sig.c */ +void setup_sighandler(void); +void block_sigs(void); +void unblock_sigs(void); -- cgit v1.2.3-70-g09d2