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
30
writeimg.c
30
writeimg.c
|
|
@ -268,20 +268,34 @@ int main(int argc, char *argv[]) {
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Seems to be the cleanest way to check for write perm on a blockdev */
|
uint64_t device_size;
|
||||||
int fd = open(wjob.oname, O_WRONLY);
|
{
|
||||||
if (fd < 0) {
|
/* Seems to be the cleanest way to check for write perm on a blockdev */
|
||||||
printf("Cannot write to \"%s\", do you have write permissions?\n", wjob.oname);
|
int fd = open(wjob.oname, O_WRONLY);
|
||||||
exit(1);
|
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;
|
wjob.total_bytes = file_stat.st_size;
|
||||||
assert(file_stat.st_size >= 0);
|
assert(file_stat.st_size >= 0);
|
||||||
|
|
||||||
if (wjob.flags & WI_WRITE)
|
if (wjob.flags & WI_WRITE)
|
||||||
printf(
|
printf("Writing \"%s\" (%.1f MiB) to \"%s\" (%.1f MiB)\n",
|
||||||
"Writing \"%s\" (%.1f MiB) to \"%s\"\n", basename(wjob.iname), BYTES_TO_MIB(wjob.total_bytes), wjob.oname);
|
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)) {
|
if ((wjob.flags & WI_ASK) && (wjob.flags & WI_WRITE)) {
|
||||||
printf("Is this okay? (y/N): ");
|
printf("Is this okay? (y/N): ");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue