Browse Source

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>
Michael Stapelberg 13 years ago
parent
commit
d57980204e
1 changed files with 4 additions and 2 deletions
  1. 4 2
      src/mkdosfs.c

+ 4 - 2
src/mkdosfs.c

@@ -1728,8 +1728,10 @@ main (int argc, char **argv)
   if (!create) {
     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? */
-    if (dev < 0)
-      die ("unable to open %s");
+    if (dev < 0) {
+      fprintf (stderr, "%s: unable to open %s: %s\n", program_name, device_name, strerror(errno));
+      exit (1);			/* The error exit code is 1! */
+    }
   }
   else {
       loff_t offset = blocks*BLOCK_SIZE - 1;