[parted-devel] > 63 heads. Why does this keep coming up?

Phillip Susi psusi at cfl.rr.com
Sat Feb 12 22:05:40 UTC 2011


I have patched the function to not use PED_ASSERT() so it properly 
returns 0 when the constraints fail.  This seems to fix the issue. 
Please review for application:

=== modified file 'libparted/labels/dos.c'
--- libparted/labels/dos.c	2010-08-05 21:06:19 +0000
+++ libparted/labels/dos.c	2011-02-12 21:40:50 +0000
@@ -645,8 +645,10 @@
  	if (cyl_size * denum != a_*H - A_*h)
  		return 0;

-	PED_ASSERT (cyl_size > 0, return 0);
- 	PED_ASSERT (cyl_size <= 255 * 63, return 0);
+	if (cyl_size <= 0)
+		return 0;
+ 	if (cyl_size > 255 * 63)
+		return 0;

  	if (h > 0)
  		head_size = ( a_ - c * cyl_size ) / h;
@@ -657,18 +659,24 @@
  		PED_ASSERT (0, return 0);
  	}

-	PED_ASSERT (head_size > 0, return 0);
-	PED_ASSERT (head_size <= 63, return 0);
+	if (head_size <= 0)
+		return 0;
+	if (head_size > 63)
+		return 0;

  	cylinders = part->disk->dev->length / cyl_size;
  	heads = cyl_size / head_size;
  	sectors = head_size;

-	PED_ASSERT (heads > 0, return 0);
-	PED_ASSERT (heads < 256, return 0);
+	if (heads <= 0)
+		return 0;
+	if (heads > 255)
+		return 0;

-	PED_ASSERT (sectors > 0, return 0);
-	PED_ASSERT (sectors <= 63, return 0);
+	if (sectors <= 0)
+		return 0;
+	if (sectors > 63)
+		return 0;

  	/* Some broken OEM partitioning program(s) seem to have an out-by-one
  	 * error on the end of partitions.  We should offer to fix the
@@ -677,8 +685,10 @@
  	if (((C + 1) * heads + H) * sectors + S == A)
  		C++;

-	PED_ASSERT ((c * heads + h) * sectors + s == a, return 0);
-	PED_ASSERT ((C * heads + H) * sectors + S == A, return 0);
+	if ((c * heads + h) * sectors + s != a)
+		return 0;
+        if ((C * heads + H) * sectors + S != A)
+		return 0;

  	bios_geom->cylinders = cylinders;
  	bios_geom->heads = heads;



More information about the parted-devel mailing list