From 75ec289a25a1f9ff079ad04f2ed92d07e33b3f90 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Thu, 1 Nov 2012 10:54:36 +0200 Subject: [PATCH] BmapCreator: synchronize the image file before generating bmap To make sure the block map is correct. Change-Id: Ic486edf22b2d986117faf9f53997d78fc589b9fd Signed-off-by: Artem Bityutskiy --- bmaptools/BmapCreator.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bmaptools/BmapCreator.py b/bmaptools/BmapCreator.py index ba64f2c..cb1ccf2 100644 --- a/bmaptools/BmapCreator.py +++ b/bmaptools/BmapCreator.py @@ -239,6 +239,18 @@ class BmapCreator: self._bmap_file_start() self._f_image.seek(0) + # Synchronize the image file before starting to generate its block map + try: + self._f_image.flush() + except IOError as err: + raise Error("cannot flush image file '%s': %s" \ + % (self._image_path, err), err.errno) + try: + os.fsync(self._f_image.fileno()), + except OSError as err: + raise Error("cannot synchronize image file '%s': %s " \ + % (self._image_path, err.strerror), err.errno) + # Generate the block map and write it to the XML block map # file as we go. self.bmap_mapped_cnt = 0 -- 2.7.4