Subject: PR#10777: make disklabel to warn overlapping partition
To: None <tech-userlevel@netbsd.org>
From: enami tsugutomo <enami@sm.sony.co.jp>
List: tech-userlevel
Date: 07/07/2004 09:49:50
Does anyone object if following patch (which is functionally identical
to the one found in the PR database) is commited to close PR#10777
(which requests our disklabel to warn overlapping partition)?

enami.

Index: disklabel.c
===================================================================
RCS file: /cvsroot/src/sbin/disklabel/disklabel.c,v
retrieving revision 1.133
diff -u -r1.133 disklabel.c
--- disklabel.c	24 Jun 2004 03:13:00 -0000	1.133
+++ disklabel.c	7 Jul 2004 00:31:53 -0000
@@ -1717,8 +1718,8 @@
 int
 checklabel(struct disklabel *lp)
 {
-	struct partition *pp;
-	int	i, errors;
+	struct partition *pp, *qp;
+	int	i, j, errors;
 	char	part;
 
 	errors = 0;
@@ -1804,6 +1805,16 @@
 			    part);
 			errors++;
 		}
+		if (pp->p_fstype != FS_UNUSED)
+			for (j = i + 1; j < lp->d_npartitions; j++) {
+				qp = &lp->d_partitions[j];
+				if (qp->p_fstype == FS_UNUSED)
+					continue;
+				if (pp->p_offset < qp->p_offset + qp->p_size &&
+				    qp->p_offset < pp->p_offset + pp->p_size)
+					warnx("partitions %c and %c overlap",
+					    part, 'a' + j);
+			}
 	}
 	return (errors);
 }