[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Removal of partition reordering code
From:       Garrett Kajmowicz <gkajmowi () tbaytel ! net>
Date:       2006-02-25 4:55:22
Message-ID: 200602242355.22437.gkajmowi () tbaytel ! net
[Download RAW message or body]

The attached patch removes partition reordering code.  Though it was kept 
under the "advanced" subsection, it is potentially harmful if you depend on 
the order of partitions (such as Dell recovery CDs).  In addition, the 
removal saves a few bytes and makes the code simpler all-around.


-     Garrett

["remove_partition_reorder.patch" (text/x-diff)]

--- busybox/util-linux/fdisk.c	2006-02-24 23:26:12.000000000 -0500
+++ busybox-new/util-linux/fdisk.c	2006-02-24 23:51:48.000000000 -0500
@@ -3599,7 +3599,6 @@
 		puts(_("\tc\tchange number of cylinders"));
 		puts(_("\td\tprint the raw data in the partition table"));
 		puts(_("\te\tlist extended partitions"));          /* !sun */
-		puts(_("\tf\tfix partition order"));               /* !sun, !aix, !sgi */
 #ifdef CONFIG_FEATURE_SGI_LABEL
 		puts(_("\tg\tcreate an IRIX (SGI) partition table"));/* sgi */
 #endif
@@ -4703,147 +4702,6 @@
 		   units_per_sector, sector_size, units_per_sector * sector_size);
 }
 
-/*
- * Check whether partition entries are ordered by their starting positions.
- * Return 0 if OK. Return i if partition i should have been earlier.
- * Two separate checks: primary and logical partitions.
- */
-static int
-wrong_p_order(int *prev)
-{
-	const struct pte *pe;
-	const struct partition *p;
-	off_t last_p_start_pos = 0, p_start_pos;
-	int i, last_i = 0;
-
-	for (i = 0 ; i < partitions; i++) {
-		if (i == 4) {
-			last_i = 4;
-			last_p_start_pos = 0;
-		}
-		pe = &ptes[i];
-		if ((p = pe->part_table)->sys_ind) {
-			p_start_pos = get_partition_start(pe);
-
-			if (last_p_start_pos > p_start_pos) {
-				if (prev)
-					*prev = last_i;
-				return i;
-			}
-
-			last_p_start_pos = p_start_pos;
-			last_i = i;
-		}
-	}
-	return 0;
-}
-
-#ifdef CONFIG_FEATURE_FDISK_ADVANCED
-/*
- * Fix the chain of logicals.
- * extended_offset is unchanged, the set of sectors used is unchanged
- * The chain is sorted so that sectors increase, and so that
- * starting sectors increase.
- *
- * After this it may still be that cfdisk doesnt like the table.
- * (This is because cfdisk considers expanded parts, from link to
- * end of partition, and these may still overlap.)
- * Now
- *   sfdisk /dev/hda > ohda; sfdisk /dev/hda < ohda
- * may help.
- */
-static void
-fix_chain_of_logicals(void)
-{
-	int j, oj, ojj, sj, sjj;
-	struct partition *pj,*pjj,tmp;
-
-	/* Stage 1: sort sectors but leave sector of part 4 */
-	/* (Its sector is the global extended_offset.) */
- stage1:
-	for (j = 5; j < partitions-1; j++) {
-		oj = ptes[j].offset;
-		ojj = ptes[j+1].offset;
-		if (oj > ojj) {
-			ptes[j].offset = ojj;
-			ptes[j+1].offset = oj;
-			pj = ptes[j].part_table;
-			set_start_sect(pj, get_start_sect(pj)+oj-ojj);
-			pjj = ptes[j+1].part_table;
-			set_start_sect(pjj, get_start_sect(pjj)+ojj-oj);
-			set_start_sect(ptes[j-1].ext_pointer,
-					   ojj-extended_offset);
-			set_start_sect(ptes[j].ext_pointer,
-					   oj-extended_offset);
-			goto stage1;
-		}
-	}
-
-	/* Stage 2: sort starting sectors */
- stage2:
-	for (j = 4; j < partitions-1; j++) {
-		pj = ptes[j].part_table;
-		pjj = ptes[j+1].part_table;
-		sj = get_start_sect(pj);
-		sjj = get_start_sect(pjj);
-		oj = ptes[j].offset;
-		ojj = ptes[j+1].offset;
-		if (oj+sj > ojj+sjj) {
-			tmp = *pj;
-			*pj = *pjj;
-			*pjj = tmp;
-			set_start_sect(pj, ojj+sjj-oj);
-			set_start_sect(pjj, oj+sj-ojj);
-			goto stage2;
-		}
-	}
-
-	/* Probably something was changed */
-	for (j = 4; j < partitions; j++)
-		ptes[j].changed = 1;
-}
-
-
-static void
-fix_partition_table_order(void)
-{
-	struct pte *pei, *pek;
-	int i,k;
-
-	if (!wrong_p_order(NULL)) {
-		printf(_("Nothing to do. Ordering is correct already.\n\n"));
-		return;
-	}
-
-	while ((i = wrong_p_order(&k)) != 0 && i < 4) {
-		/* partition i should have come earlier, move it */
-		/* We have to move data in the MBR */
-		struct partition *pi, *pk, *pe, pbuf;
-		pei = &ptes[i];
-		pek = &ptes[k];
-
-		pe = pei->ext_pointer;
-		pei->ext_pointer = pek->ext_pointer;
-		pek->ext_pointer = pe;
-
-		pi = pei->part_table;
-		pk = pek->part_table;
-
-		memmove(&pbuf, pi, sizeof(struct partition));
-		memmove(pi, pk, sizeof(struct partition));
-		memmove(pk, &pbuf, sizeof(struct partition));
-
-		pei->changed = pek->changed = 1;
-	}
-
-	if (i)
-		fix_chain_of_logicals();
-
-	printf("Done.\n");
-
-}
-#endif
-
 static void
 list_table(int xtra)
 {
@@ -5485,10 +5343,6 @@
 			if (label_dos == current_label_type)
 				x_list_table(1);
 			break;
-		case 'f':
-			if (label_dos == current_label_type)
-				fix_partition_table_order();
-			break;
 		case 'g':
 #ifdef CONFIG_FEATURE_SGI_LABEL
 			create_sgilabel();


_______________________________________________
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic