implemented numeric sort (sort -g)
[oweals/busybox.git] / mount.c
diff --git a/mount.c b/mount.c
index 4c085d01b2dddf28f97c22f4bdef948b6d08637f..1ec9cbb5b53e8ebaae47a82833ec72360155aead 100644 (file)
--- a/mount.c
+++ b/mount.c
@@ -43,7 +43,7 @@
 
 extern const char mtab_file[]; /* Defined in utility.c */
 
-static const char mount_usage[] = "Usage:\tmount [flags]\n"
+static const char mount_usage[] = "\tmount [flags]\n"
     "\tmount [flags] device directory [-o options,more-options]\n"
     "\n"
     "Flags:\n"
@@ -92,12 +92,12 @@ static const struct mount_options mount_options[] = {
 };
 
 #if ! defined BB_MTAB
-#define do_mount(specialfile, dir, filesystemtype, flags, string_flags, useMtab, fakeIt) \
+#define do_mount(specialfile, dir, filesystemtype, flags, string_flags, useMtab, fakeIt, mtab_opts) \
        mount(specialfile, dir, filesystemtype, flags, string_flags)
 #else
 static int
 do_mount(char* specialfile, char* dir, char* filesystemtype, 
-       long flags, void* string_flags, int useMtab, int fakeIt)
+       long flags, void* string_flags, int useMtab, int fakeIt, char* mtab_opts)
 {
     int status=0;
 
@@ -106,7 +106,7 @@ do_mount(char* specialfile, char* dir, char* filesystemtype,
 
     if ( status == 0 ) {
        if ( useMtab==TRUE )
-           write_mtab(specialfile, dir, filesystemtype, flags, string_flags);
+           write_mtab(specialfile, dir, filesystemtype, flags, mtab_opts);
        return 0;
     }
     else 
@@ -157,12 +157,13 @@ parse_mount_options ( char *options, unsigned long *flags, char *strflags)
 
 int
 mount_one(char *blockDevice, char *directory, char *filesystemType,
-          unsigned long flags, char *string_flags, int useMtab, int fakeIt)
+          unsigned long flags, char *string_flags, int useMtab, int fakeIt, char *mtab_opts)
 {
     int status = 0;
 
     char buf[255];
 
+#if defined BB_FEATURE_USE_PROCFS
     if (strcmp(filesystemType, "auto") == 0) {
        FILE *f = fopen ("/proc/filesystems", "r");
 
@@ -182,15 +183,19 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
                filesystemType++;       // hop past tab
 
                status = do_mount (blockDevice, directory, filesystemType,
-                               flags | MS_MGC_VAL, string_flags, useMtab, fakeIt);
+                               flags | MS_MGC_VAL, string_flags, useMtab, 
+                               fakeIt, mtab_opts);
                if (status == 0)
                    break;
            }
        }
        fclose (f);
-    } else {
+    } else
+#endif
+    {
        status = do_mount (blockDevice, directory, filesystemType,
-                       flags | MS_MGC_VAL, string_flags, useMtab, fakeIt);
+                       flags | MS_MGC_VAL, string_flags, useMtab, 
+                       fakeIt, mtab_opts);
     }
 
     if (status) {
@@ -203,7 +208,9 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
 
 extern int mount_main (int argc, char **argv)
 {
-    char string_flags[1024]="";
+    char string_flags_buf[1024]="";
+    char *string_flags = string_flags_buf;
+    char *extra_opts = string_flags_buf;
     unsigned long flags = 0;
     char *filesystemType = "auto";
     char *device = NULL;
@@ -245,27 +252,22 @@ extern int mount_main (int argc, char **argv)
     argv++;
     while (i > 0 && **argv) {
        if (**argv == '-') {
-           while (i>0 && *++(*argv)) switch (**argv) {
+           char *opt = *argv;
+           while (i>0 && *++opt) switch (*opt) {
            case 'o':
                if (--i == 0) {
-                   fprintf (stderr, "%s\n", mount_usage);
-                   exit( FALSE);
+                   goto goodbye;
                }
                parse_mount_options (*(++argv), &flags, string_flags);
-               --i;
-               ++argv;
                break;
            case 'r':
                flags |= MS_RDONLY;
                break;
            case 't':
                if (--i == 0) {
-                   fprintf (stderr, "%s\n", mount_usage);
-                   exit( FALSE);
+                   goto goodbye;
                }
                filesystemType = *(++argv);
-               --i;
-               ++argv;
                break;
            case 'w':
                flags &= ~MS_RDONLY;
@@ -284,9 +286,7 @@ extern int mount_main (int argc, char **argv)
            case 'v':
            case 'h':
            case '-':
-               fprintf (stderr, "%s\n", mount_usage);
-               exit( TRUE);
-               break;
+               goto goodbye;
            }
        } else {
            if (device == NULL)
@@ -294,8 +294,7 @@ extern int mount_main (int argc, char **argv)
            else if (directory == NULL)
                directory=*argv;
            else {
-               fprintf (stderr, "%s\n", mount_usage);
-               exit( TRUE);
+               goto goodbye;
            }
        }
        i--;
@@ -322,18 +321,26 @@ extern int mount_main (int argc, char **argv)
                *string_flags = '\0';
                parse_mount_options(m->mnt_opts, &flags, string_flags);
                mount_one (m->mnt_fsname, m->mnt_dir, m->mnt_type, 
-                       flags, string_flags, useMtab, fakeIt);
+                       flags, string_flags, useMtab, fakeIt, extra_opts);
            }
        }
        endmntent (f);
     } else {
        if (device && directory) {
+#ifdef BB_NFSMOUNT
+           if (strcmp(filesystemType, "nfs") == 0) {
+               if (nfsmount(device, directory, &flags, &extra_opts, &string_flags, 1) != 0)
+               exit(FALSE);
+           }
+#endif
            exit (mount_one (device, directory, filesystemType, 
-                       flags, string_flags, useMtab, fakeIt));
+                       flags, string_flags, useMtab, fakeIt, extra_opts));
        } else {
-           fprintf (stderr, "%s\n", mount_usage);
-           exit( FALSE);
+           goto goodbye;
        }
     }
     exit( TRUE);
+
+goodbye:
+    usage( mount_usage);
 }