From: Michael Heimpold <mhei@heimpold.de>
Date: Mon, 20 May 2013 19:34:42 +0000 (+0200)
Subject: tools/fw_env: use fsync to ensure that data is physically stored
X-Git-Tag: v2025.01-rc5-pxa1908~6351
X-Git-Url: http://git.dujemihanovic.xyz/browse.php?a=commitdiff_plain;h=7e99e14d4ba2533a07adc3d97e06cadc41d12908;p=u-boot.git

tools/fw_env: use fsync to ensure that data is physically stored

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@heimpold.de>
---

diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 2861656183..c9c79e066d 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -1088,7 +1088,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",