[master 1/2] Robustify PartitionDevice._wipe() method.
mulkieran
installerbot-noreply at redhat.com
Mon Mar 9 21:03:44 UTC 2015
From: mulhern <amulhern at redhat.com>
Previously, if block size is larger than 1 MiB, nothing gets erased.
Now, the smallest number of blocks that erases at least 1 MiB is wiped.
---
blivet/devices/partition.py | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/blivet/devices/partition.py b/blivet/devices/partition.py
index 5cccf4e..01f2c88 100644
--- a/blivet/devices/partition.py
+++ b/blivet/devices/partition.py
@@ -528,17 +528,30 @@ def probe(self):
self._bootable = self.getFlag(parted.PARTITION_BOOT)
def _wipe(self):
- """ Wipe the partition metadata. """
+ """ Wipe the partition metadata.
+
+ Assumes that the partition metadata is located at the start
+ of the partition and occupies no more than 1 MiB.
+
+ Erases in block increments. Erases the smallest number of blocks
+ such that at least 1 MiB is erased or the whole partition is
+ erased.
+ """
log_method_call(self, self.name, status=self.status)
start = self.partedPartition.geometry.start
part_len = self.partedPartition.geometry.end - start
bs = Size(self.partedPartition.geometry.device.sectorSize)
- device = self.partedPartition.geometry.device.path
- # Erase 1MiB or to end of partition
- count = min(int(Size("1 MiB") // bs), part_len)
+ # Ensure that count is smallest value such that count * bs >= 1 MiB
+ (count, rem) = divmod(Size("1 MiB"), bs)
+ if rem:
+ count += 1
+
+ # Ensure that count <= part_len
+ count = min(count, part_len)
+ device = self.partedPartition.geometry.device.path
cmd = ["dd", "if=/dev/zero", "of=%s" % device, "bs=%d" % int(bs),
"seek=%s" % start, "count=%s" % count]
try:
--
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/9f9954d14423ce93c57326a0d2192dce70537a6e
More information about the anaconda-patches
mailing list