diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2012-02-19 18:22:04 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2012-03-18 15:03:26 +0100 |
commit | b5e5b06d8bf87908a5c4bec87e751ee2681cad4f (patch) | |
tree | aed701ab0ed8be47f39c24c880dc14086fe9e097 /commands/automount.c | |
parent | b55fbf7f5f14a8a60b4f5bdf1416c25fc4d3e59d (diff) | |
download | barebox-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/automount.c')
-rw-r--r-- | commands/automount.c | 66 |
1 files changed, 66 insertions, 0 deletions
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 + |