kylemanna
6/28/2017 - 3:04 AM

0001-wic-Fix-get_block_size-on-aufs.patch

From 0f047bd73de529be3f30f6a54410f400ff2a7774 Mon Sep 17 00:00:00 2001
From: Kyle Manna <kyle@kylemanna.com>
Date: Tue, 27 Jun 2017 19:48:15 -0700
Subject: [PATCH] wic: Fix get_block_size() on aufs

Upstream commit: 17365f4fe9089df7ee9800a2a0ced177ec4798a4
Author: "Alexander D. Kanevskiy" <kad@kad.name>
Subject: [PATCH] get_block_size: if we can't get from ioctl, try from os.stat()
---
 scripts/lib/wic/filemap.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/scripts/lib/wic/filemap.py b/scripts/lib/wic/filemap.py
index f3240ba8d8..08c767a3ef 100644
--- a/scripts/lib/wic/filemap.py
+++ b/scripts/lib/wic/filemap.py
@@ -41,7 +41,15 @@ def get_block_size(file_obj):
     # 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]
+    bsize = struct.unpack('I', binary_data)[0]
+    if not bsize:
+        import os
+        stat = os.fstat(file_obj.fileno())
+        if hasattr(stat, 'st_blksize'):
+            bsize = stat.st_blksize
+        else:
+            raise IOError("Unable to determine block size")
+    return bsize
 
 class ErrorNotSupp(Exception):
     """
-- 
2.13.2