Add better error message when the device cannot be opened.

This is helpful for SD cards or other removable media which have an enabled
write lock -- without the "Permission denied" message, the user has to strace
mkdosfs to find out what's going on.

Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
This commit is contained in:
Michael Stapelberg 2010-11-19 14:09:36 +01:00 committed by Daniel Baumann
parent bb6000fc30
commit d57980204e

View File

@ -1728,8 +1728,10 @@ main (int argc, char **argv)
if (!create) { if (!create) {
check_mount (device_name); /* Is the device already mounted? */ check_mount (device_name); /* Is the device already mounted? */
dev = open (device_name, O_EXCL|O_RDWR); /* Is it a suitable device to build the FS on? */ dev = open (device_name, O_EXCL|O_RDWR); /* Is it a suitable device to build the FS on? */
if (dev < 0) if (dev < 0) {
die ("unable to open %s"); fprintf (stderr, "%s: unable to open %s: %s\n", program_name, device_name, strerror(errno));
exit (1); /* The error exit code is 1! */
}
} }
else { else {
loff_t offset = blocks*BLOCK_SIZE - 1; loff_t offset = blocks*BLOCK_SIZE - 1;