From d57980204ef78b863130e9ef75f8e9f66bb677ec Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Fri, 19 Nov 2010 14:09:36 +0100 Subject: [PATCH] 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 --- src/mkdosfs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mkdosfs.c b/src/mkdosfs.c index bfa80a3..a1378ee 100644 --- a/src/mkdosfs.c +++ b/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;