Subject: bin/10777: disklabel should warn about overlapping partitions
To: None <gnats-bugs@gnats.netbsd.org>
From: None <kalt@taranis.org>
List: netbsd-bugs
Date: 08/07/2000 14:14:13
>Number:         10777
>Category:       bin
>Synopsis:       disklabel does not warn about overlapping partitions
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Aug 07 14:15:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Christophe Kalt
>Release:        1.5_ALPHA (snapshot from 6/20 or so)
>Organization:
	
>Environment:
	
System: NetBSD bzz.taranis.org 1.5_ALPHA NetBSD 1.5_ALPHA (bzz) #0: Fri Aug 4 17:10:25 EDT 2000 kalt@bzz.taranis.org:NetBSD/syssrc-1.5/sys/arch/sparc/compile/bzz sparc


>Description:
the attached diff modifies disklabel to check that there are no overlaps
in the partition table.

i can't think of any case when someone would want to have overlaps, but if
there are, then this diff isn't going to be good enough as it makes it
impossible (afaict, at least with -e) to have overlaps.
removing the added "errors += 1;" line might be a good option in this case.
>How-To-Repeat:
this should be obvious.. :)
>Fix:

Index: disklabel.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/disklabel/disklabel.c,v
retrieving revision 1.86
diff -u -r1.86 disklabel.c
--- disklabel.c	2000/07/13 01:47:22	1.86
+++ disklabel.c	2000/08/07 21:03:47
@@ -1754,7 +1754,7 @@
 	struct disklabel *lp;
 {
 	struct partition *pp;
-	int i, errors = 0;
+	int i, j, errors = 0;
 	char part;
 
 	if (lp->d_secsize == 0) {
@@ -1824,9 +1824,30 @@
 		if (pp->p_offset + pp->p_size > lp->d_secperunit) {
 			warnx("partition %c: partition extends"
 			      " past end of unit",
-			    part);
+			      part);
 			errors++;
 		}
+		if (pp->p_size != 0 && pp->p_size != lp->d_secperunit)
+			for (j = i+1; j < lp->d_npartitions; j++ ) {
+		    		struct partition *op;
+				char other;
+				int pend, oend;
+				
+				op = &lp->d_partitions[j];
+				other = 'a' + j;
+				if (op->p_size == 0
+				    || op->p_size == lp->d_secperunit)
+				     continue;
+				pend = pp->p_offset + pp->p_size - 1;
+				oend = op->p_offset + op->p_size - 1;
+				if ((op->p_offset >= pp->p_offset &&
+				     op->p_offset <= pend) ||
+				    (oend >= pp->p_offset && oend <= pend)) {
+					warnx("partitions %c and %c overlap.",
+					      part, other);
+					errors += 1;
+				}
+			}
 	}
 	for (; i < MAXPARTITIONS; i++) {
 		part = 'a' + i;
>Release-Note:
>Audit-Trail:
>Unformatted: