summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2012-11-29 20:22:58 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2012-11-29 20:23:04 +0100
commit1533521bff4121dcd8dc37ef34fd09fc6a5018fb (patch)
treecaeca762cedb4772b651b23d4e92853008633a72 /common
parent5a9d53c47e3c6ce5bc7d38c60501a37ce2c2b276 (diff)
downloadbarebox-1533521bff4121dcd8dc37ef34fd09fc6a5018fb.tar.gz
barebox-1533521bff4121dcd8dc37ef34fd09fc6a5018fb.tar.xz
loadenv: allow more fine grained environment loading
This implements two new options for the loadenv command: -s: removes (scrubs) old directory contents to be able to create a fresh environment from for example /dev/defaultenv -n: no overwrite. Do not overwrite existing files. This allows to keep parts of the old environment. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r--common/environment.c12
-rw-r--r--common/startup.c4
2 files changed, 12 insertions, 4 deletions
diff --git a/common/environment.c b/common/environment.c
index 69c4c0aa76..e11cd9dd47 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -206,7 +206,7 @@ EXPORT_SYMBOL(envfs_save);
* Note: This function will also be used on the host! See note in the header
* of this file.
*/
-int envfs_load(char *filename, char *dir)
+int envfs_load(char *filename, char *dir, unsigned flags)
{
struct envfs_super super;
void *buf = NULL, *buf_free = NULL;
@@ -316,6 +316,14 @@ int envfs_load(char *filename, char *dir)
}
free(str);
} else {
+ struct stat s;
+
+ if (flags & ENV_FLAG_NO_OVERWRITE &&
+ !stat(str, &s)) {
+ printf("skip %s\n", str);
+ goto skip;
+ }
+
fd = open(str, O_WRONLY | O_CREAT | O_TRUNC, 0644);
free(str);
if (fd < 0) {
@@ -333,7 +341,7 @@ int envfs_load(char *filename, char *dir)
}
close(fd);
}
-
+skip:
buf += PAD4(inode_size);
size -= headerlen_full + PAD4(inode_size) +
sizeof(struct envfs_inode);
diff --git a/common/startup.c b/common/startup.c
index 7bb3c73c12..14409a217d 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -108,12 +108,12 @@ void start_barebox (void)
debug("initcalls done\n");
#ifdef CONFIG_ENV_HANDLING
- if (envfs_load(default_environment_path, "/env")) {
+ if (envfs_load(default_environment_path, "/env", 0)) {
#ifdef CONFIG_DEFAULT_ENVIRONMENT
printf("no valid environment found on %s. "
"Using default environment\n",
default_environment_path);
- envfs_load("/dev/defaultenv", "/env");
+ envfs_load("/dev/defaultenv", "/env", 0);
#endif
}
#endif