[PATCH 3/5] Add generic routine for environment partition handling
Juergen Beisert
jbe at pengutronix.de
Wed Mar 9 10:17:24 EST 2011
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
Acked-by: Juergen Beisert <jbe at pengutronix.de>
---
common/environment.c | 34 ++++++++++++++++++++++++++++++++++
include/environment.h | 1 +
2 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/common/environment.c b/common/environment.c
index eb8278f..3270a08 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -93,6 +93,40 @@ out:
return 1;
}
+#ifdef __BAREBOX__
+int file_check_and_erase(char *filename)
+{
+ int fd;
+ int ret;
+
+ fd = open(filename, O_WRONLY | O_CREAT);
+ if (fd < 0) {
+ printf("could not open %s: %s\n", filename, errno_str());
+ return errno;
+ }
+
+ ret = protect(fd, ~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());
+ return errno;
+ }
+
+ ret = erase(fd, ~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());
+ close(fd);
+ return errno;
+ }
+
+ close(fd);
+ return 0;
+}
+#endif /* __BAREBOX__ */
+
/**
* Make the current environment persistent
* @param[in] filename where to store
diff --git a/include/environment.h b/include/environment.h
index 2b1f5d9..b2b95e0 100644
--- a/include/environment.h
+++ b/include/environment.h
@@ -58,6 +58,7 @@ int export(const char *);
struct stat;
int file_size_action(const char *, struct stat *, void *, int);
int file_save_action(const char *, struct stat *, void *, int);
+int file_check_and_erase(char *filename);
#endif /* __BAREBOX__ */
--
1.7.2.3
More information about the barebox
mailing list