diff options
author | Juergen Borleis <jbe@pengutronix.de> | 2014-07-31 12:39:02 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2014-08-01 08:24:00 +0200 |
commit | 72ce27f8e02524170a922d2f6a6c73c5e4b5b5cd (patch) | |
tree | 51f5a8b71d1f24eac2bb38f18cdbf4f0be435384 | |
parent | c4c7b16588d22d99b7b9047fa0d0e1d8cb530774 (diff) | |
download | barebox-72ce27f8e02524170a922d2f6a6c73c5e4b5b5cd.tar.gz barebox-72ce27f8e02524170a922d2f6a6c73c5e4b5b5cd.tar.xz |
envfs: change API to be able to forward special flags into the envfs superblock
In order to be able to mark an stored envfs image with special features
(intentional ignore for example), we now can feed forward these flags.
By forwarding a '0' for the flags nothing changes because the envfs superblock
was already allocated with xzalloc.
Signed-off-by: Juergen Borleis <jbe@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | commands/saveenv.c | 2 | ||||
-rw-r--r-- | common/environment.c | 24 | ||||
-rw-r--r-- | include/envfs.h | 2 | ||||
-rw-r--r-- | scripts/bareboxenv.c | 2 |
4 files changed, 19 insertions, 11 deletions
diff --git a/commands/saveenv.c b/commands/saveenv.c index 29a29c19a5..178b783a0c 100644 --- a/commands/saveenv.c +++ b/commands/saveenv.c @@ -37,7 +37,7 @@ static int do_saveenv(int argc, char *argv[]) else filename = argv[1]; - ret = envfs_save(filename, dirname); + ret = envfs_save(filename, dirname, 0); return ret; } diff --git a/common/environment.c b/common/environment.c index 8c4882c59b..e55c7b7417 100644 --- a/common/environment.c +++ b/common/environment.c @@ -167,12 +167,13 @@ out: * Make the current environment persistent * @param[in] filename where to store * @param[in] dirname what to store (all files in this dir) + * @param[in] flags superblock flags (refer ENVFS_FLAGS_* macros) * @return 0 on success, anything else in case of failure * * Note: This function will also be used on the host! See note in the header * of this file. */ -int envfs_save(const char *filename, const char *dirname) +int envfs_save(const char *filename, const char *dirname, unsigned flags) { struct envfs_super *super; int envfd, size, ret; @@ -182,11 +183,15 @@ int envfs_save(const char *filename, const char *dirname) data.writep = NULL; data.base = dirname; - /* first pass: calculate size */ - recursive_action(dirname, ACTION_RECURSE, file_size_action, - NULL, &data, 0); + if (flags & ENVFS_FLAGS_FORCE_BUILT_IN) { + size = 0; /* force no content */ + } else { + /* first pass: calculate size */ + recursive_action(dirname, ACTION_RECURSE, file_size_action, + NULL, &data, 0); - size = (unsigned long)data.writep; + size = (unsigned long)data.writep; + } buf = xzalloc(size + sizeof(struct envfs_super)); data.writep = buf + sizeof(struct envfs_super); @@ -196,10 +201,13 @@ int envfs_save(const char *filename, const char *dirname) super->major = ENVFS_MAJOR; super->minor = ENVFS_MINOR; super->size = ENVFS_32(size); + super->flags = ENVFS_32(flags); - /* second pass: copy files to buffer */ - recursive_action(dirname, ACTION_RECURSE, file_save_action, - NULL, &data, 0); + if (!(flags & ENVFS_FLAGS_FORCE_BUILT_IN)) { + /* second pass: copy files to buffer */ + recursive_action(dirname, ACTION_RECURSE, file_save_action, + NULL, &data, 0); + } super->crc = ENVFS_32(crc32(0, buf + sizeof(struct envfs_super), size)); super->sb_crc = ENVFS_32(crc32(0, buf, sizeof(struct envfs_super) - 4)); diff --git a/include/envfs.h b/include/envfs.h index beae38acf5..fdcb8a8d97 100644 --- a/include/envfs.h +++ b/include/envfs.h @@ -93,7 +93,7 @@ struct envfs_super { #define ENV_FLAG_NO_OVERWRITE (1 << 0) int envfs_load(const char *filename, const char *dirname, unsigned flags); -int envfs_save(const char *filename, const char *dirname); +int envfs_save(const char *filename, const char *dirname, unsigned flags); int envfs_load_from_buf(void *buf, int len, const char *dir, unsigned flags); /* defaults to /dev/env0 */ diff --git a/scripts/bareboxenv.c b/scripts/bareboxenv.c index da420db578..ec6ccfeadb 100644 --- a/scripts/bareboxenv.c +++ b/scripts/bareboxenv.c @@ -181,7 +181,7 @@ int main(int argc, char *argv[]) if (verbose) printf("saving contents of %s to file %s\n", dirname, filename); - err = envfs_save(filename, dirname); + err = envfs_save(filename, dirname, 0); if (verbose && err) printf("saving env failed: %d\n", err); |