Now also reports the size of the block device before asking to continue

This commit is contained in:
Imbus 2026-02-21 03:57:30 +01:00
parent 60e7179766
commit 2e02a056cc

View file

@ -268,20 +268,34 @@ int main(int argc, char *argv[]) {
exit(EXIT_FAILURE);
}
/* Seems to be the cleanest way to check for write perm on a blockdev */
int fd = open(wjob.oname, O_WRONLY);
if (fd < 0) {
printf("Cannot write to \"%s\", do you have write permissions?\n", wjob.oname);
exit(1);
uint64_t device_size;
{
/* Seems to be the cleanest way to check for write perm on a blockdev */
int fd = open(wjob.oname, O_WRONLY);
if (fd < 0) {
printf("Cannot write to \"%s\", do you have write permissions?\n", wjob.oname);
close(fd);
exit(EXIT_FAILURE);
}
if (ioctl(fd, BLKGETSIZE64, &device_size) < 0) {
perror("ioctl");
close(fd);
exit(EXIT_FAILURE);
}
close(fd);
}
close(fd);
wjob.total_bytes = file_stat.st_size;
assert(file_stat.st_size >= 0);
if (wjob.flags & WI_WRITE)
printf(
"Writing \"%s\" (%.1f MiB) to \"%s\"\n", basename(wjob.iname), BYTES_TO_MIB(wjob.total_bytes), wjob.oname);
printf("Writing \"%s\" (%.1f MiB) to \"%s\" (%.1f MiB)\n",
basename(wjob.iname),
BYTES_TO_MIB(wjob.total_bytes),
wjob.oname,
BYTES_TO_MIB(device_size));
if ((wjob.flags & WI_ASK) && (wjob.flags & WI_WRITE)) {
printf("Is this okay? (y/N): ");