[Toybox] [PATCH 1/3] mount: implement -T

Isaac Dunham ibid.ag at gmail.com
Sat Mar 28 13:38:12 PDT 2015


mount: implement -T
---
 toys/lsb/mount.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/toys/lsb/mount.c b/toys/lsb/mount.c
index 4d6679d..094b535 100644
--- a/toys/lsb/mount.c
+++ b/toys/lsb/mount.c
@@ -6,14 +6,14 @@
  * Note: -hV is bad spec, haven't implemented -FsLU yet
  * no mtab (/proc/mounts does it) so -n is NOP.
 
-USE_MOUNT(NEWTOY(mount, "?O:afnrvwt:o*[-rw]", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_STAYROOT))
+USE_MOUNT(NEWTOY(mount, "?T(fstab):O:afnrvwt:o*[-rw]", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_STAYROOT))
 //USE_NFSMOUNT(NEWTOY(nfsmount, "?<2>2", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_STAYROOT))
 
 config MOUNT
   bool "mount"
   default y
   help
-    usage: mount [-afFrsvw] [-t TYPE] [-o OPTIONS...] [[DEVICE] DIR]
+    usage: mount [-afFrsvw] [-t TYPE] [-T FSTAB] [-o OPTIONS...] [[DEVICE] DIR]
 
     Mount new filesystem(s) on directories. With no arguments, display existing
     mounts.
@@ -24,6 +24,7 @@ config MOUNT
     -r	read only (same as -o ro)
     -w	read/write (default, same as -o rw)
     -t	specify filesystem type
+    -T	read FSTAB (default /etc/fstab)
     -v	verbose
 
     OPTIONS is a comma separated list of options, which can also be supplied
@@ -50,6 +51,7 @@ GLOBALS(
   struct arg_list *optlist;
   char *type;
   char *bigO;
+  char *fstab;
 
   unsigned long flags;
   char *opts;
@@ -256,6 +258,9 @@ void mount_main(void)
 // -o parsed after fstab options
 // test if mountpoint already exists (-o noremount?)
 
+  if (TT.fstab && getuid()) perror_exit("only root can use -T");
+  if (!TT.fstab) TT.fstab = "/etc/fstab";
+
   // First pass; just accumulate string, don't parse flags yet. (This is so
   // we can modify fstab entries with -a, or mtab with remount.)
   for (o = TT.optlist; o; o = o->next) comma_collate(&opts, o->arg);
@@ -288,7 +293,7 @@ void mount_main(void)
   // Do we need to do an /etc/fstab trawl?
   // This covers -a, -o remount, one argument, all user mounts
   if ((toys.optflags & FLAG_a) || (dev && (!dir || getuid() || remount))) {
-    if (!remount) dlist_terminate(mtl = xgetmountlist("/etc/fstab"));
+    if (!remount) dlist_terminate(mtl = xgetmountlist(TT.fstab));
 
     for (mm = remount ? remount : mtl; mm; mm = (remount ? mm->prev : mm->next))
     {
-- 
2.1.4


 1427575092.0


More information about the Toybox mailing list