# Diff of /trunk/src/GLIStorageDevice.py

Revision 212 Revision 386
74 return self._device 74 return self._device
75 75
76 def clear_partitions(self): 76 def clear_partitions(self):
77 self._partitions = {} 77 self._partitions = {}
78 78
79 def add_partition(self, minor, start, end, type): 79 def add_partition(self, minor, start, end, type, mountpoint='', mountopts=''):
80 free_start, free_end = self.get_free_space(start) 80 free_start, free_end = self.get_free_space(start)
81 minor = int(minor) 81 minor = int(minor)
82 if not free_end: 82 if not free_end:
83 return False 83 return False
84 if self._partitions.has_key(minor): 84 if self._partitions.has_key(minor):
97 if (i >= hole_at) and (hole_at): continue 97 if (i >= hole_at) and (hole_at): continue
98 if i >= minor: 98 if i >= minor:
99 self._partitions[i].set_minor(i+1) 99 self._partitions[i].set_minor(i+1)
100 self._partitions[i+1] = self._partitions[i] 100 self._partitions[i+1] = self._partitions[i]
101 if i == minor: stopscooting = 1 101 if i == minor: stopscooting = 1
102 self._partitions[minor] = Partition(self, minor, '', start, end, 0, type) 102 self._partitions[minor] = Partition(self, minor, '', start, end, 0, type, mountpoint=mountpoint, mountopts=mountopts)
103 103
104 def remove_partition(self, minor): 104 def remove_partition(self, minor):
105 del self._partitions[int(minor)] 105 del self._partitions[int(minor)]
106 106
107 def get_free_space(self, start): 107 def get_free_space(self, start):
213 213
214 def get_install_profile_structure(self): 214 def get_install_profile_structure(self):
215 devdic = {} 215 devdic = {}
216 for part in self._partitions: 216 for part in self._partitions:
217 tmppart = self._partitions[part] 217 tmppart = self._partitions[part]
218 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() } 218 devdic[part] = { 'mb': 0, 'minor': int(part), 'origminor': tmppart.get_orig_minor(), 'start': tmppart.get_start(), 'end': tmppart.get_end(), 'type': tmppart.get_type(), 'mountpoint': tmppart.get_mountpoint(), 'mountopts': tmppart.get_mountopts(), 'format': tmppart.get_format() }
219 return devdic 219 return devdic
220 220
221 def get_extended_partition(self): 221 def get_extended_partition(self):
222 for part in self._partitions: 222 for part in self._partitions:
223 tmppart = self._partitions[part] 223 tmppart = self._partitions[part]
281class Partition: 281class Partition:
282 "Class representing a single partition within a Device object" 282 "Class representing a single partition within a Device object"
283 283
284 _device = None 284 _device = None
285 _minor = None 285 _minor = None
286 _orig_minor = ""
286 _bootflag = None 287 _bootflag = None
287 _start = None 288 _start = None
288 _end = None 289 _end = None
289 _blocks = None 290 _blocks = None
290 _type = None 291 _type = None
295 _min_sectors_for_resize = 0 296 _min_sectors_for_resize = 0
296 297
297 def __init__(self, device, minor, bootflag, start, end, blocks, type, mountpoint='', mountopts='', format=True, existing=False): 298 def __init__(self, device, minor, bootflag, start, end, blocks, type, mountpoint='', mountopts='', format=True, existing=False):
298 self._device = device 299 self._device = device
299 self._minor = int(minor) 300 self._minor = int(minor)
301 if existing: self._orig_minor = int(minor)
300 self._bootflag = bootflag 302 self._bootflag = bootflag
301 self._start = int(start) 303 self._start = int(start)
302 self._end = int(end) 304 self._end = int(end)
303 self._blocks = int(blocks) 305 self._blocks = int(blocks)
304 if type == "": type = "unknown" 306 if type == "": type = "unknown"
306 self._mountpoint = mountpoint 308 self._mountpoint = mountpoint
307 self._mountopts = mountopts 309 self._mountopts = mountopts
308 self._format = format 310 self._format = format
309 if blocks == 0: 311 if blocks == 0:
310 self._blocks = ((self._end - self._start) * self._device.get_cylinder_size()) / 512 312 self._blocks = ((self._end - self._start) * self._device.get_cylinder_size()) / 512
311# if existing: 313 if existing:
312# parted_part = device._parted_disk.get_partition(minor) 314 parted_part = device._parted_disk.get_partition(minor)
313# if type == "ntfs": 315 if type == "ntfs":
314# 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 .\+//'")) 316 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 .\+//'"))
315# self._min_cylinders_for_resize = int(min_bytes / self._device._cylinder_bytes) + 1 317 self._min_cylinders_for_resize = int(min_bytes / self._device._cylinder_bytes) + 1
316# self._resizeable == True 318 self._resizeable == True
317# elif type == "ext2" or type == "ext3": 319 elif type == "ext2" or type == "ext3":
318# block_size = string.strip(commands.getoutput("dumpe2fs -h " + device._device + str(minor) + " 2>&1 | grep -e '^Block size:' | sed -e 's/^Block size:\s\+//'")) 320 block_size = string.strip(commands.getoutput("dumpe2fs -h " + device._device + str(minor) + r" 2>&1 | grep -e '^Block size:' | sed -e 's/^Block size:\s\+//'"))
319# free_blocks = string.strip(commands.getoutput("dumpe2fs -h " + device._device + str(minor) + " 2>&1 | grep -e '^Free blocks:' | sed -e 's/^Free blocks:\s\+//'")) 321 free_blocks = string.strip(commands.getoutput("dumpe2fs -h " + device._device + str(minor) + r" 2>&1 | grep -e '^Free blocks:' | sed -e 's/^Free blocks:\s\+//'"))
320# free_cyl = int(int(block_size) * int(free_blocks) / self._device._cylinder_bytes) 322 free_sec = int(int(block_size) * int(free_blocks) / self._device._sector_bytes)
321# free_cyl = int(free_cyl)
322# free_cyl = free_cyl - 200 # just to be safe 323 free_sec = free_sec - 2000 # just to be safe
323# self._min_cylinders_for_resize = (self._end - self._start + 1) - free_cyl 324 self._min_sectors_for_resize = (self._end - self._start + 1) - free_sec
324# self._resizeable == True 325 self._resizeable == True
325# elif type == "fat16" or type == "fat32": 326 else:
326# parted_part = self._device._parted_disk.get_partition(self._minor) 327 parted_part = self._device._parted_disk.get_partition(self._minor)
328 try:
327# parted_fs = parted_part.geom.file_system_open() 329 parted_fs = parted_part.geom.file_system_open()
330 except:
331 self._resizeable = False
332 return
328# resize_constraint = parted_fs.get_resize_constraint() 333 resize_constraint = parted_fs.get_resize_constraint()
329# min_size = float(resize_constraint.min_size / self._device._sectors_in_cylinder) 334 min_size = resize_constraint.min_size
330# if int(min_size) != min_size: min_size = int(min_size) + 1 335 if int(min_size) != min_size: min_size = int(min_size) + 1
331# self._min_cylinders_for_resize = min_size 336 self._min_sectors_for_resize = min_size
332# self._resizeable = True 337 self._resizeable = True
333# elif type == "":
334# self._min_cylinders_for_resize = 1
335# self._resizeable = True
336# else:
337# self._resizeable = True
338 338
339 def is_extended(self): 339 def is_extended(self):
340 if self._type == "extended": 340 if self._type == "extended":
341 return True 341 return True
342 else: 342 else:
351 def get_logicals(self): 351 def get_logicals(self):
352 if not self.is_extended(): 352 if not self.is_extended():
353 return None 353 return None
354 logicals = [] 354 logicals = []
355 start = self._start 355 start = self._start
356# while not start > self._end:
357# part = self._device.get_partition_at(start)
358# print "part=" + str(part)
359# if not part: break
360# logicals.append(part)
361# start = self._device._partitions[part].get_end() + 1
362 parts = self._device._partitions.keys() 356 parts = self._device._partitions.keys()
363 parts.sort() 357 parts.sort()
364 for part in parts: 358 for part in parts:
365 if part < 5: continue 359 if part < 5: continue
366 logicals.append(part) 360 logicals.append(part)
400 self._minor = int(minor) 394 self._minor = int(minor)
401 395
402 def get_minor(self): 396 def get_minor(self):
403 return int(self._minor) 397 return int(self._minor)
404 398
399 def set_orig_minor(self, orig_minor):
400 self._orig_minor = int(orig_minor)
401
402 def get_orig_minor(self):
403 return self._orig_minor
404
405 def set_mountpoint(self, mountpoint): 405 def set_mountpoint(self, mountpoint):
406 self._mountpoint = mountpoint 406 self._mountpoint = mountpoint
407 407
408 def get_mountpoint(self): 408 def get_mountpoint(self):
409 return self._mountpoint 409 return self._mountpoint
426 def get_min_sectors_for_resize(self): 426 def get_min_sectors_for_resize(self):
427 if self.is_extended(): 427 if self.is_extended():
428 min_size = self._start 428 min_size = self._start
429 for part in self._device._partitions: 429 for part in self._device._partitions:
430 if part < 5: continue 430 if part < 5: continue
431 min_size = part.get_end() 431 if part.get_end > min_size: min_size = part.get_end()
432 return min_size 432 return min_size
433 else: 433 else:
434 return self._min_sectors_for_resize 434 return self._min_sectors_for_resize
435 435
436 def get_max_sectors_for_resize(self): 436 def get_max_sectors_for_resize(self):
437 free_start, free_end = self._device.get_free_space(self._end) 437 free_start, free_end = self._device.get_free_space(self._end)
438 if free_end == -1: return self._end 438 if free_end == -1: return self._end
439 if free_start - 1 == self._end: 439 if free_start - 1 == self._end:
440 if self.is_logical(): 440 if self.is_logical():
441 if free_end <= self._device._partitions[self.get_extended_parent()]._end: 441 if free_end <= self._device._partitions[self.get_extended_parent()]._end:
442 return free_end 442 return free_end - self._start
443 else: 443 else:
444 return self._end 444 return self._end - self._start
445 else: 445 else:
446 return free_end 446 return free_end - self._start
447 447
448 def resize(self, start, end): 448 def resize(self, start, end):
449 part_at_start = self._device.get_partition_at(int(start)) 449 part_at_start = self._device.get_partition_at(int(start))
450 part_at_end = self._device.get_partition_at(int(end)) 450 part_at_end = self._device.get_partition_at(int(end))
451 logicals = None 451 logicals = None

Legend:
 Removed from v.212 changed lines Added in v.386