[PATCH] Enforce limits on the number of partitions on a disk.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ignore preexisting disks with too many partitions. Also make sure we don't
try to allocate more than the maximum allowed number of partitions from a
disk during partitioning.
---
 storage/devicetree.py   |   37 +++++++++++++++++++++++++++++++++++++
 storage/partitioning.py |    9 +++++++++
 2 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/storage/devicetree.py b/storage/devicetree.py
index f026348..c2241c5 100644
--- a/storage/devicetree.py
+++ b/storage/devicetree.py
@@ -21,6 +21,7 @@
 #
 
 import os
+import sys
 import block
 import re
 
@@ -33,6 +34,7 @@ import formats
 import devicelibs.mdraid
 from udev import *
 from iutil import log_method_call
+from constants import productName
 
 import gettext
 _ = lambda x: gettext.ldgettext("anaconda", x)
@@ -120,6 +122,31 @@ def getLUKSPassphrase(intf, device, globalPassphrase):
 
     return (passphrase, isglobal)
 
+def handleDiskMaxPartitionsExceeded(intf, device):
+    """ Ask user how to handle disk with too many partitions.
+
+        Choices are to ignore the disk or to exit the installer.
+
+        A return value of True indicates the user wants to continue with
+        installation without using this device.
+    """
+    maxPartitionCount = device.partedDisk.maxPrimaryPartitionCount + \
+                        device.partedDisk.getMaxLogicalPartitions()
+    str = _("The drive %s has more than %d partitions on it,"
+            "which is the maximum number of partitions for disk of "
+            "this type. You will not be able to make changes to the "
+            "partitioning of this disk or use any partitions beyond "
+            "%s%d in %s") % (device.path, maxPartitionCount, device.name,
+                             maxPartitionCount, productName)
+
+    rc = intf.messageWindow(_("Warning"), str, type="custom",
+                            custom_buttons = [_("_Reboot"), _("_Ignore")],
+                            custom_icon="warning")
+    if rc == 0:
+        sys.exit(0)
+
+    return True
+
 # Don't really know where to put this.
 def questionInitializeDisk(intf=None, name=None):
     retVal = False # The less destructive default
@@ -1114,6 +1141,16 @@ class DeviceTree(object):
             self.addIgnoredDisk(name)
             return
 
+        # make sure the disk does not have more partitions than are supported
+        if device.mediaPresent:
+            maxPartitionCount = device.partedDisk.maxPrimaryPartitionCount + \
+                                device.partedDisk.getMaxLogicalPartitions()
+
+            if len(device.partedDisk.partitions) > maxPartitionCount and \
+               handleDiskMaxPartitionsExceeded(self.intf, device):
+                self.addIgnoredDisk(name)
+                return
+
         self._addDevice(device)
 
         # If this is a mac-formatted disk we just initialized, make sure the
diff --git a/storage/partitioning.py b/storage/partitioning.py
index 8e9ab3c..f2c036f 100644
--- a/storage/partitioning.py
+++ b/storage/partitioning.py
@@ -697,6 +697,15 @@ def allocatePartitions(disks, partitions):
         # loop through disks
         for _disk in req_disks:
             disk = partedDisks[_disk.path]
+
+            # check if we can allocate new partitions from this disk
+            max_parts = disk.maxPrimaryPartitionCount + \
+                        disk.getMaxLogicalPartitions()
+            if len(disk.partitions) >= max_parts:
+                log.debug("disk %s already has its maximum allowable number"
+                          " of partitions (%d)" % (_disk.name, max_parts))
+                continue
+
             #for p in disk.partitions:
             #    log.debug("disk %s: part %s" % (disk.device.path, p.path))
             sectorSize = disk.device.physicalSectorSize
-- 
1.6.0.6

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux