Add in BB_FEATURE_CLEAN_UP, which is whether to clean up mem leaks and close
[oweals/busybox.git] / mount.c
diff --git a/mount.c b/mount.c
index 76f048b1c86c55dfb717b317f104e3d9f7b439aa..610d12d3419901ea3ab4bec234cd66fc4a9f93f8 100644 (file)
--- a/mount.c
+++ b/mount.c
 #include <string.h>
 #include <stdio.h>
 #include <mntent.h>
-#include <sys/mount.h>
 #include <ctype.h>
 #if defined BB_FEATURE_USE_DEVPS_PATCH
-#include <linux/devmtab.h>
-#endif
-#ifndef MS_RDONLY
-#include <linux/fs.h>
+#include <linux/devmtab.h> /* For Erik's nifty devmtab device driver */
 #endif
 
 
+#define MS_MGC_VAL             0xc0ed0000 /* Magic number indicatng "new" flags */
+#define MS_RDONLY        1      /* Mount read-only */
+#define MS_NOSUID        2      /* Ignore suid and sgid bits */
+#define MS_NODEV         4      /* Disallow access to device special files */
+#define MS_NOEXEC        8      /* Disallow program execution */
+#define MS_SYNCHRONOUS  16      /* Writes are synced at once */
+#define MS_REMOUNT      32      /* Alter flags of a mounted FS */
+#define MS_MANDLOCK     64      /* Allow mandatory locks on an FS */
+#define S_QUOTA         128     /* Quota initialized for file/directory/symlink */
+#define S_APPEND        256     /* Append-only file */
+#define S_IMMUTABLE     512     /* Immutable file */
+#define MS_NOATIME      1024    /* Do not update access times. */
+#define MS_NODIRATIME   2048    /* Do not update directory access times */
+
+
+
 #if defined BB_FEATURE_MOUNT_LOOP
 #include <fcntl.h>
 #include <sys/ioctl.h>
-#include <linux/loop.h>
-
-
 static int use_loop = FALSE;
 #endif
 
-extern const char mtab_file[]; /* Defined in utility.c */
+extern int mount (__const char *__special_file, __const char *__dir,
+                       __const char *__fstype, unsigned long int __rwflag,
+                       __const void *__data);
+extern int umount (__const char *__special_file);
+extern int umount2 (__const char *__special_file, int __flags);
 
-static const char mount_usage[] = 
-       "mount [flags] device directory [-o options,more-options]\n"
-#ifndef BB_FEATURE_TRIVIAL_HELP
-       "\nMount a filesystem\n\n"
-       "Flags:\n" 
-       "\t-a:\t\tMount all filesystems in fstab.\n"
-#ifdef BB_MTAB
-       "\t-f:\t\t\"Fake\" mount. Add entry to mount table but don't mount it.\n"
-       "\t-n:\t\tDon't write a mount table entry.\n"
-#endif
-       "\t-o option:\tOne of many filesystem options, listed below.\n"
-       "\t-r:\t\tMount the filesystem read-only.\n"
-       "\t-t fs-type:\tSpecify the filesystem type.\n"
-       "\t-w:\t\tMount for reading and writing (default).\n"
-       "\n"
-       "Options for use with the \"-o\" flag:\n"
-       "\tasync/sync:\tWrites are asynchronous / synchronous.\n"
-       "\tatime/noatime:\tEnable / disable updates to inode access times.\n"
-       "\tdev/nodev:\tAllow use of special device files / disallow them.\n"
-       "\texec/noexec:\tAllow use of executable files / disallow them.\n"
-#if defined BB_FEATURE_MOUNT_LOOP
-       "\tloop:\t\tMounts a file via loop device.\n"
-#endif
-       "\tsuid/nosuid:\tAllow set-user-id-root programs / disallow them.\n"
-       "\tremount:\tRe-mount a currently-mounted filesystem, changing its flags.\n"
-       "\tro/rw:\t\tMount for read-only / read-write.\n"
-       "\nThere are EVEN MORE flags that are specific to each filesystem.\n"
-       "You'll have to see the written documentation for those.\n"
-#endif
-       ;
 
+extern const char mtab_file[]; /* Defined in utility.c */
 
 struct mount_options {
        const char *name;
@@ -141,15 +125,15 @@ do_mount(char *specialfile, char *dir, char *filesystemtype,
 
                        specialfile = find_unused_loop_device();
                        if (specialfile == NULL) {
-                               fprintf(stderr, "Could not find a spare loop device\n");
+                               errorMsg("Could not find a spare loop device\n");
                                return (FALSE);
                        }
                        if (set_loop(specialfile, lofile, 0, &loro)) {
-                               fprintf(stderr, "Could not setup loop device\n");
+                               errorMsg("Could not setup loop device\n");
                                return (FALSE);
                        }
                        if (!(flags & MS_RDONLY) && loro) {     /* loop is ro, but wanted rw */
-                               fprintf(stderr, "WARNING: loop device is read-only\n");
+                               errorMsg("WARNING: loop device is read-only\n");
                                flags &= ~MS_RDONLY;
                        }
                }
@@ -177,7 +161,7 @@ do_mount(char *specialfile, char *dir, char *filesystemtype,
 #endif
 
        if (errno == EPERM) {
-               fatalError("mount: permission denied. Are you root?\n");
+               fatalError("permission denied. Are you root?\n");
        }
 
        return (FALSE);
@@ -187,7 +171,7 @@ do_mount(char *specialfile, char *dir, char *filesystemtype,
 
 /* Seperate standard mount options from the nonstandard string options */
 static void
-parse_mount_options(char *options, unsigned long *flags, char *strflags)
+parse_mount_options(char *options, int *flags, char *strflags)
 {
        while (options) {
                int gotone = FALSE;
@@ -313,7 +297,7 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
 
        if (status == FALSE) {
                if (whineOnErrors == TRUE) {
-                       fprintf(stderr, "Mounting %s on %s failed: %s\n",
+                       errorMsg("Mounting %s on %s failed: %s\n",
                                        blockDevice, directory, strerror(errno));
                }
                return (FALSE);
@@ -326,7 +310,7 @@ extern int mount_main(int argc, char **argv)
        char string_flags_buf[1024] = "";
        char *string_flags = string_flags_buf;
        char *extra_opts = string_flags_buf;
-       unsigned long flags = 0;
+       int flags = 0;
        char *filesystemType = "auto";
        char *device = NULL;
        char *directory = NULL;