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

Diff of /trunk/src/GLIStorageDevice.py

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

Revision 204 Revision 205
24 self._parted_disk = parted.PedDisk.new(self._parted_dev) 24 self._parted_disk = parted.PedDisk.new(self._parted_dev)
25 self.set_disk_geometry_from_disk() 25 self.set_disk_geometry_from_disk()
26 26
27 def set_disk_geometry_from_disk(self): 27 def set_disk_geometry_from_disk(self):
28 self._total_bytes = self._parted_dev.length * self._parted_dev.sector_size 28 self._total_bytes = self._parted_dev.length * self._parted_dev.sector_size
29 if string.strip(commands.getoutput("echo " + self._device + " | grep '/hd'")) == self._device: # IDE 29# if string.strip(commands.getoutput("echo " + self._device + " | grep '/hd'")) == self._device: # IDE
30 proc_dir = "/proc/ide/" + commands.getoutput("echo " + self._device + " | cut -d '/' -f 3") 30# proc_dir = "/proc/ide/" + commands.getoutput("echo " + self._device + " | cut -d '/' -f 3")
31 proc_dir = string.strip(proc_dir) 31# proc_dir = string.strip(proc_dir)
32 heads = commands.getoutput("cat " + proc_dir + "/geometry | grep logical | cut -d '/' -f 2") 32# heads = commands.getoutput("cat " + proc_dir + "/geometry | grep logical | cut -d '/' -f 2")
33 sectors = commands.getoutput("cat " + proc_dir + "/geometry | grep logical | cut -d '/' -f 3") 33# sectors = commands.getoutput("cat " + proc_dir + "/geometry | grep logical | cut -d '/' -f 3")
34 total_sectors = commands.getoutput("cat " + proc_dir + "/capacity") 34# total_sectors = commands.getoutput("cat " + proc_dir + "/capacity")
35 cylinders = int(total_sectors) / (int(heads) * int(sectors)) 35# cylinders = int(total_sectors) / (int(heads) * int(sectors))
36 self._geometry['heads'], self._geometry['sectors'], self._geometry['cylinders'] = int(heads), int(sectors), int(cylinders) 36# self._geometry['heads'], self._geometry['sectors'], self._geometry['cylinders'] = int(heads), int(sectors), int(cylinders)
37 else: #SCSI 37# else: #SCSI
38 self._geometry['heads'], self._geometry['sectors'], self._geometry['cylinders'] = self._parted_dev.heads, self._parted_dev.sectors, self._parted_dev.cylinders 38 self._geometry['heads'], self._geometry['sectors'], self._geometry['cylinders'] = self._parted_dev.heads, self._parted_dev.sectors, self._parted_dev.cylinders
39 39
40 self._cylinder_bytes = self._geometry['heads'] * self._geometry['sectors'] * self._parted_dev.sector_size 40 self._cylinder_bytes = self._geometry['heads'] * self._geometry['sectors'] * self._parted_dev.sector_size
41 self._total_sectors = self._geometry['cylinders'] * self._geometry['heads'] * self._geometry['sectors'] 41 self._total_sectors = self._geometry['cylinders'] * self._geometry['heads'] * self._geometry['sectors']
42 self._sectors_in_cylinder = self._geometry['heads'] * self._geometry['sectors'] 42 self._sectors_in_cylinder = self._geometry['heads'] * self._geometry['sectors']
43 43
48 parted_part = self._parted_disk.next_partition(parted_part) 48 parted_part = self._parted_disk.next_partition(parted_part)
49 continue 49 continue
50 fs_type = "" 50 fs_type = ""
51 if parted_part.fs_type != None: fs_type = parted_part.fs_type.name 51 if parted_part.fs_type != None: fs_type = parted_part.fs_type.name
52 if parted_part.type == 2: fs_type = "extended" 52 if parted_part.type == 2: fs_type = "extended"
53 self._partitions[int(parted_part.num)] = Partition(self, parted_part.num, '', (parted_part.geom.start / self._sectors_in_cylinder), (parted_part.geom.end / self._sectors_in_cylinder), (parted_part.geom.end - parted_part.geom.start), fs_type, format=False, existing=True) 53 self._partitions[int(parted_part.num)] = Partition(self, parted_part.num, '', parted_part.geom.start, parted_part.geom.end, (parted_part.geom.end - parted_part.geom.start), fs_type, format=False, existing=True)
54 parted_part = self._parted_disk.next_partition(parted_part) 54 parted_part = self._parted_disk.next_partition(parted_part)
55 55
56 def set_partitions_from_install_profile_structure(self, ips): 56 def set_partitions_from_install_profile_structure(self, ips):
57 for part in ips: 57 for part in ips:
58 tmppart = ips[part] 58 tmppart = ips[part]
107 parts.sort() 107 parts.sort()
108 lastend_pri = 0 108 lastend_pri = 0
109 lastend_log = 0 109 lastend_log = 0
110 free_start = -1 110 free_start = -1
111 free_end = -1 111 free_end = -1
112 if start > self.get_num_cylinders(): return (-1, -1) 112 if start > self._total_sectors: return (-1, -1)
113 for part in parts: 113 for part in parts:
114 if part > 4: break 114 if part > 4: break
115 tmppart = self._partitions[part] 115 tmppart = self._partitions[part]
116 if (tmppart.get_start() > lastend_pri) and (lastend_pri >= start): 116 if (tmppart.get_start() > lastend_pri) and (lastend_pri >= start):
117 free_start = lastend_pri 117 free_start = lastend_pri
130 if free_start == -1 and lastend_log < tmppart.get_end(): 130 if free_start == -1 and lastend_log < tmppart.get_end():
131 free_start = lastend_log 131 free_start = lastend_log
132 free_end = tmppart.get_end() 132 free_end = tmppart.get_end()
133 break 133 break
134 lastend_pri = tmppart.get_end() + 1 134 lastend_pri = tmppart.get_end() + 1
135 if free_start == -1 and lastend_pri < self.get_num_cylinders(): 135 if free_start == -1 and lastend_pri < self._total_sectors:
136 free_start = lastend_pri 136 free_start = lastend_pri
137 free_end = self.get_num_cylinders() 137 free_end = self._total_sectors
138 return (free_start, free_end) 138 return (free_start, free_end)
139 139
140 def get_partition_at(self, cylinder, ignore_extended=1): 140 def get_partition_at(self, sector, ignore_extended=1):
141 parts = self._partitions.keys() 141 parts = self._partitions.keys()
142 parts.sort() 142 parts.sort()
143 for part in parts: 143 for part in parts:
144 tmppart = self._partitions[part] 144 tmppart = self._partitions[part]
145 if ignore_extended and tmppart.is_extended(): continue 145 if ignore_extended and tmppart.is_extended(): continue
146 if (cylinder >= tmppart.get_start()) and (cylinder <= tmppart.get_end()): 146 if (sector >= tmppart.get_start()) and (sector <= tmppart.get_end()):
147 return part 147 return part
148 return 0 148 return 0
149 149
150 def get_free_minor_at(self, start, end): 150 def get_free_minor_at(self, start, end):
151 parts = self._partitions.keys() 151 parts = self._partitions.keys()
284 _type = None 284 _type = None
285 _mountpoint = None 285 _mountpoint = None
286 _mountopts = None 286 _mountopts = None
287 _format = None 287 _format = None
288 _resizeable = None 288 _resizeable = None
289 _min_cylinders_for_resize = 0 289 _min_sectors_for_resize = 0
290 290
291 def __init__(self, device, minor, bootflag, start, end, blocks, type, mountpoint='', mountopts='', format=True, existing=False): 291 def __init__(self, device, minor, bootflag, start, end, blocks, type, mountpoint='', mountopts='', format=True, existing=False):
292 self._device = device 292 self._device = device
293 self._minor = int(minor) 293 self._minor = int(minor)
294 self._bootflag = bootflag 294 self._bootflag = bootflag
415 return self._format 415 return self._format
416 416
417 def get_blocks(self): 417 def get_blocks(self):
418 return int(self._blocks) 418 return int(self._blocks)
419 419
420 def get_min_cylinders_for_resize(self): 420 def get_min_sectors_for_resize(self):
421 if self.is_extended(): 421 if self.is_extended():
422 min_size = self._start 422 min_size = self._start
423 for part in self._device._partitions: 423 for part in self._device._partitions:
424 if part < 5: continue 424 if part < 5: continue
425 min_size = part.get_end() 425 min_size = part.get_end()
426 return min_size
426 else: 427 else:
427 return self._min_cylinders_for_resize 428 return self._min_sectors_for_resize
428 429
429 def get_max_cylinders_for_resize(self): 430 def get_max_sectors_for_resize(self):
430 free_start, free_end = self._device.get_free_space(self._end) 431 free_start, free_end = self._device.get_free_space(self._end)
431 if free_end == -1: return self._end 432 if free_end == -1: return self._end
432 if free_start - 1 == self._end: 433 if free_start - 1 == self._end:
433 if self.is_logical(): 434 if self.is_logical():
434 if free_end <= self._device._partitions[self.get_extended_parent()]._end: 435 if free_end <= self._device._partitions[self.get_extended_parent()]._end:

Legend:
Removed from v.204  
changed lines
  Added in v.205

  ViewVC Help
Powered by ViewVC 1.1.20