diff options
author | Artem Bityutskiy <artem.bityutskiy@intel.com> | 2013-04-10 09:51:01 +0300 |
---|---|---|
committer | Artem Bityutskiy <artem.bityutskiy@intel.com> | 2013-04-19 16:25:55 +0300 |
commit | 39a18410920986e625551158e708ce9a304c4943 (patch) | |
tree | ae07e4af57dd3b060066936b133c14b8a479cb90 | |
parent | 55b84374490c7baca5597a68c908095625b00b06 (diff) | |
download | mic-39a18410920986e625551158e708ce9a304c4943.tar.gz mic-39a18410920986e625551158e708ce9a304c4943.tar.bz2 mic-39a18410920986e625551158e708ce9a304c4943.zip |
gpt_parser: add backup GPT header reading support
Change-Id: Ie496acd5b8020a2a48a4c905be2467dda338cf12
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
-rw-r--r-- | mic/utils/gpt_parser.py | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/mic/utils/gpt_parser.py b/mic/utils/gpt_parser.py index 0476bfb..52e1a6c 100644 --- a/mic/utils/gpt_parser.py +++ b/mic/utils/gpt_parser.py @@ -98,7 +98,7 @@ class GptParser: self.disk_obj.close() - def read_header(self): + def read_header(self, primary = True): """ Read and verify the GPT header and return a tuple containing the following elements: @@ -108,9 +108,12 @@ class GptParser: Size of a single partition entry, CRC32 of partition array) This tuple corresponds to the GPT header format. Please, see the UEFI - standard for the description of these fields. """ + standard for the description of these fields. - # The header sits at LBA 1 - read it + If the 'primary' parameter is 'True', the primary GPT header is read, + otherwise the backup GPT header is read instead. """ + + # Read and validate the primary GPT header self.disk_obj.seek(self.sector_size) try: header = self.disk_obj.read(struct.calcsize(_GPT_HEADER_FORMAT)) @@ -121,6 +124,18 @@ class GptParser: header = struct.unpack(_GPT_HEADER_FORMAT, header) _validate_header(header) + if not primary: + # Read and validate the backup GPT header + self.disk_obj.seek(header[6] * self.sector_size) + try: + header = self.disk_obj.read(struct.calcsize(_GPT_HEADER_FORMAT)) + except IOError as err: + raise MountError("cannot read from file '%s': %s" % \ + (self.disk_path, err)) + + header = struct.unpack(_GPT_HEADER_FORMAT, header) + _validate_header(header) + return (header[0], # 0. Signature header[1], # 1. Revision header[2], # 2. Header size in bytes |