Guard for verify only
This commit is contained in:
parent
19bf88b2e6
commit
c08ee6a738
1 changed files with 31 additions and 19 deletions
50
writeimg.c
50
writeimg.c
|
|
@ -100,15 +100,20 @@ int perform_write(write_job_t *job) {
|
|||
int crc = crc32_init();
|
||||
size_t b_written = 0;
|
||||
|
||||
while (!job->verify_only) {
|
||||
while (42) {
|
||||
fsync(block_fd);
|
||||
ssize_t read_bytes = read(file_fd, job->buffer, job->block_size);
|
||||
assert(read_bytes >= 0);
|
||||
|
||||
if (read_bytes == 0) {
|
||||
fsync(block_fd);
|
||||
crc = crc32_finalize(crc);
|
||||
printf("\nWriting done...\n");
|
||||
assert(job->total_bytes == b_written);
|
||||
|
||||
if (!job->verify_only) {
|
||||
printf("\nWriting done...\n");
|
||||
assert(job->total_bytes == b_written);
|
||||
} else
|
||||
assert(0 == b_written);
|
||||
|
||||
break; /* Finished */
|
||||
}
|
||||
|
||||
|
|
@ -120,13 +125,15 @@ int perform_write(write_job_t *job) {
|
|||
|
||||
crc = crc32_update(crc, job->buffer, read_bytes);
|
||||
|
||||
ssize_t written_bytes = write(block_fd, job->buffer, read_bytes);
|
||||
if (written_bytes < 0) {
|
||||
fprintf(stderr, "%s: Write error\n", job->dev_name);
|
||||
perror("Write");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
print_progress(b_written += written_bytes, job->total_bytes);
|
||||
if (!job->verify_only) {
|
||||
ssize_t written_bytes = write(block_fd, job->buffer, read_bytes);
|
||||
if (written_bytes < 0) {
|
||||
fprintf(stderr, "%s: Write error\n", job->dev_name);
|
||||
perror("Write");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
print_progress(b_written += written_bytes, job->total_bytes);
|
||||
} /* Else maybe give some helpful insights? */
|
||||
}
|
||||
|
||||
lseek(block_fd, 0, SEEK_SET);
|
||||
|
|
@ -173,6 +180,7 @@ static const struct option longopts[] = {
|
|||
{"help", 0, 0, 'h'},
|
||||
{"version", 0, 0, 'V'},
|
||||
{"device", 1, 0, 'd'},
|
||||
{"noconfirm", 0, 0, 'n'},
|
||||
{NULL, 0, 0, 0},
|
||||
};
|
||||
|
||||
|
|
@ -240,12 +248,16 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
close(fd);
|
||||
|
||||
printf("Writing %s to %s\n", wjob.filename, wjob.dev_name);
|
||||
if (!wjob.verify_only)
|
||||
printf("Writing %s to %s\n", wjob.filename, wjob.dev_name);
|
||||
|
||||
printf("Is this okay? (y/n): ");
|
||||
fflush(stdout);
|
||||
if ('y' != getchar()) {
|
||||
exit(0);
|
||||
if (ask_permission && !wjob.verify_only) {
|
||||
printf("Is this okay? (y/n): ");
|
||||
fflush(stdout);
|
||||
if ('y' != getchar()) {
|
||||
printf("Aborting...\n");
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
wjob.buffer = malloc(BLOCKSIZE);
|
||||
|
|
@ -266,7 +278,7 @@ int main(int argc, char *argv[]) {
|
|||
if (wjob.buffer2)
|
||||
free(wjob.buffer2);
|
||||
|
||||
printf("\n%.1f MiB's written and verified.\nAll good!\n", BYTES_TO_MIB(wjob.total_bytes));
|
||||
exit(0);
|
||||
return 0;
|
||||
printf("\n%.1f MiB's verified.\nAll good!\n", BYTES_TO_MIB(wjob.total_bytes));
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue