OSDN Git Service

dos: fix a bug affecting very small devices (smaller than 1 cylinder)
authorJim Meyering <meyering@redhat.com>
Tue, 9 Nov 2010 09:25:36 +0000 (10:25 +0100)
committerJim Meyering <meyering@redhat.com>
Tue, 9 Nov 2010 09:29:35 +0000 (10:29 +0100)
This bug was introduced in commit c79d91ec, "dos: accommodate very
small devices (useful for testing)".
* libparted/labels/dos.c (_primary_constraint): The bug was to
skip setting start_geom for small devices.  That led to a used-
uninitialized bug in the subsequent ped_constraint_new call.
The fix is to relax the constraint to use a starting sector of "1",
if necessary.  Report and diagnosis by Jean-Christian de Rivaz in
http://thread.gmane.org/gmane.comp.gnu.parted.bugs/10178
* NEWS (Bug fixes): Mention it.

NEWS
libparted/labels/dos.c

diff --git a/NEWS b/NEWS
index 5dd7dca..4979b90 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,10 @@ GNU parted NEWS                                    -*- outline -*-
   libparted now recognizes scsi disks with a high major (128-135) as scsi
   disks
 
+  an msdos partition table on a very small device (smaller than one cylinder)
+  is now recognized.  [bug introduced in parted-2.2]
+
+
 * Noteworthy changes in release 2.3 (2010-05-28) [stable]
 
 ** New features
index d9e7d4a..578180b 100644 (file)
@@ -1713,13 +1713,13 @@ _primary_constraint (const PedDisk* disk, const PedCHSGeometry* bios_geom,
                                        dev->length - min_geom->end))
                        return NULL;
        } else {
-               /* Do not assume that length is larger than 1 cylinder's
-                  worth of sectors.  This is useful when testing with
-                  a memory-mapped "disk" (a la scsi_debug) that is say,
-                  2048 sectors long.  */
-               if (cylinder_size < dev->length
-                   && !ped_geometry_init (&start_geom, dev, cylinder_size,
-                                          dev->length - cylinder_size))
+               /* Use cylinder_size as the starting sector number
+                  when the device is large enough to accommodate that.
+                  Otherwise, use sector 1.  */
+               PedSector start = (cylinder_size < dev->length
+                                  ? cylinder_size : 1);
+               if (!ped_geometry_init (&start_geom, dev, start,
+                                       dev->length - start))
                        return NULL;
                if (!ped_geometry_init (&end_geom, dev, 0, dev->length))
                        return NULL;