Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-5]: src/sbin/mount Pull up revisions 1.48-1.49, 1.51, 1.54 (via p...



details:   https://anonhg.NetBSD.org/src/rev/f930265371b7
branches:  netbsd-1-5
changeset: 490677:f930265371b7
user:      he <he%NetBSD.org@localhost>
date:      Mon Feb 26 16:50:36 2001 +0000

description:
Pull up revisions 1.48-1.49,1.51,1.54 (via patch, requested by abs):
  If both special and node are given (but no type), the disklabel
  is checked for the file system type before falling back to ffs.

diffstat:

 sbin/mount/mount.c |  78 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 74 insertions(+), 4 deletions(-)

diffs (120 lines):

diff -r 325a9b086722 -r f930265371b7 sbin/mount/mount.c
--- a/sbin/mount/mount.c        Mon Feb 26 16:50:13 2001 +0000
+++ b/sbin/mount/mount.c        Mon Feb 26 16:50:36 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mount.c,v 1.47.4.1 2000/10/18 00:39:46 tv Exp $        */
+/*     $NetBSD: mount.c,v 1.47.4.2 2001/02/26 16:50:36 he Exp $        */
 
 /*
  * Copyright (c) 1980, 1989, 1993, 1994
@@ -43,7 +43,7 @@
 #if 0
 static char sccsid[] = "@(#)mount.c    8.25 (Berkeley) 5/8/95";
 #else
-__RCSID("$NetBSD: mount.c,v 1.47.4.1 2000/10/18 00:39:46 tv Exp $");
+__RCSID("$NetBSD: mount.c,v 1.47.4.2 2001/02/26 16:50:36 he Exp $");
 #endif
 #endif /* not lint */
 
@@ -61,6 +61,11 @@
 #include <string.h>
 #include <unistd.h>
 
+#define MOUNTNAMES
+#include <fcntl.h>
+#include <sys/disklabel.h>
+#include <sys/ioctl.h>
+
 #include "pathnames.h"
 
 int    debug, verbose;
@@ -72,6 +77,8 @@
 int    hasopt __P((const char *, const char *));
 const char
       **makevfslist __P((char *));
+const static char *
+       getfslab __P((const char *str));
 static void
        mangle __P((char *, int *, const char ***, int *));
 int    mountfs __P((const char *, const char *, const char *,
@@ -247,8 +254,15 @@
                 * a ':' or a '@' then assume that an NFS filesystem is being
                 * specified ala Sun.
                 */
-               if (vfslist == NULL && strpbrk(argv[0], ":@") != NULL)
-                       vfstype = "nfs";
+               if (vfslist == NULL) {
+                       if (strpbrk(argv[0], ":@") != NULL)
+                               vfstype = "nfs";
+                       else {
+                               vfstype = getfslab(argv[0]);
+                               if (vfstype == NULL)
+                                       vfstype = ffs_fstype;
+                       }
+               }
                rval = mountfs(vfstype,
                    argv[0], argv[1], init_flags, options, NULL, 0);
                break;
@@ -561,6 +575,62 @@
        *maxargcp = maxargc;
 }
 
+       /* deduce the filesystem type from the disk label */
+
+const static char *
+getfslab(str)
+       const char *str;
+{
+       struct disklabel dl;
+       int fd;
+       int part;
+       const char *vfstype;
+       u_char fstype;
+       char buf[MAXPATHLEN+1];
+       char *sp, *ep;
+
+       if ((fd = open(str, O_RDONLY)) == -1) {
+               /*
+                * Iff we get EBUSY try the raw device. Since mount always uses
+                * the block device we know we are never passed a raw device.
+                */
+               if (errno != EBUSY)
+                       err(1, "cannot open `%s'", str);
+               strlcpy(buf, str, MAXPATHLEN);
+               if ((sp = strrchr(buf, '/')) != NULL)
+                       ++sp;
+               else
+                       sp = buf;
+               for( ep = sp + strlen(sp) + 1 ;  ep > sp ; ep-- )
+                       *ep = *(ep-1);
+               *sp = 'r';
+
+               /* Silently fail here - mount call can display error */
+               if ((fd = open(buf, O_RDONLY)) == -1)
+                       return NULL;
+       }
+
+       if (ioctl(fd, DIOCGDINFO, &dl) == -1) {
+               (void) close(fd);
+               return NULL;
+       }
+
+       (void) close(fd);
+
+       part = str[strlen(str) - 1] - 'a';
+
+       if (part < 0 || part >= dl.d_npartitions)
+               errx(1, "partition `%s' is not defined on disk", str);
+
+       /* Return NULL for unknown types - caller can fall back to ffs */
+       if ((fstype = dl.d_partitions[part].p_fstype) >= FSMAXMOUNTNAMES)
+               vfstype = NULL;
+       else
+               vfstype = mountnames[fstype];
+
+       return vfstype;
+}
+
 void
 usage()
 {



Home | Main Index | Thread Index | Old Index