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