Add an unmount helper
authorBarret Rhoden <brho@cs.berkeley.edu>
Wed, 7 Mar 2018 00:50:10 +0000 (16:50 -0800)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 28 Mar 2018 20:43:05 +0000 (16:43 -0400)
Should we make a symlink to it called 'umount'?

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
tests/unmount.c [new file with mode: 0644]

diff --git a/tests/unmount.c b/tests/unmount.c
new file mode 100644 (file)
index 0000000..542ca14
--- /dev/null
@@ -0,0 +1,45 @@
+#define _LARGEFILE64_SOURCE /* needed to use lseek64 */
+
+#include <stdio.h> 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <parlib/arch/arch.h>
+#include <unistd.h>
+#include <errno.h>
+#include <dirent.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ros/syscall.h>
+
+/* The naming for the args in bind is messy historically.  We do:
+ *             bind src_path onto_path
+ * plan9 says bind NEW OLD, where new is *src*, and old is *onto*.
+ * Linux says mount --bind OLD NEW, where OLD is *src* and NEW is *onto*.
+ *
+ * For unmount, we use the same names as for bind. */
+int main(int argc, char *argv[]) 
+{ 
+       int ret;
+       int flag = 0;
+       char *src_path, *onto_path;
+
+       switch (argc) {
+       case 3:
+               src_path = argv[1];
+               onto_path = argv[2];
+               break;
+       case 2:
+               src_path = NULL;
+               onto_path = argv[1];
+               break;
+       default:
+               fprintf(stderr, "usage: unmount [src_path] onto_path\n");
+               exit(1);
+       }
+       ret = syscall(SYS_nunmount, src_path, src_path ? strlen(src_path) : 0,
+                     onto_path, strlen(onto_path));
+       if (ret < 0)
+               perror("Unmount failed");
+       return ret;
+}