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

Diff of /trunk/src/GLIStorageDevice.py

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

Revision 543 Revision 544
124 self._partitions[last_log_free].set_mb(self._partitions[last_log_free].get_mb()+tmppart_log.get_mb()) 124 self._partitions[last_log_free].set_mb(self._partitions[last_log_free].get_mb()+tmppart_log.get_mb())
125 del self._partitions[part_log] 125 del self._partitions[part_log]
126 else: 126 else:
127 if not last_log_free: 127 if not last_log_free:
128 last_log_free = last_log_minor + 0.9 128 last_log_free = last_log_minor + 0.9
129 else:
130 lost_log_free = part_log
129 tmppart_log.set_minor(last_log_free) 131 tmppart_log.set_minor(last_log_free)
130 self._partitions[last_log_free] = tmppart_log 132 self._partitions[last_log_free] = tmppart_log
131 if part_log != last_log_free: del self._partitions[part_log] 133 if part_log != last_log_free: del self._partitions[part_log]
132 continue 134 continue
133 last_log_free = part_log
134 else: 135 else:
135 if part_log > (last_log_minor + 1): 136 if part_log > (last_log_minor + 1):
136 tmppart_log.set_minor(last_log_minor + 1) 137 tmppart_log.set_minor(last_log_minor + 1)
137 last_log_minor = last_log_minor + 1 138 last_log_minor = last_log_minor + 1
138 self._partitions[last_log_minor] = tmppart_log 139 self._partitions[last_log_minor] = tmppart_log
139 del self._partitions[part_log] 140 del self._partitions[part_log]
140 continue 141 continue
142 else:
141 last_log_minor = part_log 143 last_log_minor = part_log
142 if tmppart.get_type() == "free": 144 if tmppart.get_type() == "free":
143 if last_minor < last_free: 145 if last_minor < last_free:
144 self._partitions[last_free].set_mb(self._partitions[last_free].get_mb()+tmppart.get_mb()) 146 self._partitions[last_free].set_mb(self._partitions[last_free].get_mb()+tmppart.get_mb())
145 del self._partitions[part] 147 del self._partitions[part]
146 else: 148 else:
147 if not last_free: 149 if not last_free:
148 last_free = last_minor + 0.1 150 last_free = last_minor + 0.1
151 else:
152 last_free = part
149 tmppart.set_minor(last_free) 153 tmppart.set_minor(last_free)
150 self._partitions[last_free] = tmppart 154 self._partitions[last_free] = tmppart
151 if part != last_free: del self._partitions[part] 155 if part != last_free: del self._partitions[part]
152 continue 156 continue
153 last_free = part
154 else: 157 else:
155 if part > (last_minor + 1): 158 if part > (last_minor + 1):
156 tmppart.set_minor(last_minor + 1) 159 tmppart.set_minor(last_minor + 1)
157 last_minor = last_minor + 1 160 last_minor = last_minor + 1
158 self._partitions[last_minor] = tmppart 161 self._partitions[last_minor] = tmppart
159 del self._partitions[part] 162 del self._partitions[part]
160 continue 163 continue
164 else:
161 last_minor = part 165 last_minor = part
162 166
163 ## 167 ##
164 # Adds a new partition to the partition info 168 # Adds a new partition to the partition info
165 # @param free_minor minor of unallocated space partition is being created in 169 # @param free_minor minor of unallocated space partition is being created in
166 # @param mb size of partition in MB 170 # @param mb size of partition in MB
655 return -1 659 return -1
656 660
657 ## 661 ##
658 # Returns maximum MB for resize 662 # Returns maximum MB for resize
659 def get_max_mb_for_resize(self): 663 def get_max_mb_for_resize(self):
664 if self._resizeable:
660 free_minor = 0 665 free_minor = 0
666 if self.is_logical():
667 free_minor = self._minor + 0.9
668 else:
669 free_minor = self._minor + 0.1
670 if free_minor in self._device._partitions:
671 return self._mb + self._device._partitions[free_minor]._mb
672 else:
673 return self._mb
674 else:
675 return -1
676
677 ##
678 # Resizes the partition
679 # @param mb New size in MB
680 def resize(self, mb):
681 free_minor = self._minor
661 if self.is_logical(): 682 if self.is_logical():
662 free_minor = self._minor + 0.9 683 free_minor += 0.9
663 else: 684 else:
664 free_minor = self._minor + 0.1 685 free_minor += 0.1
686 if mb < self._mb:
687 # Shrinking
665 if free_minor in self._device._partitions: 688 if not free_minor in self._device._partitions:
689 self._device._partitions[free_minor] = Partition(self._device, free_minor, 0, 0, 0, "free", format=False, existing=False)
690 self._device._partitions[free_minor]._mb += self._mb - mb
691 self._mb = mb
666 return self._mb + self._device._partitions[free_minor]._mb 692 elif mb == self._mb + self._device._partitions[free_minor]._mb:
667 else: 693 # Using all available unallocated space
668 return self._mb 694 del self._device._partitions[free_minor]
669 695 self._mb = mb
670 ## 696 elif mb > self._mb:
671 # Resizes the partition (ignore) 697 # Growing
672 # @param start New start sector 698 self._device._partitions[free_minor]._mb = mb - self._mb
673 # @param end New end sector 699 self._mb = mb
674 def resize(self, start, end):
675 part_at_start = self._device.get_partition_at(int(start))
676 part_at_end = self._device.get_partition_at(int(end))
677 logicals = None
678 if self.is_logical():
679 parent = self.get_extended_parent()
680 parentstart = int(self._device._partitions[parent].get_start())
681 parentend = int(self._device._partitions[parent].get_end())
682 if (start < parentstart) or (end > parentend): return 0
683 if self.is_extended():
684 logicals = self.get_logicals()
685 if len(logicals):
686 logicals_start = self._device._partitions[logicals[0]].get_start()
687 logicals_end = self._device._partitions[logicals[len(logicals)-1]].get_end()
688 if (start > logicals_start) or (end < logicals_end): return 0
689 if part_at_start in logicals: part_at_start = 0
690 if part_at_end in logicals: part_at_end = 0
691 if ((not part_at_start == 0) and (part_at_start != self._minor)) or ((not part_at_end == 0) and (part_at_end != self._minor)):
692 return 0
693 self.set_start(start)
694 self.set_end(end)
695 return 1
696 700
697 ## 701 ##
698 # Utility function to raise an exception 702 # Utility function to raise an exception
699 # @param message Error message 703 # @param message Error message
700 def _error(self, message): 704 def _error(self, message):

Legend:
Removed from v.543  
changed lines
  Added in v.544

  ViewVC Help
Powered by ViewVC 1.1.20