diff -u -r1.32 -r1.33
--- parted/stable/libparted/disk_dos.c	2005/08/03 07:56:07	1.32
+++ parted/stable/libparted/disk_dos.c	2005/08/22 22:19:31	1.33
@@ -1690,6 +1690,60 @@
 		return base_head + 1;
 }
 
+/* Shamelessly copied and adapted from _partition_get_overlap_constraint
+ * (in disk.c)
+ * This should get ride of the infamous Assertion (metadata_length > 0) failed
+ * bug for extended msdos disklabels generated by Parted.
+ * 1) There always is a partition table at the start of ext_part, so we leave
+ *    a one sector gap there.
+ * 2)*The partition table of part5 is always at the beginning of the ext_part
+ *    so there is no need to leave a one sector gap before part5.
+ *   *There always is a partition table at the beginning of each partition != 5.
+ * We don't need to worry to much about consistency with 
+ * _partition_get_overlap_constraint because missing it means we are in edge
+ * cases anyway, and we don't lose anything by just refusing to do the job in
+ * those cases.
+ */
+static PedConstraint*
+_log_meta_overlap_constraint (PedPartition* part, PedGeometry* geom)
+{
+	PedGeometry	safe_space;
+	PedSector	min_start;
+	PedSector	max_end;
+	PedPartition*	ext_part = ped_disk_extended_partition (part->disk);
+	PedPartition*	walk;
+	int		not_5 = (part->num != 5);
+
+	PED_ASSERT (ext_part != NULL, return NULL);
+
+	walk = ext_part->part_list;
+
+	/*                                 1)  2)     */
+	min_start = ext_part->geom.start + 1 + not_5; 
+	max_end = ext_part->geom.end;
+
+	while (walk != NULL             /*      2)                         2) */
+		&& (   walk->geom.start - (walk->num != 5) < geom->start - not_5
+		    || walk->geom.start - (walk->num != 5) <= min_start )) {
+		if (walk != part)
+			min_start = walk->geom.end + 1 + not_5; /* 2) */
+		walk = walk->next;
+	}
+
+	if (walk == part)
+		walk = walk->next;
+
+	if (walk)
+		max_end = walk->geom.start - 1 - (walk->num != 5); /* 2) */
+
+	if (min_start >= max_end)
+		return NULL;
+
+	ped_geometry_init (&safe_space, part->disk->dev,
+			   min_start, max_end - min_start + 1);
+	return ped_constraint_new_from_max (&safe_space);
+}
+
 static int
 _align_logical (PedPartition* part, const PedCHSGeometry* bios_geom,
 		const PedConstraint* constraint)
@@ -1701,9 +1755,16 @@
 	PedSector	start_base;
 	int		head;
 	PedGeometry*	solution = NULL;
+	PedConstraint   *intersect, *log_meta_overlap;
 
 	PED_ASSERT (ext_part != NULL, return 0);
 
+	log_meta_overlap = _log_meta_overlap_constraint(part, &part->geom);
+	intersect = ped_constraint_intersect (constraint, log_meta_overlap);
+	ped_constraint_destroy (log_meta_overlap);
+	if (!intersect)
+		return 0;
+
 	start_base = ped_round_down_to (part->geom.start, cyl_size);
 
 	for (head = _logical_min_start_head (part, bios_geom, ext_part, 0);
@@ -1720,10 +1781,12 @@
 				_logical_constraint (disk, bios_geom, start, 0);
 
 		solution = _best_solution (part, bios_geom, solution,
-				_try_constraint (part, constraint,
+				_try_constraint (part, intersect,
 						 disk_constraint));
 	}
 
+	ped_constraint_destroy (intersect);
+
 	if (solution) {
 		ped_geometry_set (&part->geom, solution->start,
 				  solution->length);
@@ -1800,39 +1863,13 @@
 	return 0;
 }
 
-static PedSector
-_calc_min_logical_start (PedPartition* part)
-{
-	PedDisk*	disk = part->disk;
-	PedPartition*	ext_part = ped_disk_extended_partition (disk);
-	PedPartition*	walk;
-
-	for (walk = ext_part->part_list; walk && walk != part;
-	     walk = walk->next) {
-		if (walk->geom.end > part->geom.start) {
-			if (walk->prev)
-				return walk->prev->geom.end + 2;
-			break;
-		}
-	}
-
-	if (part->num == 5)
-		return ext_part->geom.start + 1;
-	else
-		return ext_part->geom.start + 2;
-}
-
 static int
 _align_logical_no_geom (PedPartition* part, const PedConstraint* constraint)
 {
-	PedDisk*	disk = part->disk;
-	PedPartition*	ext_part = ped_disk_extended_partition (disk);
-	PedSector	min_start = _calc_min_logical_start (part);
 	PedGeometry*	solution;
 
 	solution = _try_constraint (part, constraint,
-			_no_geom_constraint (disk, min_start,
-					     ext_part->geom.end));
+			_log_meta_overlap_constraint (part, &part->geom));
 
 	if (solution) {
 		ped_geometry_set (&part->geom, solution->start,
