/[gli]/trunk/src/GLIStorageDevice.py
Gentoo

Diff of /trunk/src/GLIStorageDevice.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 495 Revision 497
1import commands, string, re, os, parted 1import commands, string, re, os, parted
2from decimal import Decimal 2from decimal import Decimal
3 3
4MEGABYTE = 1024 * 1024 4MEGABYTE = 1024 * 1024
5
6archinfo = { 'sparc': { 'fixedparts': [ { 'minor': 3, 'type': "wholedisk" } ], 'disklabel': 'sun', 'extended': False },
7 'hppa': { 'fixedparts': [ { 'minor': 1, 'type': "boot" } ], 'disklabel': 'msdos', 'extended': False },
8 'x86': { 'fixedparts': [], 'disklabel': 'msdos', 'extended': True },
9 'ppc': { 'fixedparts': [ { 'minor': 1, 'type': "metadata" } ], 'disklabel': 'mac', 'extended': False }
10 }
5 11
6class Device: 12class Device:
7 "Class representing a partitionable device." 13 "Class representing a partitionable device."
8 14
9 _device = None 15 _device = None
17 _parted_disk = None 23 _parted_disk = None
18 _sector_bytes = 0 24 _sector_bytes = 0
19 _total_mb = 0 25 _total_mb = 0
20 _arch = None 26 _arch = None
21 27
22 archinfo = { 'sparc': { 'fixedparts': [ { 'minor': 3, 'type': "wholedisk" } ], 'disklabel': 'sun', 'extended': False },
23 'hppa': { 'fixedparts': [ { 'minor': 1, 'type': "boot" } ], 'disklabel': 'msdos', 'extended': False },
24 'x86': { 'fixedparts': [], 'disklabel': 'msdos', 'extended': True },
25 'ppc': { 'fixedparts': [ { 'minor': 1, 'type': "metadata" } ], 'disklabel': 'mac', 'extended': False }
26 }
27
28 def __init__(self, device, arch="x86"): 28 def __init__(self, device, arch="x86"):
29 self._device = device 29 self._device = device
30 self._partitions = {} 30 self._partitions = {}
31 self._geometry = {'cylinders': 0, 'heads': 0, 'sectors': 0, 'sectorsize': 512} 31 self._geometry = {'cylinders': 0, 'heads': 0, 'sectors': 0, 'sectorsize': 512}
32 self._total_bytes = 0 32 self._total_bytes = 0
91 last_free = 0 91 last_free = 0
92 last_log_free = 0 92 last_log_free = 0
93 parts = self._partitions.keys() 93 parts = self._partitions.keys()
94 parts.sort() 94 parts.sort()
95 for part in parts: 95 for part in parts:
96 if self.archinfo[self._arch]['extended'] and part > 4: break 96 if archinfo[self._arch]['extended'] and part > 4: break
97 tmppart = self._partitions[part] 97 tmppart = self._partitions[part]
98 if tmppart.get_type() == "extended": 98 if tmppart.get_type() == "extended":
99 for part_log in parts: 99 for part_log in parts:
100 if part_log < Decimal("4.9"): continue 100 if part_log < Decimal("4.9"): continue
101 tmppart_log = self._partitions[part_log] 101 tmppart_log = self._partitions[part_log]
163 self._partitions[i+1] = self._partitions[i] 163 self._partitions[i+1] = self._partitions[i]
164 if i == new_minor: stopscooting = 1 164 if i == new_minor: stopscooting = 1
165 if mb != self._partitions[free_minor].get_mb(): 165 if mb != self._partitions[free_minor].get_mb():
166 old_free_mb = self._partitions[free_minor].get_mb() 166 old_free_mb = self._partitions[free_minor].get_mb()
167 del self._partitions[free_minor] 167 del self._partitions[free_minor]
168 if self.archinfo[self._arch]['extended'] and new_minor >= 5: 168 if archinfo[self._arch]['extended'] and new_minor >= 5:
169 free_minor = Decimal(str(new_minor + 0.9)) 169 free_minor = Decimal(str(new_minor + 0.9))
170 else: 170 else:
171 free_minor = Decimal(str(new_minor + 0.1)) 171 free_minor = Decimal(str(new_minor + 0.1))
172 self._partitions[free_minor] = Partition(self, free_minor, old_free_mb-mb, 0, 0, "free") 172 self._partitions[free_minor] = Partition(self, free_minor, old_free_mb-mb, 0, 0, "free")
173# print "add_partition(): new part doesn't use all freespace. new free part is: minor=" + str(free_minor) 173# print "add_partition(): new part doesn't use all freespace. new free part is: minor=" + str(free_minor)
269 parts.sort() 269 parts.sort()
270 partlist = [] 270 partlist = []
271 tmppart = None 271 tmppart = None
272 tmppart_log = None 272 tmppart_log = None
273 for part in parts: 273 for part in parts:
274 if self.archinfo[self._arch]['extended'] and part > Decimal("4.1"): break 274 if archinfo[self._arch]['extended'] and part > Decimal("4.1"): break
275 tmppart = self._partitions[part] 275 tmppart = self._partitions[part]
276 partlist.append(part) 276 partlist.append(part)
277 if tmppart.is_extended(): 277 if tmppart.is_extended():
278 for part_log in parts: 278 for part_log in parts:
279 if part_log < Decimal("4.9"): continue 279 if part_log < Decimal("4.9"): continue
420 if self._type == "free": 420 if self._type == "free":
421 if int(self._minor) + Decimal("0.9") == Decimal(str(self._minor)): 421 if int(self._minor) + Decimal("0.9") == Decimal(str(self._minor)):
422 return True 422 return True
423 else: 423 else:
424 return False 424 return False
425 elif self._device.archinfo[self._device._arch]['extended'] and self._minor > 4: 425 elif archinfo[self._device._arch]['extended'] and self._minor > 4:
426 return True 426 return True
427 else: 427 else:
428 return False 428 return False
429 429
430 def get_logicals(self): 430 def get_logicals(self):

Legend:
Removed from v.495  
changed lines
  Added in v.497

  ViewVC Help
Powered by ViewVC 1.1.20