[Toybox] [patch] add u?mount
Isaac
ibid.ag at gmail.com
Sun Aug 18 08:43:24 PDT 2013
On Sun, Aug 18, 2013 at 09:38:42AM -0500, Strake wrote:
> From 999f64b2615cd53504e4ad312f7a72eb2170da5f Mon Sep 17 00:00:00 2001
> From: Strake <strake888 at gmail.com>
> Date: Sun, 18 Aug 2013 09:29:51 -0500
> Subject: [PATCH] add u?mount
>
Good start, but I'd suggest looking at Rob's mount.c for a guide to
what is needed. (There's also some tricks that reduce size in there.)
If only I could find it on the archive; I'm sure it's there, but
google isn't finding it and that email account is dead.
But see these:
http://landley.net/notes-2012.html#09-08-2012
https://lkml.org/lkml/2012/8/12/134
> ---
> toys/pending/mount.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++
> toys/pending/umount.c | 27 +++++++++++++++
> 2 files changed, 121 insertions(+)
> create mode 100644 toys/pending/mount.c
> create mode 100644 toys/pending/umount.c
>
> diff --git a/toys/pending/mount.c b/toys/pending/mount.c
> new file mode 100644
> index 0000000..3b666ea
> --- /dev/null
> +++ b/toys/pending/mount.c
> @@ -0,0 +1,94 @@
> +/* mount.c - mount filesystem
> + *
> + * Copyright 2013 Strake <strake888 at gmail.com>
> + *
> + * See http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/mount.html
> +
> +USE_MOUNT(NEWTOY(mount, "o*t:", TOYFLAG_BIN))
> +
> +config MOUNT
> + bool "mount"
> + default n
> + help
> + usage: mount -t TYPE DEVICE DIR
> +
> + mount the filesystem of TYPE on DEVICE onto DIR.
> +*/
> +
> +#define FOR_mount
> +#include "toys.h"
> +
> +GLOBALS(
> + char *t;
> + struct arg_list *o;
> +)
> +
> +struct optkv {
> + char *k;
> + long v;
> +};
> +
> +struct optkv mount_options[] = {
> + { "bind", MS_BIND },
> + { "dirsync", MS_DIRSYNC },
> + { "mandlock", MS_MANDLOCK },
> + { "move", MS_MOVE },
> + { "atime", ~MS_NOATIME },
> + { "dev", ~MS_NODEV },
> + { "diratime", ~MS_NODIRATIME },
> + { "exec", ~MS_NOEXEC },
> + { "suid", ~MS_NOSUID },
> + { "rdonly", MS_RDONLY },
> + { "relatime", MS_RELATIME },
> + { "silent", MS_SILENT },
> + { "strictatime", MS_STRICTATIME },
> + { "sync", MS_SYNC },
> + { 0 }
> +};
> +
> +long findmountopt (char *o) {
> + int ii;
> + long v = 0;
> +
> + if (strncmp (o, "no", 2) == 0) {
> + v = -1;
> + o += 2;
> + }
> +
> + for (ii = 0; mount_options[ii].k; ii++) if (strcmp (o,
> mount_options[ii].k) == 0) return (v ^ mount_options[ii].v);
> + return 0;
> +}
Here Rob's version uses the index in place of a struct with a long:
// These entries are in the order the corresponding linux vfs bits occur in.
static char *vfsflags[] = {
"ro", "nosuid", "nodev", "noexec", "sync", "remount", "mand", "dirsync",
"", "", "noatime", "nodiratime", "bind", "move", "rec", "silent",
"", "unbindable", "private", "slave", "shared", "relatime",
"", "iversion", "strictatime"
};
...
Note the support for private, slave, and remount.
Loopback support is also nice.
> +
> +void mount_main () {
> + char *fsopts;
> + long mountflags = 0;
> +
> + fsopts = 0;
> + for (; TT.o; TT.o = TT.o -> next) {
> + char *o, *p;
> + for (o = TT.o -> arg; o; o = p) {
> + p = strchr (o, ',');
> + if (p) p[0] = 0;
> + long flag = findmountopt (o);
> + if (flag < 0) mountflags &= flag;
> + if (flag > 0) mountflags |= flag;
> + if (flag == 0) {
> + if (fsopts) fsopts = xastrcat (fsopts, ",");
> + fsopts = xastrcat (fsopts, o);
> + }
> + if (p) p++[0] = ',';
> + }
> + }
> +
> + switch (toys.optc) {
> + case 0:
> + xsendfile (xopen ("/proc/self/mounts", O_RDONLY), 1);
> + break;
> + case 2:
> + if (!(toys.optflags & FLAG_t)) error_exit ("usage: mount -t TYPE
> DEVICE DIR");
> + if (mount (toys.optargs[0], toys.optargs[1], TT.t, mountflags,
> fsopts) < 0) perror_exit ("can't mount -t %s %s %s", TT.t,
> toys.optargs[0], toys.optargs[1]);
> + break;
> + default:
> + error_exit ("usage: mount -t TYPE DEVICE DIR");
> + }
> +}
> diff --git a/toys/pending/umount.c b/toys/pending/umount.c
> new file mode 100644
> index 0000000..dd7bc53
> --- /dev/null
> +++ b/toys/pending/umount.c
> @@ -0,0 +1,27 @@
> +/* umount.c - umount filesystem
> + *
> + * Copyright 2013 CE Strake <strake888 at gmail.com>
> + *
> + * See http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/umount.html
> +
> +USE_UMOUNT(NEWTOY(umount, "", TOYFLAG_BIN))
> +
> +config UMOUNT
> + bool "umount"
> + default n
> + help
> + usage: umount DIR...
> +
> + unmount filesystem on DIR.
> +*/
> +
> +#define FOR_umount
> +#include "toys.h"
> +
> +void umount_main () {
> + int ii;
> + for (ii = 0; toys.optargs[ii]; ii++) if (umount (toys.optargs[ii]) < 0) {
> + error_msg ("can't umount %s", toys.optargs[ii]);
> + toys.exitval++;
> + }
> +}
> --
> 1.7.11.1
> _______________________________________________
> Toybox mailing list
> Toybox at lists.landley.net
> http://lists.landley.net/listinfo.cgi/toybox-landley.net
1376840604.0
More information about the Toybox
mailing list