summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2013-04-01 19:40:23 +0000
committerIgor Pashev <pashev.igor@gmail.com>2013-04-01 19:40:23 +0000
commit63cb3d4f5f41186d99ebad7d5021f5a61b2aa9e7 (patch)
treedfe533b96a66f3a3aa321bc96dff9f7c88560caf
parentad96e366d10a8b5fc49794a646eac6c5b5b0a949 (diff)
downloadlive-63cb3d4f5f41186d99ebad7d5021f5a61b2aa9e7.tar.gz
Fix handling extended partitions
-rw-r--r--lib/hdd/__init__.py30
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/hdd/__init__.py b/lib/hdd/__init__.py
index 6189e24..fb0c8ab 100644
--- a/lib/hdd/__init__.py
+++ b/lib/hdd/__init__.py
@@ -1,5 +1,14 @@
#!/usr/bin/python
+"""
+Written by Igor Pashev <pashev.igor@gmail.com>
+
+The author has placed this work in the Public Domain,
+thereby relinquishing all copyrights. Everyone is free
+to use, modify, republish, sell or give away this work
+without prior consent from anybody.
+"""
+
from subprocess import Popen, PIPE
import re
import sys
@@ -53,29 +62,32 @@ class HDD(object):
# boot? start end blocks id system
fdisk_ul = re.compile('^/dev/rdsk/{}\S+\s+(\*|\s)\s+(\d+)\s+(\d+)\s+(\d+)\+?\s+([a-f0-9]+)\s(.+)\s*$'.format(self.name))
fdisk_ul_cmd = Popen(['fdisk.ul', '-l', self.raw_device], stdout=PIPE, stderr=PIPE)
- logical = False
self.partitions = []
for line in fdisk_ul_cmd.stdout:
m = fdisk_ul.match(line)
if m:
- part_id = int(m.group(5), 16)
- # Ignore "Extended" partitions, mark subsequent partitions as "logical"
- if not logical and part_id == 0x5:
- logical = True
- continue
-
p = Partition()
p.boot = m.group(1) == '*'
p.start = int(m.group(2))
p.end = int(m.group(3))
p.blocks = int(m.group(4))
- p.id = part_id
+ p.id = int(m.group(5), 16)
p.system = m.group(6)
- p.logical = logical
+ p.logical = False # Update in the second pass
p.bytes = (p.end - p.start) * self.geometry['secsiz']
p.capacity = human_capacity(p.bytes)
self.partitions.append(p)
+ ext= None
+ for p in self.partitions:
+ if p.id == 0x05:
+ ext= p
+ break
+ if ext:
+ for p in self.partitions:
+ if p.id != 0x05 and p.start >= ext.start and p.end <= ext.end:
+ p.logical = True
+
def __init_capacity(self):
fdisk_cmd = Popen(['fdisk', '-G', self.raw_device], stdout=PIPE)
for line in fdisk_cmd.stdout: