diff options
author | Artem Bityutskiy <artem.bityutskiy@intel.com> | 2013-05-07 10:02:19 +0300 |
---|---|---|
committer | Artem Bityutskiy <artem.bityutskiy@intel.com> | 2013-05-07 10:07:00 +0300 |
commit | 2de2aa0181cf7ec69cbfc8fe62db5372deff0c8f (patch) | |
tree | cdebb2a67215f50b8e84739c08e56b5052cdfb73 | |
parent | 30cac73a5712d354c88a7b8713f26064c9e3a48b (diff) | |
download | mic-2de2aa0181cf7ec69cbfc8fe62db5372deff0c8f.tar.gz mic-2de2aa0181cf7ec69cbfc8fe62db5372deff0c8f.tar.bz2 mic-2de2aa0181cf7ec69cbfc8fe62db5372deff0c8f.zip |
misc: add get_block_size helper function
It returns file-system block size.
Change-Id: Idc512a90c58d76925e46f3bd3782093f2c102d5e
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
-rw-r--r-- | mic/utils/misc.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/mic/utils/misc.py b/mic/utils/misc.py index 83ab8d6..e7dbf2f 100644 --- a/mic/utils/misc.py +++ b/mic/utils/misc.py @@ -267,6 +267,18 @@ def human_size(size): mant = float(size/math.pow(1024, expo)) return "{0:.1f}{1:s}".format(mant, measure[expo]) +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] + def check_space_pre_cp(src, dst): """Check whether disk space is enough before 'cp' like operations, else exception will be raised. |