mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Juergen Beisert <jbe@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 3/5] Add generic routine for environment partition handling
Date: Wed,  9 Mar 2011 16:17:24 +0100	[thread overview]
Message-ID: <1299683846-20616-4-git-send-email-jbe@pengutronix.de> (raw)
In-Reply-To: <1299683846-20616-1-git-send-email-jbe@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Acked-by: Juergen Beisert <jbe@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


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2011-03-09 15:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-09 15:17 [RFC] Support multiple environments in barebox Juergen Beisert
2011-03-09 15:17 ` [PATCH 1/5] Move environment handling out from the main routine Juergen Beisert
2011-03-09 15:17 ` [PATCH 2/5] CRC value handling and dry run mode in 'envfs_load' Juergen Beisert
2011-03-09 15:17 ` Juergen Beisert [this message]
2011-03-09 15:17 ` [PATCH 4/5] Add multi environment support Juergen Beisert
2011-03-09 15:17 ` [PATCH 5/5] " Juergen Beisert
2011-08-14  6:09   ` Boaz Ben-David
2011-08-14  6:12   ` Boaz Ben-David

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=1299683846-20616-4-git-send-email-jbe@pengutronix.de \
    --to=jbe@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