diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2014-04-09 12:14:06 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2014-04-28 11:41:02 +0200 |
commit | ebb8a4b59466dd366b6a04e3684e114a02cd8234 (patch) | |
tree | 24baffb61013372c002953815a64b995c14ee258 /common | |
parent | 54bea204e298daea8ea545c03f278fe3e778198c (diff) | |
download | barebox-ebb8a4b59466dd366b6a04e3684e114a02cd8234.tar.gz barebox-ebb8a4b59466dd366b6a04e3684e114a02cd8234.tar.xz |
env: erase/protect in envfs_save
So that the envfs_save is more useful outside of the saveenv command
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r-- | common/environment.c | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/common/environment.c b/common/environment.c index e55df401dc..2d1edf8381 100644 --- a/common/environment.c +++ b/common/environment.c @@ -60,6 +60,16 @@ char *default_environment_path_get(void) { return default_environment_path; } +#else +static inline int protect(int fd, size_t count, unsigned long offset, int prot) +{ + return 0; +} + +static inline int erase(int fd, size_t count, unsigned long offset) +{ + return 0; +} #endif static int file_size_action(const char *filename, struct stat *statbuf, @@ -196,11 +206,27 @@ int envfs_save(const char *filename, const char *dirname) envfd = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); if (envfd < 0) { - printf("Open %s %s\n", filename, errno_str()); - ret = envfd; + printf("could not open %s: %s\n", filename, errno_str()); + ret = -errno; goto out1; } + ret = protect(envfd, ~0, 0, 0); + + /* ENOSYS is no error here, many devices do not need it */ + if (ret && errno != ENOSYS) { + printf("could not unprotect %s: %s\n", filename, errno_str()); + goto out; + } + + ret = erase(envfd, ~0, 0); + + /* ENOSYS is no error here, many devices do not need it */ + if (ret && errno != ENOSYS) { + printf("could not erase %s: %s\n", filename, errno_str()); + goto out; + } + size += sizeof(struct envfs_super); wbuf = buf; @@ -216,6 +242,14 @@ int envfs_save(const char *filename, const char *dirname) size -= now; } + ret = protect(envfd, ~0, 0, 1); + + /* ENOSYS is no error here, many devices do not need it */ + if (ret && errno != ENOSYS) { + printf("could not protect %s: %s\n", filename, errno_str()); + goto out; + } + ret = 0; out: |