aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn2019-01-10 16:30:51 -0600
committerMark Salyzyn2019-01-10 16:49:34 -0600
commit6541d0a80e9e5cf7ac6fff19007532f36ef70cbd (patch)
tree457309a1326d7fca38d0ff8609b4f3a1e69e6968
parent60a716fe8c4bff137fad55943b5a172de0158020 (diff)
downloadplatform-build-6541d0a80e9e5cf7ac6fff19007532f36ef70cbd.tar.gz
platform-build-6541d0a80e9e5cf7ac6fff19007532f36ef70cbd.tar.xz
platform-build-6541d0a80e9e5cf7ac6fff19007532f36ef70cbd.zip
build_image: support non-sparse right-sized images
Allow right-size to support images that are not sparse. This is in support of cuttlefish. Test: build Bug: 122328872 Change-Id: Ic8ef968e750203dffde7044bc6dfc71c1e283158
-rwxr-xr-xtools/releasetools/build_image.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/tools/releasetools/build_image.py b/tools/releasetools/build_image.py
index 29d363381..521b319ed 100755
--- a/tools/releasetools/build_image.py
+++ b/tools/releasetools/build_image.py
@@ -79,22 +79,26 @@ def GetInodeUsage(path):
79 return output.count('\n') * 2 79 return output.count('\n') * 2
80 80
81 81
82def GetFilesystemCharacteristics(sparse_image_path): 82def GetFilesystemCharacteristics(image_path, sparse_image=True):
83 """Returns various filesystem characteristics of "sparse_image_path". 83 """Returns various filesystem characteristics of "image_path".
84 84
85 Args: 85 Args:
86 sparse_image_path: The file to analyze. 86 image_path: The file to analyze.
87 sparse_image: Image is sparse
87 88
88 Returns: 89 Returns:
89 The characteristics dictionary. 90 The characteristics dictionary.
90 """ 91 """
91 unsparse_image_path = UnsparseImage(sparse_image_path, replace=False) 92 unsparse_image_path = image_path
93 if sparse_image:
94 unsparse_image_path = UnsparseImage(image_path, replace=False)
92 95
93 cmd = ["tune2fs", "-l", unsparse_image_path] 96 cmd = ["tune2fs", "-l", unsparse_image_path]
94 try: 97 try:
95 output = common.RunAndCheckOutput(cmd, verbose=False) 98 output = common.RunAndCheckOutput(cmd, verbose=False)
96 finally: 99 finally:
97 os.remove(unsparse_image_path) 100 if sparse_image:
101 os.remove(unsparse_image_path)
98 fs_dict = {} 102 fs_dict = {}
99 for line in output.splitlines(): 103 for line in output.splitlines():
100 fields = line.split(":") 104 fields = line.split(":")
@@ -414,7 +418,10 @@ def BuildImage(in_dir, prop_dict, out_file, target_out=None):
414 "First Pass based on estimates of %d MB and %s inodes.", 418 "First Pass based on estimates of %d MB and %s inodes.",
415 size // BYTES_IN_MB, prop_dict["extfs_inode_count"]) 419 size // BYTES_IN_MB, prop_dict["extfs_inode_count"])
416 BuildImageMkfs(in_dir, prop_dict, out_file, target_out, fs_config) 420 BuildImageMkfs(in_dir, prop_dict, out_file, target_out, fs_config)
417 fs_dict = GetFilesystemCharacteristics(out_file) 421 sparse_image = False
422 if "extfs_sparse_flag" in prop_dict:
423 sparse_image = True
424 fs_dict = GetFilesystemCharacteristics(out_file, sparse_image)
418 os.remove(out_file) 425 os.remove(out_file)
419 block_size = int(fs_dict.get("Block size", "4096")) 426 block_size = int(fs_dict.get("Block size", "4096"))
420 free_size = int(fs_dict.get("Free blocks", "0")) * block_size 427 free_size = int(fs_dict.get("Free blocks", "0")) * block_size