On 2020-08-09, Jonathan Gray wrote:
> mount_msdos(8) knows about EINVAL and will print "not an MSDOS filesystem"

I think mount_msdos could also inspect the filesytem for the common case of
exfat confusion.

Index: mount_msdos.c
===================================================================
RCS file: /home/cvs/src/sbin/mount_msdos/mount_msdos.c,v
retrieving revision 1.34
diff -u -p -r1.34 mount_msdos.c
--- mount_msdos.c       28 Jun 2019 13:32:45 -0000      1.34
+++ mount_msdos.c       9 Aug 2020 15:10:08 -0000
@@ -37,6 +37,7 @@
 #include <ctype.h>
 #include <err.h>
 #include <grp.h>
+#include <fcntl.h>
 #include <pwd.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -58,6 +59,7 @@ gid_t a_gid(char *);
 uid_t  a_uid(char *);
 mode_t a_mask(char *);
 void   usage(void);
+int    checkexfat(const char *);
 
 int
 main(int argc, char **argv)
@@ -140,6 +142,9 @@ main(int argc, char **argv)
                case EINVAL:
                        errcause =
                            "not an MSDOS filesystem";
+                       if (checkexfat(dev)) {
+                               errcause = "exFAT is not supported";
+                       }
                        break;
                default:
                        errcause = strerror(errno);
@@ -204,4 +209,20 @@ usage(void)
        fprintf(stderr,
            "usage: mount_msdos [-9ls] [-g gid] [-m mask] [-o options] [-u uid] 
special node\n");
        exit(1);
+}
+
+int
+checkexfat(const char *dev)
+{
+       char buf[4096];
+       int fd;
+
+       fd = open(dev, O_RDONLY);
+       if (fd != -1) {
+               ssize_t amt = read(fd, buf, sizeof(buf));
+               close(fd);
+               if (amt >= 11 && memcmp(buf + 3, "EXFAT   ", 8) == 0)
+                       return 1;
+       }
+       return 0;
 }

Reply via email to