From patchwork Mon May 20 19:34:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Heimpold X-Patchwork-Id: 245097 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id D7DF52C00A3 for ; Tue, 21 May 2013 05:35:52 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 496E74A109; Mon, 20 May 2013 21:35:49 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gVA5JdmT0DZw; Mon, 20 May 2013 21:35:49 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E2C504A102; Mon, 20 May 2013 21:35:46 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CF06F4A102 for ; Mon, 20 May 2013 21:35:39 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8yMaVjXbty3D for ; Mon, 20 May 2013 21:35:33 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mo-p00-ob.rzone.de (mo-p00-ob.rzone.de [81.169.146.162]) by theia.denx.de (Postfix) with ESMTP id C60854A101 for ; Mon, 20 May 2013 21:35:26 +0200 (CEST) X-RZG-AUTH: :O2kGeEG7b/pS1EW8QnKjhhg/vO4pzqdNys2z+NfqLSUoNNCTudAAGuYMMopkvPcwtItn X-RZG-CLASS-ID: mo00 Received: from tonne.mhei.heimpold.itr (lpzg-4d059a75.pool.mediaWays.net [77.5.154.117]) by smtp.strato.de (josoe mo3) (RZmta 31.27 DYNA|AUTH) with ESMTPA id g06b37p4KHGNKE ; Mon, 20 May 2013 21:35:26 +0200 (CEST) Received: from kerker.mhei.heimpold.itr (kerker.mhei.heimpold.itr [192.168.8.1]) by tonne.mhei.heimpold.itr (Postfix) with ESMTP id 7027F2163B; Mon, 20 May 2013 21:35:24 +0200 (CEST) From: Michael Heimpold To: u-boot@lists.denx.de Date: Mon, 20 May 2013 21:34:42 +0200 Message-Id: <1369078482-5863-1-git-send-email-mhei@heimpold.de> X-Mailer: git-send-email 1.7.10.4 Subject: [U-Boot] [PATCH] tools/fw_env: use fsync to ensure that data is physically stored X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de 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 --- 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",