From 472f506817bb1af2fceb039ba148d15723944562 Mon Sep 17 00:00:00 2001 From: Ethan Yonker Date: Thu, 25 Feb 2016 13:47:30 -0600 Subject: Improve progress bar handling for backup / restore / image flash The progress bar will now be updated during image backups, restores and during image flashing (except for sparse images which will require significant changes to libsparse, and except for mtd nand using flash_utils). The progress bar will now be updated mid-file for file systems (tar) so the user will see changes even during large file backup / restore. Add a new progress tracking class to simplify handling of progress bar updates. The class will only update the progress bar 5 times a second to reduce the CPU load from updating the GUI frequently which does affect backup times. Change-Id: Iff382faef3df1f86604af336c1a8ce8993cd12c5 --- tarWrite.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'tarWrite.c') diff --git a/tarWrite.c b/tarWrite.c index 98fa14cad..98461452a 100644 --- a/tarWrite.c +++ b/tarWrite.c @@ -28,6 +28,8 @@ unsigned char *write_buffer; unsigned buffer_size = 4096; unsigned buffer_loc = 0; int buffer_status = 0; +int prog_pipe = -1; +const unsigned long long progress_size = (unsigned long long)(T_BLOCKSIZE); void reinit_libtar_buffer(void) { flush = 0; @@ -36,18 +38,20 @@ void reinit_libtar_buffer(void) { buffer_status = 1; } -void init_libtar_buffer(unsigned new_buff_size) { +void init_libtar_buffer(unsigned new_buff_size, int pipe_fd) { if (new_buff_size != 0) buffer_size = new_buff_size; reinit_libtar_buffer(); write_buffer = (unsigned char*) malloc(sizeof(char *) * buffer_size); + prog_pipe = pipe_fd; } void free_libtar_buffer(void) { if (buffer_status > 0) free(write_buffer); buffer_status = 0; + prog_pipe = -1; } ssize_t write_libtar_buffer(int fd, const void *buffer, size_t size) { @@ -79,6 +83,8 @@ ssize_t write_libtar_buffer(int fd, const void *buffer, size_t size) { buffer_loc = 0; return -1; } else { + unsigned long long fs = (unsigned long long)(buffer_loc); + write(prog_pipe, &fs, sizeof(fs)); buffer_loc = 0; return size; } @@ -94,3 +100,14 @@ void flush_libtar_buffer(int fd) { if (buffer_status) buffer_status = 2; } + +void init_libtar_no_buffer(int pipe_fd) { + buffer_size = T_BLOCKSIZE; + prog_pipe = pipe_fd; + buffer_status = 0; +} + +ssize_t write_libtar_no_buffer(int fd, const void *buffer, size_t size) { + write(prog_pipe, &progress_size, sizeof(progress_size)); + return write(fd, buffer, size); +} -- cgit v1.2.3