Now also reports the size of the block device before asking to continue
This commit is contained in:
parent
60e7179766
commit
2e02a056cc
1 changed files with 22 additions and 8 deletions
22
writeimg.c
22
writeimg.c
|
|
@ -268,20 +268,34 @@ int main(int argc, char *argv[]) {
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
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);
|
||||
exit(1);
|
||||
}
|
||||
close(fd);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (ioctl(fd, BLKGETSIZE64, &device_size) < 0) {
|
||||
perror("ioctl");
|
||||
close(fd);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
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): ");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue