From dc87263d472beaa7882b1ed9adc1358a26f4ad03 Mon Sep 17 00:00:00 2001 From: Alexey Sheplyakov Date: Wed, 18 Aug 2021 22:00:11 +0400 Subject: [PATCH] load_ramdisk_fd: support loading files >= 2GB Related: #40710 --- newt-frontend.c | 2 +- tools.c | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/newt-frontend.c b/newt-frontend.c index f717a0e..eace220 100644 --- a/newt-frontend.c +++ b/newt-frontend.c @@ -152,7 +152,7 @@ void update_progression(int current_size) time = t.tv_sec*3 + t.tv_usec/300000; if (time != last_time) { char msg_prog_final[500]; - sprintf(msg_prog_final, "%s (%d bytes read) ", msg_progress, current_size); + sprintf(msg_prog_final, "%s (%d MB read) ", msg_progress, current_size); remove_wait_message(); wait_message(msg_prog_final); } diff --git a/tools.c b/tools.c index 31e4ed9..3b059be 100644 --- a/tools.c +++ b/tools.c @@ -300,8 +300,8 @@ enum return_type load_ramdisk_fd(int source_fd, unsigned long size) int ram_fd; char buffer[32768]; char * wait_msg = "Loading program into memory..."; - int bytes_read = 0; - int actually; + unsigned long bytes_read = 0; + ssize_t actually; int seems_ok = 0; ram_fd = open(ramdisk, O_WRONLY); @@ -311,7 +311,7 @@ enum return_type load_ramdisk_fd(int source_fd, unsigned long size) return RETURN_ERROR; } - init_progression(wait_msg, (int)size); + init_progression(wait_msg, (int)BYTES2MB(size)); while ((actually = read(source_fd, buffer, sizeof(buffer))) > 0) { seems_ok = 1; @@ -320,7 +320,8 @@ enum return_type load_ramdisk_fd(int source_fd, unsigned long size) remove_wait_message(); return RETURN_ERROR; } - update_progression((int)(bytes_read += actually)); + bytes_read += actually; + update_progression((int)BYTES2MB(bytes_read)); if (bytes_read == size) break; } @@ -443,7 +444,7 @@ enum return_type verify_ramdisk_digest(const char *filename, const char *sha256_ return RETURN_ERROR; } - init_progression("Verifying stage2 authenticity...", st.st_size); + init_progression("Verifying stage2 authenticity...", (int)BYTES2MB(st.st_size)); sha256_context ctx; sha256_starts(&ctx); @@ -462,7 +463,7 @@ enum return_type verify_ramdisk_digest(const char *filename, const char *sha256_ } sha256_update(&ctx, buffer, bytes_read); total_bytes_read += bytes_read; - update_progression(total_bytes_read); + update_progression((int)BYTES2MB(total_bytes_read)); } close(fd);