load_ramdisk_fd: support loading files >= 2GB

Related: #40710
This commit is contained in:
Alexey Sheplyakov 2021-08-18 22:00:11 +04:00
parent fa6c5ef78f
commit dc87263d47
2 changed files with 8 additions and 7 deletions

View File

@ -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);
}

13
tools.c
View File

@ -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);