mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] automount work
@ 2012-04-15 14:51 Sascha Hauer
  2012-04-15 14:51 ` [PATCH 1/4] automount: Pass automount pass as environment variable Sascha Hauer
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Sascha Hauer @ 2012-04-15 14:51 UTC (permalink / raw)
  To: barebox

Some patches for the new automount support

----------------------------------------------------------------
Sascha Hauer (4):
      automount: Pass automount pass as environment variable
      automount: fix argument parsing
      automount: optionally make directory
      automount: remove existing automountpoint

 commands/automount.c |   17 +++++++++++++----
 fs/fs.c              |   15 +++++++++++----
 2 files changed, 24 insertions(+), 8 deletions(-)

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] automount: Pass automount pass as environment variable
  2012-04-15 14:51 [PATCH] automount work Sascha Hauer
@ 2012-04-15 14:51 ` Sascha Hauer
  2012-04-15 14:51 ` [PATCH 2/4] automount: fix argument parsing Sascha Hauer
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2012-04-15 14:51 UTC (permalink / raw)
  To: barebox

This makes it possible to pass a command sequence to the automount
command instead of only a script (a command sequence would get confused
by the additional argument)

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/fs.c |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index 24ef258..64997cc 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -31,6 +31,8 @@
 #include <init.h>
 #include <module.h>
 #include <libbb.h>
+#include <magicvar.h>
+#include <environment.h>
 
 void *read_file(const char *filename, size_t *size)
 {
@@ -289,7 +291,6 @@ static void automount_mount(const char *path, int instat)
 	int ret;
 
 	list_for_each_entry(am, &automount_list, list) {
-		char *cmd;
 		int len_path = strlen(path);
 		int len_am_path = strlen(am->path);
 
@@ -312,9 +313,10 @@ static void automount_mount(const char *path, int instat)
 		if (*(path + len_am_path) != 0 && *(path + len_am_path) != '/')
 			continue;
 
-		cmd = asprintf("%s %s", am->cmd, am->path);
-		ret = run_command(cmd, 0);
-		free(cmd);
+		setenv("automount_path", am->path);
+		export("automount_path");
+		ret = run_command(am->cmd, 0);
+		setenv("automount_path", NULL);
 
 		if (ret)
 			printf("running automount command '%s' failed\n",
@@ -325,6 +327,9 @@ static void automount_mount(const char *path, int instat)
 		return;
 	}
 }
+
+BAREBOX_MAGICVAR(automount_path, "mountpath passed to automount scripts");
+
 #else
 static void automount_mount(const char *path, int instat)
 {
-- 
1.7.10


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/4] automount: fix argument parsing
  2012-04-15 14:51 [PATCH] automount work Sascha Hauer
  2012-04-15 14:51 ` [PATCH 1/4] automount: Pass automount pass as environment variable Sascha Hauer
@ 2012-04-15 14:51 ` Sascha Hauer
  2012-04-15 14:51 ` [PATCH 3/4] automount: optionally make directory Sascha Hauer
  2012-04-15 14:51 ` [PATCH 4/4] automount: remove existing automountpoint Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2012-04-15 14:51 UTC (permalink / raw)
  To: barebox

With getopt we have to use argv[optind] instead of hardcoded argv[0]

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/automount.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/commands/automount.c b/commands/automount.c
index 5fc68f3..8c0e4de 100644
--- a/commands/automount.c
+++ b/commands/automount.c
@@ -40,10 +40,10 @@ static int do_automount(int argc, char *argv[])
 		}
 	}
 
-	if (argc != 3)
+	if (optind + 2 != argc)
 		return COMMAND_ERROR_USAGE;
 
-	ret = automount_add(argv[1], argv[2]);
+	ret = automount_add(argv[optind], argv[optind + 1]);
 	if (ret)
 		printf("adding automountpoint failed: %s\n",
 				strerror(-ret));
-- 
1.7.10


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/4] automount: optionally make directory
  2012-04-15 14:51 [PATCH] automount work Sascha Hauer
  2012-04-15 14:51 ` [PATCH 1/4] automount: Pass automount pass as environment variable Sascha Hauer
  2012-04-15 14:51 ` [PATCH 2/4] automount: fix argument parsing Sascha Hauer
@ 2012-04-15 14:51 ` Sascha Hauer
  2012-04-15 14:51 ` [PATCH 4/4] automount: remove existing automountpoint Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2012-04-15 14:51 UTC (permalink / raw)
  To: barebox

Add an option to create the mount path to make using this command easier.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/automount.c |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/commands/automount.c b/commands/automount.c
index 8c0e4de..aa1e417 100644
--- a/commands/automount.c
+++ b/commands/automount.c
@@ -27,9 +27,9 @@
 
 static int do_automount(int argc, char *argv[])
 {
-	int opt, ret;
+	int opt, ret, make_dir = 0;
 
-	while ((opt = getopt(argc, argv, "lr:")) > 0) {
+	while ((opt = getopt(argc, argv, "lr:d")) > 0) {
 		switch (opt) {
 		case 'l':
 			automount_print();
@@ -37,12 +37,21 @@ static int do_automount(int argc, char *argv[])
 		case 'r':
 			automount_remove(optarg);
 			return 0;
+		case 'd':
+			make_dir = 1;
+			break;
 		}
 	}
 
 	if (optind + 2 != argc)
 		return COMMAND_ERROR_USAGE;
 
+	if (make_dir) {
+		ret = make_directory(argv[optind]);
+		if (ret)
+			return ret;
+	}
+
 	ret = automount_add(argv[optind], argv[optind + 1]);
 	if (ret)
 		printf("adding automountpoint failed: %s\n",
-- 
1.7.10


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 4/4] automount: remove existing automountpoint
  2012-04-15 14:51 [PATCH] automount work Sascha Hauer
                   ` (2 preceding siblings ...)
  2012-04-15 14:51 ` [PATCH 3/4] automount: optionally make directory Sascha Hauer
@ 2012-04-15 14:51 ` Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2012-04-15 14:51 UTC (permalink / raw)
  To: barebox

Before creating a new mountpoint on an already existing mountpoint
we have to remove it.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/fs.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/fs.c b/fs/fs.c
index 64997cc..04dace4 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -259,6 +259,8 @@ int automount_add(const char *path, const char *cmd)
 	am->path = normalise_path(path);
 	am->cmd = xstrdup(cmd);
 
+	automount_remove(am->path);
+
 	ret = stat(path, &s);
 	if (!ret) {
 		/*
-- 
1.7.10


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-04-15 14:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-15 14:51 [PATCH] automount work Sascha Hauer
2012-04-15 14:51 ` [PATCH 1/4] automount: Pass automount pass as environment variable Sascha Hauer
2012-04-15 14:51 ` [PATCH 2/4] automount: fix argument parsing Sascha Hauer
2012-04-15 14:51 ` [PATCH 3/4] automount: optionally make directory Sascha Hauer
2012-04-15 14:51 ` [PATCH 4/4] automount: remove existing automountpoint Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox