BmapCreator: synchronize the image file before generating bmap
authorArtem Bityutskiy <artem.bityutskiy@intel.com>
Thu, 1 Nov 2012 08:54:36 +0000 (10:54 +0200)
committerArtem Bityutskiy <artem.bityutskiy@intel.com>
Thu, 1 Nov 2012 13:14:45 +0000 (15:14 +0200)
To make sure the block map is correct.

Change-Id: Ic486edf22b2d986117faf9f53997d78fc589b9fd
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
bmaptools/BmapCreator.py

index ba64f2c..cb1ccf2 100644 (file)
@@ -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