Compare commits

...

4 commits

Author SHA1 Message Date
Imbus
9d2645ad65 Readme 2026-02-07 18:38:48 +01:00
Imbus
53239324ef Tell the user how much data will be written beforehand 2026-02-07 18:24:32 +01:00
Imbus
a1556ca383 Set (y/n) prompt to (y/N) to better reflect behaviour 2026-02-07 18:23:59 +01:00
Imbus
0a4626e7d1 Fix formatting when error occurs 2026-02-07 18:23:33 +01:00
2 changed files with 31 additions and 7 deletions

View file

@ -1,4 +1,24 @@
Simple dd-like image writer with additional security checks.
# Simple dd-like image writer with additional security checks.
```
writeimg v0.2.0, Rev. 5323932-dirty
In honor of SwePwnage - the OG disk destroyer
Copyright (C) 2026 Imbus, BSD-2-Clause
Build date: 2026-02-07
Usage:
writeimg [-v] -d <device> <file.img>
Args:
<file.img> Binary image file
-v Verify only
-d device Target block device
-h, --help Print this help message
-n, --noconfirm Do not ask for premission
-V, --version Print version
```
## Testing
dd if=/dev/zero of=./disk.img bs=1M count=1024
losetup -fP ./disk.img

View file

@ -175,7 +175,8 @@ int perform_write(write_job_t *job) {
int cmp = memcmp((const void *)job->buffer2, (const void *)job->buffer, (size_t)read_file);
if (0 != cmp) {
fprintf(stderr, "WARNING: File did not verify correctly!\n");
fflush(stdout);
fprintf(stderr, "\nWARNING: File did not verify correctly!\n");
exit(EXIT_FAILURE);
}
}
@ -260,11 +261,17 @@ int main(int argc, char *argv[]) {
}
close(fd);
wjob.total_bytes = file_stat.st_size;
assert(file_stat.st_size >= 0);
if (!wjob.verify_only)
printf("Writing %s to %s\n", wjob.filename, wjob.dev_name);
printf("Writing \"%s\" (%.1f MiB) to \"%s\"\n",
basename(wjob.filename),
BYTES_TO_MIB(wjob.total_bytes),
wjob.dev_name);
if (ask_permission && !wjob.verify_only) {
printf("Is this okay? (y/n): ");
printf("Is this okay? (y/N): ");
fflush(stdout);
if ('y' != getchar()) {
printf("Aborting...\n");
@ -280,9 +287,6 @@ int main(int argc, char *argv[]) {
wjob.bufsize = BLOCKSIZE;
wjob.block_size = BLOCKSIZE;
wjob.total_bytes = file_stat.st_size;
assert(file_stat.st_size >= 0);
perform_write(&wjob);
if (wjob.buffer)