from fcntl import ioctl
import struct
from itertools import groupby
-from bmaptools.BmapHelpers import human_size
+from bmaptools.BmapHelpers import human_size, get_block_size
import array
# The bmap format version we generate
raise Error("cannot generate bmap for zero-sized image file '%s'" \
% image_path, err.errno)
- # Get the block size of the host file-system for the image file by
- # calling the FIGETBSZ ioctl (number 2).
try:
- binary_data = ioctl(self._f_image, 2, struct.pack('I', 0))
- self.bmap_block_size = struct.unpack('I', binary_data)[0]
+ self.bmap_block_size = get_block_size(self._f_image)
except IOError as err:
raise Error("cannot get block size for '%s': %s" \
% (image_path, err), err.errno)
"""
-This module contains various helper functions which are shared between
-BmapFlash and BmapCreate or which are useful for users of bmaptools.
+This module contains various shared helper functions.
"""
def human_size(size):
result += "%dm " % minutes
return result + "%.1fs" % seconds
+
+def get_block_size(file_obj):
+ """ Returns block size for file object 'file_obj'. Errors are indicated by
+ the 'IOError' exception. """
+
+ from fcntl import ioctl
+ import struct
+
+ # Get the block size of the host file-system for the image file by calling
+ # the FIGETBSZ ioctl (number 2).
+ binary_data = ioctl(file_obj, 2, struct.pack('I', 0))
+ return struct.unpack('I', binary_data)[0]