From: Artem Bityutskiy Date: Thu, 16 Jan 2014 11:22:07 +0000 (+0200) Subject: Filemap: remove useless constants and a parameter X-Git-Tag: v3.2~42 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=58a96f0c08d156944fc6d70343b030c5a8c81a54;p=tools%2Fbmap-tools.git Filemap: remove useless constants and a parameter This patch simplifies the Fiemap class API and removes the 'buf_size' constructor parameter because it is useless. The default 256K value is good enough. Remove a couple of related constants along with this for the same reason. Change-Id: I6d9bbca7f54ae409ad6e83b21b35a5e84504f847 Signed-off-by: Artem Bityutskiy --- diff --git a/bmaptools/Filemap.py b/bmaptools/Filemap.py index b5f7c2c..4dcb0cb 100644 --- a/bmaptools/Filemap.py +++ b/bmaptools/Filemap.py @@ -42,11 +42,10 @@ _FIEMAP_IOCTL = 0xC020660B # This FIEMAP ioctl flag which instructs the kernel to sync the file before # reading the block map _FIEMAP_FLAG_SYNC = 0x00000001 - -# Minimum buffer which is required for 'class Fiemap' to operate -MIN_BUFFER_SIZE = _FIEMAP_SIZE + _FIEMAP_EXTENT_SIZE -# The default buffer size for 'class Fiemap' -DEFAULT_BUFFER_SIZE = 256 * 1024 +# Size of the buffer for 'struct fiemap_extent' elements which will be used +# when invoking the FIEMAP ioctl. The larger is the buffer, the less times the +# FIEMAP ioctl will be invoked. +_FIEMAP_BUFFER_SIZE = 256 * 1024 class Error(Exception): """ @@ -62,16 +61,11 @@ class Fiemap: over all mapped blocks and over all holes. """ - def __init__(self, image, buf_size=DEFAULT_BUFFER_SIZE): + def __init__(self, image): """ Initialize a class instance. The 'image' argument is full path to the file to operate on, or a file object to operate on. - The 'buf_size' argument is the size of the buffer for 'struct - fiemap_extent' elements which will be used when invoking the FIEMAP - ioctl. The larger is the buffer, the less times the FIEMAP ioctl will - be invoked. - This class synchronizes the image file every time it invokes the FIEMAP ioctl in order to work-around early FIEMAP implementation kernel bugs. """ @@ -85,14 +79,12 @@ class Fiemap: self._image_path = image self._open_image_file() - # Validate 'buf_size' - if buf_size < MIN_BUFFER_SIZE: - raise Error("too small buffer (%d bytes), minimum is %d bytes" - % (buf_size, MIN_BUFFER_SIZE)) + self._buf_size = _FIEMAP_BUFFER_SIZE - # How many 'struct fiemap_extent' elements fit the buffer - buf_size -= _FIEMAP_SIZE - self._fiemap_extent_cnt = buf_size / _FIEMAP_EXTENT_SIZE + # Calculate how many 'struct fiemap_extent' elements fit the buffer + self._buf_size -= _FIEMAP_SIZE + self._fiemap_extent_cnt = self._buf_size / _FIEMAP_EXTENT_SIZE + assert self._fiemap_extent_cnt > 0 self._buf_size = self._fiemap_extent_cnt * _FIEMAP_EXTENT_SIZE self._buf_size += _FIEMAP_SIZE diff --git a/tests/test_filemap.py b/tests/test_filemap.py index 6de2cee..6919e53 100644 --- a/tests/test_filemap.py +++ b/tests/test_filemap.py @@ -88,17 +88,16 @@ def _check_ranges(f_image, filemap, first_block, blocks_cnt, ranges_type, first_block, blocks_cnt, check[0], check[1])) -def _do_test(f_image, mapped, unmapped, buf_size=Filemap.DEFAULT_BUFFER_SIZE): +def _do_test(f_image, mapped, unmapped): """ Verify that Filemap reports the correct mapped and unmapped areas for the 'f_image' file object. The 'mapped' and 'unmapped' lists contain the - correct ranges. The 'buf_size' argument specifies the internal buffer size - of the 'Filemap' class. + correct ranges. """ # Make sure that 'Filemap' module's 'get_mapped_ranges()' returns the same # ranges as we have in the 'mapped' list. - filemap = Filemap.Fiemap(f_image, buf_size) + filemap = Filemap.Fiemap(f_image) # Check both 'get_mapped_ranges()' and 'get_unmapped_ranges()' for the # entire file. @@ -142,7 +141,3 @@ class TestCreateCopy(unittest.TestCase): delete) for f_image, _, mapped, unmapped in iterator: _do_test(f_image, mapped, unmapped) - _do_test(f_image, mapped, unmapped, Filemap.MIN_BUFFER_SIZE) - _do_test(f_image, mapped, unmapped, Filemap.MIN_BUFFER_SIZE * 2) - _do_test(f_image, mapped, unmapped, Filemap.DEFAULT_BUFFER_SIZE / 2) - _do_test(f_image, mapped, unmapped, Filemap.DEFAULT_BUFFER_SIZE * 2)