Add errno.h
[oweals/busybox.git] / umount.c
index eff080463abc8ba323da50bba82b1b7ac9963edf..2e2d95de449562333e230816848ea68ca8d0dee8 100644 (file)
--- a/umount.c
+++ b/umount.c
 #include <errno.h>
 
 
-#define MNT_FORCE              1
-#define MS_MGC_VAL             0xc0ed0000 /* Magic number indicatng "new" flags */
-#define MS_REMOUNT             32      /* Alter flags of a mounted FS.  */
-#define MS_RDONLY              1       /* Mount read-only.  */
+static const int MNT_FORCE = 1;
+static const int MS_MGC_VAL = 0xc0ed0000; /* Magic number indicatng "new" flags */
+static const int MS_REMOUNT = 32;      /* Alter flags of a mounted FS.  */
+static const int MS_RDONLY = 1;        /* Mount read-only.  */
 
 extern int mount (__const char *__special_file, __const char *__dir,
                        __const char *__fstype, unsigned long int __rwflag,
@@ -79,7 +79,7 @@ void mtab_read(void)
                return;
 
        if ((fp = setmntent(mtab_file, "r")) == NULL) {
-               errorMsg("Cannot open %s\n", mtab_file);
+               error_msg("Cannot open %s\n", mtab_file);
                return;
        }
        while ((e = getmntent(fp))) {
@@ -179,7 +179,7 @@ static int do_umount(const char *name, int useMtab)
        if (status != 0 && doForce == TRUE) {
                status = umount2(blockDevice, MNT_FORCE);
                if (status != 0) {
-                       fatalError("forced umount of %s failed!\n", blockDevice);
+                       error_msg_and_die("forced umount of %s failed!\n", blockDevice);
                }
        }
 #endif
@@ -187,9 +187,9 @@ static int do_umount(const char *name, int useMtab)
                status = mount(blockDevice, name, NULL,
                                           MS_MGC_VAL | MS_REMOUNT | MS_RDONLY, NULL);
                if (status == 0) {
-                       errorMsg("%s busy - remounted read-only\n", blockDevice);
+                       error_msg("%s busy - remounted read-only\n", blockDevice);
                } else {
-                       errorMsg("Cannot remount %s read-only\n", blockDevice);
+                       error_msg("Cannot remount %s read-only\n", blockDevice);
                }
        }
        if (status == 0) {
@@ -212,18 +212,18 @@ static int umount_all(int useMtab)
                /* Never umount /proc on a umount -a */
                if (strstr(mountpt, "proc")!= NULL)
                        continue;
-               status = do_umount(mountpt, useMtab);
-               if (status != 0) {
+               if (!do_umount(mountpt, useMtab)) {
                        /* Don't bother retrying the umount on busy devices */
                        if (errno == EBUSY) {
-                               perror(mountpt);
+                               perror_msg("%s", mountpt);
+                               status = FALSE;
                                continue;
                        }
-                       status = do_umount(mountpt, useMtab);
-                       if (status != 0) {
+                       if (!do_umount(mountpt, useMtab)) {
                                printf("Couldn't umount %s on %s: %s\n",
                                           mountpt, mtab_getinfo(mountpt, MTAB_GETDEVICE),
                                           strerror(errno));
+                               status = FALSE;
                        }
                }
        }
@@ -280,7 +280,6 @@ extern int umount_main(int argc, char **argv)
        }
        if (do_umount(*argv, useMtab) == TRUE)
                return EXIT_SUCCESS;
-       perror("umount");
-       return EXIT_FAILURE;
+       perror_msg_and_die("%s", *argv);
 }