# The bmap format version we generate
SUPPORTED_BMAP_VERSION = "1.2"
+_BMAP_START_TEMPLATE = \
+"""<?xml version="1.0" ?>
+<!-- This file contains the block map for an image file, which is basically
+ a list of useful (mapped) block numbers in the image file. In other words,
+ it lists only those blocks which contain data (boot sector, partition
+ table, file-system metadata, files, directories, extents, etc). These
+ blocks have to be copied to the target device. The other blocks do not
+ contain any useful data and do not have to be copied to the target
+ device.
+
+ The block map an optimization which allows to copy or flash the image to
+ the image quicker than copying of flashing the entire image. This is
+ because with bmap less data is copied: <MappedBlocksCount> blocks instead
+ of <BlocksCount> blocks.
+
+ Besides the machine-readable data, this file contains useful commentaries
+ which contain human-readable information like image size, percentage of
+ mapped data, etc.
+
+ The 'version' attribute is the block map file format version in the
+ 'major.minor' format. The version major number is increased whenever an
+ incompatible block map format change is made. The minor number changes
+ in case of minor backward-compatible changes. -->
+
+<bmap version="%s">
+ <!-- Image size in bytes (%s) -->
+ <ImageSize> %u </ImageSize>
+
+ <!-- Size of a block in bytes -->
+ <BlockSize> %u </BlockSize>
+
+ <!-- Count of blocks in the image file -->
+ <BlocksCount> %u </BlocksCount>
+
+ <!-- The block map which consists of elements which may either be a
+ range of blocks or a single block. The 'sha1' attribute (if present)
+ is the SHA1 checksum of this blocks range. -->
+ <BlockMap>"""
+
class Error(Exception):
""" A class for exceptions generated by the 'BmapCreate' module. We
currently support only one type of exceptions, and we basically throw
""" A helper function which generates the starting contents of the
block map file: the header comment, image size, block size, etc. """
- xml = "<?xml version=\"1.0\" ?>\n\n"
- xml += "<!-- This file contains block map for an image file. The block map\n"
- xml += " is basically a list of block numbers in the image file. It lists\n"
- xml += " only those blocks which contain data (boot sector, partition\n"
- xml += " table, file-system metadata, files, directories, extents, etc).\n"
- xml += " These blocks have to be copied to the target device. The other\n"
- xml += " blocks do not contain any useful data and do not have to be\n"
- xml += " copied to the target device. Thus, using the block map users can\n"
- xml += " flash the image fast. So the block map is just an optimization.\n"
- xml += " It is OK to ignore this file and just flash the entire image to\n"
- xml += " the target device if the flashing speed is not important.\n\n"
-
- xml += " Note, this file contains commentaries with useful information\n"
- xml += " like image size in gigabytes, percentage of mapped data, etc.\n"
- xml += " This data is there merely to make the XML file human-readable.\n\n"
-
- xml += " The 'version' attribute is the block map file format version in\n"
- xml += " the 'major.minor' format. The version major number is increased\n"
- xml += " whenever we make incompatible changes to the block map format,\n"
- xml += " meaning that the bmap-aware flasher would have to be modified in\n"
- xml += " order to support the new format. The minor version is increased\n"
- xml += " in case of compatible changes. For example, if we add an attribute\n"
- xml += " which is optional for the bmap-aware flasher. -->\n\n"
-
- xml += "<bmap version=\"%s\">\n" % SUPPORTED_BMAP_VERSION
- xml += "\t<!-- Image size in bytes (%s) -->\n" \
- % self.bmap_image_size_human
- xml += "\t<ImageSize> %u </ImageSize>\n\n" % self.bmap_image_size
-
- xml += "\t<!-- Size of a block in bytes -->\n"
- xml += "\t<BlockSize> %u </BlockSize>\n\n" % self.bmap_block_size
-
- xml += "\t<!-- Count of blocks in the image file -->\n"
- xml += "\t<BlocksCount> %u </BlocksCount>\n\n" % self.bmap_blocks_cnt
-
- xml += "\t<!-- The block map which consists of elements which may\n"
- xml += "\t either be a range of blocks or a single block. The\n"
- xml += "\t 'sha1' attribute (if present) is the SHA1 checksum of\n"
- xml += "\t this blocks range. -->\n"
- xml += "\t<BlockMap>"
+ xml = _BMAP_START_TEMPLATE \
+ % (SUPPORTED_BMAP_VERSION,
+ self.bmap_image_size_human, self.bmap_image_size,
+ self.bmap_block_size, self.bmap_blocks_cnt)
self._output.info(xml)
return result != 0
def _is_mapped_fiemap(self, block):
- """ A helper function which returns 'True' if block number 'block' of the
- image file is mapped and 'False' otherwise.
+ """ A helper function which returns 'True' if block number 'block' of
+ the image file is mapped and 'False' otherwise.
This function uses the FIEMAP ioctl to detect whether 'block' is mapped
to the disk. However, we do not use all the power of this ioctl: we
file: the ending tags and the information about the amount of mapped
blocks. """
- xml = "\t</BlockMap>\n\n"
- xml += "\t<!-- Count of mapped blocks (%s or %.1f%% mapped) -->\n" \
+ xml = " </BlockMap>\n\n"
+ xml += " <!-- Count of mapped blocks (%s or %.1f%% mapped) -->\n" \
% (self.bmap_mapped_size_human, self.bmap_mapped_percent)
- xml += "\t<MappedBlocksCount> %u </MappedBlocksCount>\n" \
+ xml += " <MappedBlocksCount> %u </MappedBlocksCount>\n" \
% self.bmap_mapped_cnt
xml += "</bmap>"
sha1 = " sha1=\"%s\"" % sha1
else:
sha1 = ""
- self._output.info("\t\t<Range%s> %s-%s </Range>" \
+ self._output.info(" <Range%s> %s-%s </Range>" \
% (sha1, first, last))
self.bmap_mapped_size = self.bmap_mapped_cnt * self.bmap_block_size