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

Diff of /trunk/src/GLIStorageDevice.py

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

Revision 207 Revision 386
10 _total_sectors = 0 10 _total_sectors = 0
11 _cylinder_bytes = 0 11 _cylinder_bytes = 0
12 _sectors_in_cylinder = 0 12 _sectors_in_cylinder = 0
13 _parted_dev = None 13 _parted_dev = None
14 _parted_disk = None 14 _parted_disk = None
15 _fdiskcall = "fdisk -l " 15 _sector_bytes = 0
16 16
17 def __init__(self, device): 17 def __init__(self, device):
18 self._device = device 18 self._device = device
19 self._partitions = {} 19 self._partitions = {}
20 self._geometry = {'cylinders': 0, 'heads': 0, 'sectors': 0, 'sectorsize': 512} 20 self._geometry = {'cylinders': 0, 'heads': 0, 'sectors': 0, 'sectorsize': 512}
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._sector_bytes = self._parted_dev.sector_size
40 self._cylinder_bytes = self._geometry['heads'] * self._geometry['sectors'] * self._parted_dev.sector_size 41 self._cylinder_bytes = self._geometry['heads'] * self._geometry['sectors'] * self._sector_bytes
41 self._total_sectors = self._geometry['cylinders'] * self._geometry['heads'] * self._geometry['sectors'] 42# self._total_sectors = self._geometry['cylinders'] * self._geometry['heads'] * self._geometry['sectors']
43 self._total_sectors = self._parted_dev.length
42 self._sectors_in_cylinder = self._geometry['heads'] * self._geometry['sectors'] 44 self._sectors_in_cylinder = self._geometry['heads'] * self._geometry['sectors']
43 45
44 def set_partitions_from_disk(self): 46 def set_partitions_from_disk(self):
45 parted_part = self._parted_disk.next_partition() 47 parted_part = self._parted_disk.next_partition()
46 while parted_part != None: 48 while parted_part != None:
72 return self._device 74 return self._device
73 75
74 def clear_partitions(self): 76 def clear_partitions(self):
75 self._partitions = {} 77 self._partitions = {}
76 78
77 def add_partition(self, minor, start, end, type): 79 def add_partition(self, minor, start, end, type, mountpoint='', mountopts=''):
78 free_start, free_end = self.get_free_space(start) 80 free_start, free_end = self.get_free_space(start)
79 minor = int(minor) 81 minor = int(minor)
80 if not free_end: 82 if not free_end:
81 return False 83 return False
82 if self._partitions.has_key(minor): 84 if self._partitions.has_key(minor):
95 if (i >= hole_at) and (hole_at): continue 97 if (i >= hole_at) and (hole_at): continue
96 if i >= minor: 98 if i >= minor:
97 self._partitions[i].set_minor(i+1) 99 self._partitions[i].set_minor(i+1)
98 self._partitions[i+1] = self._partitions[i] 100 self._partitions[i+1] = self._partitions[i]
99 if i == minor: stopscooting = 1 101 if i == minor: stopscooting = 1
100 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)
101 103
102 def remove_partition(self, minor): 104 def remove_partition(self, minor):
103 del self._partitions[int(minor)] 105 del self._partitions[int(minor)]
104 106
105 def get_free_space(self, start): 107 def get_free_space(self, start):
211 213
212 def get_install_profile_structure(self): 214 def get_install_profile_structure(self):
213 devdic = {} 215 devdic = {}
214 for part in self._partitions: 216 for part in self._partitions:
215 tmppart = self._partitions[part] 217 tmppart = self._partitions[part]
216 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() }
217 return devdic 219 return devdic
218 220
219 def get_extended_partition(self): 221 def get_extended_partition(self):
220 for part in self._partitions: 222 for part in self._partitions:
221 tmppart = self._partitions[part] 223 tmppart = self._partitions[part]
227 return int(self._total_sectors) 229 return int(self._total_sectors)
228 230
229 def get_cylinder_size(self): 231 def get_cylinder_size(self):
230 return int(self._cylinder_bytes) 232 return int(self._cylinder_bytes)
231 233
234 def get_sector_size(self):
235 return int(self._sector_bytes)
236
232 def get_num_cylinders(self): 237 def get_num_cylinders(self):
233 return int(self._geometry['cylinders']) 238 return int(self._geometry['cylinders'])
234 239
235 def get_drive_bytes(self): 240 def get_drive_bytes(self):
236 return int(self._total_bytes) 241 return int(self._total_bytes)
276class Partition: 281class Partition:
277 "Class representing a single partition within a Device object" 282 "Class representing a single partition within a Device object"
278 283
279 _device = None 284 _device = None
280 _minor = None 285 _minor = None
286 _orig_minor = ""
281 _bootflag = None 287 _bootflag = None
282 _start = None 288 _start = None
283 _end = None 289 _end = None
284 _blocks = None 290 _blocks = None
285 _type = None 291 _type = None
290 _min_sectors_for_resize = 0 296 _min_sectors_for_resize = 0
291 297
292 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):
293 self._device = device 299 self._device = device
294 self._minor = int(minor) 300 self._minor = int(minor)
301 if existing: self._orig_minor = int(minor)
295 self._bootflag = bootflag 302 self._bootflag = bootflag
296 self._start = int(start) 303 self._start = int(start)
297 self._end = int(end) 304 self._end = int(end)
298 self._blocks = int(blocks) 305 self._blocks = int(blocks)
299 if type == "": type = "unknown" 306 if type == "": type = "unknown"
301 self._mountpoint = mountpoint 308 self._mountpoint = mountpoint
302 self._mountopts = mountopts 309 self._mountopts = mountopts
303 self._format = format 310 self._format = format
304 if blocks == 0: 311 if blocks == 0:
305 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
306# if existing: 313 if existing:
307# parted_part = device._parted_disk.get_partition(minor) 314 parted_part = device._parted_disk.get_partition(minor)
308# if type == "ntfs": 315 if type == "ntfs":
309# 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 .\+//'"))
310# 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
311# self._resizeable == True 318 self._resizeable == True
312# elif type == "ext2" or type == "ext3": 319 elif type == "ext2" or type == "ext3":
313# 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\+//'"))
314# 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\+//'"))
315# 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)
316# free_cyl = int(free_cyl)
317# free_cyl = free_cyl - 200 # just to be safe 323 free_sec = free_sec - 2000 # just to be safe
318# 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
319# self._resizeable == True 325 self._resizeable == True
320# elif type == "fat16" or type == "fat32": 326 else:
321# parted_part = self._device._parted_disk.get_partition(self._minor) 327 parted_part = self._device._parted_disk.get_partition(self._minor)
328 try:
322# 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
323# resize_constraint = parted_fs.get_resize_constraint() 333 resize_constraint = parted_fs.get_resize_constraint()
324# min_size = float(resize_constraint.min_size / self._device._sectors_in_cylinder) 334 min_size = resize_constraint.min_size
325# 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
326# self._min_cylinders_for_resize = min_size 336 self._min_sectors_for_resize = min_size
327# self._resizeable = True 337 self._resizeable = True
328# elif type == "":
329# self._min_cylinders_for_resize = 1
330# self._resizeable = True
331# else:
332# self._resizeable = True
333 338
334 def is_extended(self): 339 def is_extended(self):
335 if self._type == "extended": 340 if self._type == "extended":
336 return True 341 return True
337 else: 342 else:
346 def get_logicals(self): 351 def get_logicals(self):
347 if not self.is_extended(): 352 if not self.is_extended():
348 return None 353 return None
349 logicals = [] 354 logicals = []
350 start = self._start 355 start = self._start
351# while not start > self._end:
352# part = self._device.get_partition_at(start)
353# print "part=" + str(part)
354# if not part: break
355# logicals.append(part)
356# start = self._device._partitions[part].get_end() + 1
357 parts = self._device._partitions.keys() 356 parts = self._device._partitions.keys()
358 parts.sort() 357 parts.sort()
359 for part in parts: 358 for part in parts:
360 if part < 5: continue 359 if part < 5: continue
361 logicals.append(part) 360 logicals.append(part)
395 self._minor = int(minor) 394 self._minor = int(minor)
396 395
397 def get_minor(self): 396 def get_minor(self):
398 return int(self._minor) 397 return int(self._minor)
399 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
400 def set_mountpoint(self, mountpoint): 405 def set_mountpoint(self, mountpoint):
401 self._mountpoint = mountpoint 406 self._mountpoint = mountpoint
402 407
403 def get_mountpoint(self): 408 def get_mountpoint(self):
404 return self._mountpoint 409 return self._mountpoint
421 def get_min_sectors_for_resize(self): 426 def get_min_sectors_for_resize(self):
422 if self.is_extended(): 427 if self.is_extended():
423 min_size = self._start 428 min_size = self._start
424 for part in self._device._partitions: 429 for part in self._device._partitions:
425 if part < 5: continue 430 if part < 5: continue
426 min_size = part.get_end() 431 if part.get_end > min_size: min_size = part.get_end()
427 return min_size 432 return min_size
428 else: 433 else:
429 return self._min_sectors_for_resize 434 return self._min_sectors_for_resize
430 435
431 def get_max_sectors_for_resize(self): 436 def get_max_sectors_for_resize(self):
432 free_start, free_end = self._device.get_free_space(self._end) 437 free_start, free_end = self._device.get_free_space(self._end)
433 if free_end == -1: return self._end 438 if free_end == -1: return self._end
434 if free_start - 1 == self._end: 439 if free_start - 1 == self._end:
435 if self.is_logical(): 440 if self.is_logical():
436 if free_end <= self._device._partitions[self.get_extended_parent()]._end: 441 if free_end <= self._device._partitions[self.get_extended_parent()]._end:
437 return free_end 442 return free_end - self._start
438 else: 443 else:
439 return self._end 444 return self._end - self._start
440 else: 445 else:
441 return free_end 446 return free_end - self._start
442 447
443 def resize(self, start, end): 448 def resize(self, start, end):
444 part_at_start = self._device.get_partition_at(int(start)) 449 part_at_start = self._device.get_partition_at(int(start))
445 part_at_end = self._device.get_partition_at(int(end)) 450 part_at_end = self._device.get_partition_at(int(end))
446 logicals = None 451 logicals = None

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

  ViewVC Help
Powered by ViewVC 1.1.20