More stuff
[oweals/busybox.git] / mount.c
diff --git a/mount.c b/mount.c
index 4e5c0745bab8ace66c6c579896c5b492c2310a0d..a7d5aed2d46b196b8d76f3fa2e097b0c24b0c0b5 100644 (file)
--- a/mount.c
+++ b/mount.c
@@ -37,7 +37,7 @@
 #include <ctype.h>
 #include <fstab.h>
 
-const char mount_usage[] = "Usage:\tmount [flags]\n"
+static const char mount_usage[] = "Usage:\tmount [flags]\n"
     "\tmount [flags] device directory [-o options,more-options]\n"
     "\n"
     "Flags:\n"
@@ -174,23 +174,32 @@ extern int mount_main (int argc, char **argv)
     char *filesystemType = "auto";
     char *device = NULL;
     char *directory = NULL;
+    struct stat statBuf;
     int all = 0;
     int i;
 
+    if (stat("/etc/fstab", &statBuf) < 0) 
+       fprintf(stderr, "/etc/fstab file missing -- Please install one.\n\n");
+
     if (argc == 1) {
        FILE *mountTable;
        if ((mountTable = setmntent ("/proc/mounts", "r"))) {
            struct mntent *m;
            while ((m = getmntent (mountTable)) != 0) {
+               struct fstab* fstabItem;
                char *blockDevice = m->mnt_fsname;
-               if (strcmp (blockDevice, "/dev/root") == 0)
-                   blockDevice = (getfsfile ("/"))->fs_spec;
+               /* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
+               if (strcmp (blockDevice, "/dev/root") == 0) {
+                   fstabItem = getfsfile ("/");
+                   if (fstabItem != NULL)
+                       blockDevice = fstabItem->fs_spec;
+               }
                printf ("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir,
                        m->mnt_type, m->mnt_opts);
            }
            endmntent (mountTable);
        }
-       return( TRUE);
+       exit( TRUE);
     }
 
 
@@ -203,7 +212,7 @@ extern int mount_main (int argc, char **argv)
            case 'o':
                if (--i == 0) {
                    fprintf (stderr, "%s\n", mount_usage);
-                   return( FALSE);
+                   exit( FALSE);
                }
                parse_mount_options (*(++argv), &flags, string_flags);
                --i;
@@ -215,7 +224,7 @@ extern int mount_main (int argc, char **argv)
            case 't':
                if (--i == 0) {
                    fprintf (stderr, "%s\n", mount_usage);
-                   return( FALSE);
+                   exit( FALSE);
                }
                filesystemType = *(++argv);
                --i;
@@ -231,7 +240,7 @@ extern int mount_main (int argc, char **argv)
            case 'h':
            case '-':
                fprintf (stderr, "%s\n", mount_usage);
-               return( TRUE);
+               exit( TRUE);
                break;
            }
        } else {
@@ -241,7 +250,7 @@ extern int mount_main (int argc, char **argv)
                directory=*argv;
            else {
                fprintf (stderr, "%s\n", mount_usage);
-               return( TRUE);
+               exit( TRUE);
            }
        }
        i--;
@@ -254,7 +263,7 @@ extern int mount_main (int argc, char **argv)
 
        if (f == NULL) {
            perror("/etc/fstab");
-           return( FALSE); 
+           exit( FALSE); 
        }
        while ((m = getmntent (f)) != NULL) {
            // If the file system isn't noauto, and isn't mounted on /, mount 
@@ -270,12 +279,12 @@ extern int mount_main (int argc, char **argv)
        endmntent (f);
     } else {
        if (device && directory) {
-           return (mount_one (device, directory, filesystemType, 
+           exit (mount_one (device, directory, filesystemType, 
                        flags, string_flags));
        } else {
            fprintf (stderr, "%s\n", mount_usage);
-           return( FALSE);
+           exit( FALSE);
        }
     }
-    return( TRUE);
+    exit( TRUE);
 }