From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 2/6] env: erase/protect in envfs_save
Date: Mon, 28 Apr 2014 11:49:35 +0200 [thread overview]
Message-ID: <1398678579-17491-2-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1398678579-17491-1-git-send-email-s.hauer@pengutronix.de>
So that the envfs_save is more useful outside of the saveenv command
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/saveenv.c | 46 +---------------------------------------------
common/environment.c | 38 ++++++++++++++++++++++++++++++++++++--
2 files changed, 37 insertions(+), 47 deletions(-)
diff --git a/commands/saveenv.c b/commands/saveenv.c
index 8ead98d..cb2b01d 100644
--- a/commands/saveenv.c
+++ b/commands/saveenv.c
@@ -29,7 +29,7 @@
static int do_saveenv(int argc, char *argv[])
{
- int ret, fd;
+ int ret;
char *filename, *dirname;
printf("saving environment\n");
@@ -42,52 +42,8 @@ static int do_saveenv(int argc, char *argv[])
else
filename = argv[1];
- fd = open(filename, O_WRONLY | O_CREAT);
- if (fd < 0) {
- printf("could not open %s: %s\n", filename, errno_str());
- return 1;
- }
-
- 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());
- close(fd);
- return 1;
- }
-
- 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 1;
- }
-
- close(fd);
-
ret = envfs_save(filename, dirname);
- if (ret) {
- printf("saveenv failed\n");
- goto out;
- }
-
- fd = open(filename, O_WRONLY | O_CREAT);
-
- ret = protect(fd, ~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());
- close(fd);
- return 1;
- }
- ret = 0;
-out:
- close(fd);
return ret;
}
diff --git a/common/environment.c b/common/environment.c
index e55df40..2d1edf8 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:
--
1.9.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2014-04-28 9:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-28 9:49 [PATCH 1/6] environment: drop envfs_register_partition Sascha Hauer
2014-04-28 9:49 ` Sascha Hauer [this message]
2014-04-28 9:49 ` [PATCH 3/6] mtd: nand: bb: use mtd api directly Sascha Hauer
2014-04-28 13:05 ` Alexander Aring
2014-04-28 18:48 ` Sascha Hauer
2014-04-28 9:49 ` [PATCH 4/6] mtd: refactor bb device creation Sascha Hauer
2014-04-28 9:49 ` [PATCH 5/6] mtd: nand: create bb devices automatically Sascha Hauer
2014-04-28 9:49 ` [PATCH 6/6] OF: barebox-env: Use bb device on NAND Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1398678579-17491-2-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox