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

Diff of /trunk/src/GLIStorageDevice.py

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

Revision 113 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 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
40 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']
41 self._sectors_in_cylinder = self._geometry['heads'] * self._geometry['sectors'] 42 self._sectors_in_cylinder = self._geometry['heads'] * self._geometry['sectors']
42 43
43 def set_partitions_from_disk(self): 44 def set_partitions_from_disk(self):
47 parted_part = self._parted_disk.next_partition(parted_part) 48 parted_part = self._parted_disk.next_partition(parted_part)
48 continue 49 continue
49 fs_type = "" 50 fs_type = ""
50 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
51 if parted_part.type == 2: fs_type = "extended" 52 if parted_part.type == 2: fs_type = "extended"
52 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)
53 parted_part = self._parted_disk.next_partition(parted_part) 54 parted_part = self._parted_disk.next_partition(parted_part)
54 55
55 def set_partitions_from_install_profile_structure(self, ips): 56 def set_partitions_from_install_profile_structure(self, ips):
56 for part in ips: 57 for part in ips:
57 tmppart = ips[part] 58 tmppart = ips[part]
106 parts.sort() 107 parts.sort()
107 lastend_pri = 0 108 lastend_pri = 0
108 lastend_log = 0 109 lastend_log = 0
109 free_start = -1 110 free_start = -1
110 free_end = -1 111 free_end = -1
111 if start > self.get_num_cylinders(): return (-1, -1) 112 if start > self._total_sectors: return (-1, -1)
112 for part in parts: 113 for part in parts:
113 if part > 4: break 114 if part > 4: break
114 tmppart = self._partitions[part] 115 tmppart = self._partitions[part]
115 if (tmppart.get_start() > lastend_pri) and (lastend_pri >= start): 116 if (tmppart.get_start() > lastend_pri) and (lastend_pri >= start):
116 free_start = lastend_pri 117 free_start = lastend_pri
129 if free_start == -1 and lastend_log < tmppart.get_end(): 130 if free_start == -1 and lastend_log < tmppart.get_end():
130 free_start = lastend_log 131 free_start = lastend_log
131 free_end = tmppart.get_end() 132 free_end = tmppart.get_end()
132 break 133 break
133 lastend_pri = tmppart.get_end() + 1 134 lastend_pri = tmppart.get_end() + 1
134 if free_start == -1 and lastend_pri < self.get_num_cylinders(): 135 if free_start == -1 and lastend_pri < self._total_sectors:
135 free_start = lastend_pri 136 free_start = lastend_pri
136 free_end = self.get_num_cylinders() 137 free_end = self._total_sectors
137 return (free_start, free_end) 138 return (free_start, free_end)
138 139
139 def get_partition_at(self, cylinder, ignore_extended=1): 140 def get_partition_at(self, sector, ignore_extended=1):
140 parts = self._partitions.keys() 141 parts = self._partitions.keys()
141 parts.sort() 142 parts.sort()
142 for part in parts: 143 for part in parts:
143 tmppart = self._partitions[part] 144 tmppart = self._partitions[part]
144 if ignore_extended and tmppart.is_extended(): continue 145 if ignore_extended and tmppart.is_extended(): continue
145 if (cylinder >= tmppart.get_start()) and (cylinder <= tmppart.get_end()): 146 if (sector >= tmppart.get_start()) and (sector <= tmppart.get_end()):
146 return part 147 return part
147 return 0 148 return 0
148 149
149 def get_free_minor_at(self, start, end): 150 def get_free_minor_at(self, start, end):
150 parts = self._partitions.keys() 151 parts = self._partitions.keys()
212 for part in self._partitions: 213 for part in self._partitions:
213 tmppart = self._partitions[part] 214 tmppart = self._partitions[part]
214 devdic[part] = { 'mb': 0, 'start': tmppart.get_start(), 'end': tmppart.get_end(), 'type': tmppart.get_type(), 'mountpoint': tmppart.get_mountpoint(), 'mountopts': tmppart.get_mountopts(), 'format': tmppart.get_format() } 215 devdic[part] = { 'mb': 0, 'start': tmppart.get_start(), 'end': tmppart.get_end(), 'type': tmppart.get_type(), 'mountpoint': tmppart.get_mountpoint(), 'mountopts': tmppart.get_mountopts(), 'format': tmppart.get_format() }
215 return devdic 216 return devdic
216 217
218 def get_extended_partition(self):
219 for part in self._partitions:
220 tmppart = self._partitions[part]
221 if tmppart.is_extended():
222 return part
223 return 0
224
217 def get_num_sectors(self): 225 def get_num_sectors(self):
218 return int(self._total_sectors) 226 return int(self._total_sectors)
219 227
220 def get_cylinder_size(self): 228 def get_cylinder_size(self):
221 return int(self._cylinder_bytes) 229 return int(self._cylinder_bytes)
276 _type = None 284 _type = None
277 _mountpoint = None 285 _mountpoint = None
278 _mountopts = None 286 _mountopts = None
279 _format = None 287 _format = None
280 _resizeable = None 288 _resizeable = None
281 _min_cylinders_for_resize = 0 289 _min_sectors_for_resize = 0
282 290
283 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):
284 self._device = device 292 self._device = device
285 self._minor = int(minor) 293 self._minor = int(minor)
286 self._bootflag = bootflag 294 self._bootflag = bootflag
287 self._start = int(start) 295 self._start = int(start)
288 self._end = int(end) 296 self._end = int(end)
289 self._blocks = int(blocks) 297 self._blocks = int(blocks)
298 if type == "": type = "unknown"
290 self._type = type 299 self._type = type
291 self._mountpoint = mountpoint 300 self._mountpoint = mountpoint
292 self._mountopts = mountopts 301 self._mountopts = mountopts
293 self._format = format 302 self._format = format
294 if blocks == 0: 303 if blocks == 0:
295 self._blocks = ((self._end - self._start) * self._device.get_cylinder_size()) / 512 304 self._blocks = ((self._end - self._start) * self._device.get_cylinder_size()) / 512
296 if existing: 305# if existing:
297 parted_part = device._parted_disk.get_partition(minor) 306# parted_part = device._parted_disk.get_partition(minor)
298 if type == "ntfs": 307# if type == "ntfs":
299 min_bytes = int(commands.getoutput("ntfsresize --info " + device._device + str(minor) + " | grep -e '^You might resize' | sed -e 's/You might resize at //' -e 's/ bytes or .\+//'")) 308# min_bytes = int(commands.getoutput("ntfsresize -f --info " + device._device + str(minor) + " | grep -e '^You might resize' | sed -e 's/You might resize at //' -e 's/ bytes or .\+//'"))
300 self._min_cylinders_for_resize = int(min_bytes / self._device._cylinder_bytes) + 1 309# self._min_cylinders_for_resize = int(min_bytes / self._device._cylinder_bytes) + 1
301 self._resizeable == True 310# self._resizeable == True
302 elif type == "ext2" or type == "ext3": 311# elif type == "ext2" or type == "ext3":
303 commands.system("mkdir /mnt/freespace; mount " + device._device + str(minor) + " /mnt/freespace") 312# block_size = string.strip(commands.getoutput("dumpe2fs -h " + device._device + str(minor) + " 2>&1 | grep -e '^Block size:' | sed -e 's/^Block size:\s\+//'"))
304 min_bytes = int(commands.getoutput("df -B kB " + device._device + str(minor) + " | tail -n 1 | sed -e 's:^" + device._device + str(minor) + "\s\+[0-9]\+kB\s\+::' -e 's:kB\s.\+::'")) * 1000 313# free_blocks = string.strip(commands.getoutput("dumpe2fs -h " + device._device + str(minor) + " 2>&1 | grep -e '^Free blocks:' | sed -e 's/^Free blocks:\s\+//'"))
305 commands.system("umount /mnt/freespace; rm -rf /mnt/freespace") 314# free_cyl = int(int(block_size) * int(free_blocks) / self._device._cylinder_bytes)
306 min_bytes = min_bytes + (100 * 1024 * 1024) # Add 100M just to be safe 315# free_cyl = int(free_cyl)
307 self._min_cylinders_for_resize = int(min_bytes / self._device._cylinder_bytes) + 1 316# free_cyl = free_cyl - 200 # just to be safe
317# self._min_cylinders_for_resize = (self._end - self._start + 1) - free_cyl
308 self._resizeable == True 318# self._resizeable == True
309 elif type == "fat16" or type == "fat32": 319# elif type == "fat16" or type == "fat32":
310 parted_part = self._device._parted_disk.get_partition(self._minor) 320# parted_part = self._device._parted_disk.get_partition(self._minor)
311 parted_fs = parted_part.geom.file_system_open() 321# parted_fs = parted_part.geom.file_system_open()
312 resize_constraint = parted_fs.get_resize_constraint() 322# resize_constraint = parted_fs.get_resize_constraint()
313 min_size = float(resize_constraint.min_size / self._device._sectors_in_cylinder) 323# min_size = float(resize_constraint.min_size / self._device._sectors_in_cylinder)
314 if int(min_size) != min_size: min_size = int(min_size) + 1 324# if int(min_size) != min_size: min_size = int(min_size) + 1
315 self._min_cylinders_for_resize = min_size 325# self._min_cylinders_for_resize = min_size
316 self._resizeable = True 326# self._resizeable = True
317 elif type == "": 327# elif type == "":
318 self._min_cylinders_for_resize = 1 328# self._min_cylinders_for_resize = 1
319 self._resizeable = True 329# self._resizeable = True
320 else: 330# else:
321 self._resizeable = True 331# self._resizeable = True
322 332
323 def is_extended(self): 333 def is_extended(self):
324 if self._type == "extended": 334 if self._type == "extended":
325 return True 335 return True
326 else: 336 else:
331 if part and self._device._partitions[part].is_extended() and not part == self._minor: 341 if part and self._device._partitions[part].is_extended() and not part == self._minor:
332 return True 342 return True
333 return False 343 return False
334 344
335 def get_logicals(self): 345 def get_logicals(self):
346 if not self.is_extended():
347 return None
336 logicals = [] 348 logicals = []
337 start = self._start 349 start = self._start
338 while not start > self._end: 350# while not start > self._end:
339 part = self._device.get_partition_at(start) 351# part = self._device.get_partition_at(start)
352# print "part=" + str(part)
340 if not part: break 353# if not part: break
354# logicals.append(part)
355# start = self._device._partitions[part].get_end() + 1
356 parts = self._device._partitions.keys()
357 parts.sort()
358 for part in parts:
359 if part < 5: continue
341 logicals.append(part) 360 logicals.append(part)
342 start = self._device._partitions[part].get_end() + 1
343 logicals.sort() 361 logicals.sort()
344 return logicals 362 return logicals
345 363
346 def get_extended_parent(self): 364 def get_extended_parent(self):
365 if not self.is_logical():
366 return None
367 else:
347 return self._device.get_partition_at(self._start, ignore_extended=0) 368 return self._device.get_partition_at(self._start, ignore_extended=0)
348 369
349 def set_start(self, start): 370 def set_start(self, start):
350 self._start = int(start) 371 self._start = int(start)
351 self._blocks = ((self._end - self._start) * self._device.get_cylinder_size()) / 512 372 self._blocks = ((self._end - self._start) * self._device.get_cylinder_size()) / 512
352 373
394 return self._format 415 return self._format
395 416
396 def get_blocks(self): 417 def get_blocks(self):
397 return int(self._blocks) 418 return int(self._blocks)
398 419
399 def get_min_cylinders_for_resize(self): 420 def get_min_sectors_for_resize(self):
400# min_size = self._start + 1
401# if not self._format:
402# parted_part = self._device._parted_disk.get_partition(self._minor)
403# parted_fs = parted_part.geom.file_system_open()
404# resize_constraint = parted_fs.get_resize_constraint()
405# min_size = float(resize_constraint.min_size / self._device._sectors_in_cylinder)
406# if int(min_size) != min_size: min_size = int(min_size) + 1
407# min_size = min_size + self._start
408#################################################
409 if self.is_extended(): 421 if self.is_extended():
410 min_size = self._start 422 min_size = self._start
411 for part in self._device._partitions: 423 for part in self._device._partitions:
412 if part < 5: continue 424 if part < 5: continue
413 min_size = part.get_end() 425 min_size = part.get_end()
426 return min_size
414 else: 427 else:
415 return self._min_cylinders_for_resize 428 return self._min_sectors_for_resize
416 429
417 def get_max_cylinders_for_resize(self): 430 def get_max_sectors_for_resize(self):
418 free_start, free_end = self._device.get_free_space(self._end) 431 free_start, free_end = self._device.get_free_space(self._end)
419 if free_end == -1: return self._end 432 if free_end == -1: return self._end
420 if free_start - 1 == self._end: 433 if free_start - 1 == self._end:
421 if self.is_logical(): 434 if self.is_logical():
422 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.113  
changed lines
  Added in v.205

  ViewVC Help
Powered by ViewVC 1.1.20