]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
tools/fw_env: use fsync to ensure that data is physically stored
authorMichael Heimpold <mhei@heimpold.de>
Mon, 20 May 2013 19:34:42 +0000 (21:34 +0200)
committerTom Rini <trini@konsulko.com>
Sat, 22 Jul 2017 19:36:16 +0000 (15:36 -0400)
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>
tools/env/fw_env.c

index 286165618304f9259daadde0c8262f10265539ca..c9c79e066dc1282a57baadb6249df937f0ff1ab2 100644 (file)
@@ -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",