summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtem Bityutskiy <artem.bityutskiy@intel.com>2013-04-10 11:47:41 +0300
committerArtem Bityutskiy <artem.bityutskiy@intel.com>2013-04-19 16:25:55 +0300
commit25f9cc47abacb0967459e93b1b68c393cd0a854f (patch)
tree55fd4f98db1bf974297eab642f041dbf6df1a7a7
parent8e0a1bb5ea6a6f9946fa99e76f1e1ade6f334b0e (diff)
downloadmic-25f9cc47abacb0967459e93b1b68c393cd0a854f.tar.gz
mic-25f9cc47abacb0967459e93b1b68c393cd0a854f.tar.bz2
mic-25f9cc47abacb0967459e93b1b68c393cd0a854f.zip
gpt_parser: use _read_disk helper in get_partitions
Use the helper which we just introduced, because it does errors checking. Also, introduce a helper _GPT_ENTRY_SIZE constant. Change-Id: I496933f46292f31987ff37fdc9dabc8c5bd150c6 Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
-rw-r--r--mic/utils/gpt_parser.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/mic/utils/gpt_parser.py b/mic/utils/gpt_parser.py
index aa0de1d..1e09c14 100644
--- a/mic/utils/gpt_parser.py
+++ b/mic/utils/gpt_parser.py
@@ -26,6 +26,7 @@ from mic.utils.errors import MountError
_GPT_HEADER_FORMAT = "<8s4sIIIQQQQ16sQIII"
_GPT_HEADER_SIZE = struct.calcsize(_GPT_HEADER_FORMAT)
_GPT_ENTRY_FORMAT = "<16s16sQQQ72s"
+_GPT_ENTRY_SIZE = struct.calcsize(_GPT_ENTRY_FORMAT)
_SUPPORTED_GPT_REVISION = '\x00\x00\x01\x00'
def _stringify_uuid(binary_uuid):
@@ -173,15 +174,15 @@ class GptParser:
partition table are generated. """
header = self.read_header(primary)
- entries_start = header[9] * self.sector_size
- entries_count = header[10]
- self._disk_obj.seek(entries_start)
+ start = header[9] * self.sector_size
index = -1
- for _ in xrange(0, entries_count):
- entry = self._disk_obj.read(struct.calcsize(_GPT_ENTRY_FORMAT))
+ for _ in xrange(0, header[10]):
+ entry = self._read_disk(start, _GPT_ENTRY_SIZE)
entry = struct.unpack(_GPT_ENTRY_FORMAT, entry)
+
+ start += header[11]
index += 1
if entry[2] == 0 or entry[3] == 0: