Small size optimization from Aaron Lehmann
[oweals/busybox.git] / umount.c
index 3e23b9705edf3e660f277fca16eadf945d496ded..74638d21c0899c4fa9c01be7ed8c7270a233786b 100644 (file)
--- a/umount.c
+++ b/umount.c
@@ -22,6 +22,7 @@
  *
  */
 
+#include <limits.h>
 #include <stdio.h>
 #include <mntent.h>
 #include <errno.h>
 #include <stdlib.h>
 #include "busybox.h"
 
+/* Teach libc5 about realpath -- it includes it but the 
+ * prototype is missing... */
+#if (__GLIBC__ <= 2) && (__GLIBC_MINOR__ < 1)
+extern char *realpath(const char *path, char *resolved_path);
+#endif
 
 static const int MNT_FORCE = 1;
 static const int MS_MGC_VAL = 0xc0ed0000; /* Magic number indicatng "new" flags */
@@ -73,7 +79,7 @@ extern const char mtab_file[];        /* Defined in utility.c */
  * TODO: Perhaps switch to using Glibc's getmntent_r
  *        -Erik
  */
-void mtab_read(void)
+static void mtab_read(void)
 {
        struct _mtab_entry_t *entry = NULL;
        struct mntent *e;
@@ -96,7 +102,7 @@ void mtab_read(void)
        endmntent(fp);
 }
 
-char *mtab_getinfo(const char *match, const char which)
+static char *mtab_getinfo(const char *match, const char which)
 {
        struct _mtab_entry_t *cur = mtab_cache;
 
@@ -110,8 +116,7 @@ char *mtab_getinfo(const char *match, const char which)
                                if (strcmp(cur->device, "/dev/root") == 0) {
                                        /* Adjusts device to be the real root device,
                                         * or leaves device alone if it can't find it */
-                                       find_real_root_device_name( cur->device);
-                                       return ( cur->device);
+                                       cur->device = find_real_root_device_name(cur->device);
                                }
 #endif
                                return cur->device;
@@ -122,18 +127,7 @@ char *mtab_getinfo(const char *match, const char which)
        return NULL;
 }
 
-char *mtab_first(void **iter)
-{
-       struct _mtab_entry_t *mtab_iter;
-
-       if (!iter)
-               return NULL;
-       mtab_iter = mtab_cache;
-       *iter = (void *) mtab_iter;
-       return mtab_next(iter);
-}
-
-char *mtab_next(void **iter)
+static char *mtab_next(void **iter)
 {
        char *mp;
 
@@ -144,10 +138,21 @@ char *mtab_next(void **iter)
        return mp;
 }
 
+static char *mtab_first(void **iter)
+{
+       struct _mtab_entry_t *mtab_iter;
+
+       if (!iter)
+               return NULL;
+       mtab_iter = mtab_cache;
+       *iter = (void *) mtab_iter;
+       return mtab_next(iter);
+}
+
 /* Don't bother to clean up, since exit() does that 
  * automagically, so we can save a few bytes */
 #ifdef BB_FEATURE_CLEAN_UP
-void mtab_free(void)
+static void mtab_free(void)
 {
        struct _mtab_entry_t *this, *next;
 
@@ -236,6 +241,8 @@ static int umount_all(void)
 
 extern int umount_main(int argc, char **argv)
 {
+       char path[PATH_MAX];
+
        if (argc < 2) {
                show_usage();
        }
@@ -282,7 +289,9 @@ extern int umount_main(int argc, char **argv)
                else
                        return EXIT_FAILURE;
        }
-       if (do_umount(*argv) == TRUE)
+       if (realpath(*argv, path) == NULL)
+               perror_msg_and_die("%s", path);
+       if (do_umount(path) == TRUE)
                return EXIT_SUCCESS;
        perror_msg_and_die("%s", *argv);
 }