[U-Boot] [PATCH] tools/fw_env: use fsync to ensure that data is physically stored
Michael Heimpold
mhei at heimpold.de
Mon May 20 21:34:42 CEST 2013
Closing a file descriptor does not guarantee that the data has been
successfully saved to disk, as the kernel might defer the write.
Signed-off-by: Michael Heimpold <mhei at heimpold.de>
---
tools/env/fw_env.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 428e374..0420495 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -1033,7 +1033,19 @@ static int flash_io (int mode)
rc = flash_write (fd_current, fd_target, dev_target);
+ if (fsync (fd_current)) {
+ fprintf (stderr,
+ "fsync failed on %s: %s\n",
+ DEVNAME (dev_current), strerror (errno));
+ }
+
if (HaveRedundEnv) {
+ if (fsync (fd_target)) {
+ fprintf (stderr,
+ "fsync failed on %s: %s\n",
+ DEVNAME (dev_current), strerror (errno));
+ }
+
if (close (fd_target)) {
fprintf (stderr,
"I/O error on %s: %s\n",
--
1.7.10.4
More information about the U-Boot
mailing list