summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2012-02-19 18:22:04 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2012-03-18 15:03:26 +0100
commitb5e5b06d8bf87908a5c4bec87e751ee2681cad4f (patch)
treeaed701ab0ed8be47f39c24c880dc14086fe9e097 /commands
parentb55fbf7f5f14a8a60b4f5bdf1416c25fc4d3e59d (diff)
downloadbarebox-b5e5b06d8bf87908a5c4bec87e751ee2681cad4f.tar.gz
barebox-b5e5b06d8bf87908a5c4bec87e751ee2681cad4f.tar.xz
Add automount support
This patch adds an automount command which makes it possible to execute a script when a certain directory is first accessed. It's the commands responsibility to make this directory available (bringing devices up and mounting it). This results in automount support which makes sure that from the shell every file can be accessed without having to care for device bringup. Bringing up devices may be expensive (USB, dhcp). The automount support makes it easy for the environment to bringup devices when they are actually needed. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r--commands/Kconfig10
-rw-r--r--commands/Makefile1
-rw-r--r--commands/automount.c66
3 files changed, 77 insertions, 0 deletions
diff --git a/commands/Kconfig b/commands/Kconfig
index e332a85f1f..7a8811e92f 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -181,6 +181,16 @@ config CMD_NANDTEST
select PARTITION_NEED_MTD
prompt "nandtest"
+config CMD_AUTOMOUNT
+ tristate
+ select FS_AUTOMOUNT
+ prompt "automount"
+ help
+ automount allows it to automatically execute a script when a certain
+ directory is accessed for the first time. The script should then make
+ this directory available (discover USB devices, bring network interface
+ up and finally mount the filesystem).
+
endmenu
menu "console "
diff --git a/commands/Makefile b/commands/Makefile
index 31442b5ad4..f02b5cac3a 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -64,3 +64,4 @@ obj-$(CONFIG_CMD_OFTREE) += oftree.o
obj-$(CONFIG_CMD_MAGICVAR) += magicvar.o
obj-$(CONFIG_CMD_IOMEM) += iomem.o
obj-$(CONFIG_CMD_LINUX_EXEC) += linux_exec.o
+obj-$(CONFIG_CMD_AUTOMOUNT) += automount.o
diff --git a/commands/automount.c b/commands/automount.c
new file mode 100644
index 0000000000..5fc68f3cb4
--- /dev/null
+++ b/commands/automount.c
@@ -0,0 +1,66 @@
+/*
+ * automount.c - automount devices
+ *
+ * Copyright (c) 2012 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation.
+ */
+#include <common.h>
+#include <command.h>
+#include <fs.h>
+#include <errno.h>
+#include <getopt.h>
+
+static int do_automount(int argc, char *argv[])
+{
+ int opt, ret;
+
+ while ((opt = getopt(argc, argv, "lr:")) > 0) {
+ switch (opt) {
+ case 'l':
+ automount_print();
+ return 0;
+ case 'r':
+ automount_remove(optarg);
+ return 0;
+ }
+ }
+
+ if (argc != 3)
+ return COMMAND_ERROR_USAGE;
+
+ ret = automount_add(argv[1], argv[2]);
+ if (ret)
+ printf("adding automountpoint failed: %s\n",
+ strerror(-ret));
+
+ return ret ? 1 : 0;
+}
+
+BAREBOX_CMD_HELP_START(automount)
+BAREBOX_CMD_HELP_USAGE("automount [OPTIONS] <PATH> <cmd>\n")
+BAREBOX_CMD_HELP_SHORT("execute <cmd> when <PATH> is first accessed\n")
+BAREBOX_CMD_HELP_OPT("-l", "List currently registered automountpoints\n")
+BAREBOX_CMD_HELP_OPT("-r <PATH>", "remove an automountpoint\n")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(automount)
+ .cmd = do_automount,
+ .usage = "automount [OPTIONS] <PATH> <cmd>\n",
+ BAREBOX_CMD_HELP(cmd_automount_help)
+BAREBOX_CMD_END
+