[PATCH] Stop the user from creating msdos labels in drives that have more than 2^32 sectors. libparted/labels/dos.c: After creating the disk in memory, check how many sectors in has. If the sector count exceeds UINT_MAX, we tell the uesr that the label creation cannot be performed.

Joel Granados Moreno jgranado at redhat.com
Fri Nov 14 18:25:42 UTC 2008


---
 libparted/labels/dos.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c
index cb7e45e..c237cae 100644
--- a/libparted/labels/dos.c
+++ b/libparted/labels/dos.c
@@ -243,6 +243,25 @@ msdos_alloc (const PedDevice* dev)
 	disk = _ped_disk_alloc ((PedDevice*)dev, &msdos_disk_type);
 	if (disk)
 		disk->disk_specific = NULL;
+
+    /* We need to check if the user is trying to create an msdos table on a
+     * disk that has more than the addressable size of sectors.  Msdos
+     * partition table is capable of addressing 2^32 sectors.  Going to use
+     * lenght because this containes the total sectors for the device.
+     *
+     * Do we need an override option for this check?
+     */
+    if(disk->dev->length > UINT32_MAX){
+        ped_exception_throw(
+                PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+                _("%s labels do not support devices that have more than "
+                    "%jd sectors."),
+                msdos_disk_type.name,
+                UINT32_MAX);
+        _ped_disk_free(disk);
+        return NULL;
+
+    }
 	return disk;
 }
 
-- 
1.5.6.5


------=_Part_113976_429989511.1226687340690--



More information about the parted-devel mailing list