Subject: Re: disklabeling a 1.7 TB disk
To: None <current-users@netbsd.org>
From: David Laight <david@l8s.co.uk>
List: current-users
Date: 02/28/2004 19:00:24
On Fri, Feb 27, 2004 at 05:51:31PM -0500, Jan Schaumann wrote:
> Ok, I'm going completely insane here.  I have a 1.7 TB disk, that I'm
> desparately trying to disklabel.  So:

> cylinders: -869262
> total sectors: -876216576

printfs now fixed in current.

> Ok, so I think: how about I correct the faulty fields?  I fix 'total

> total sectors: 2147483647

This patch should fix disklabel so that it will accept up to 2^32-1
for important fields.

Going beyond 2^32 sectors is hard.....

	David

Index: disklabel.c
===================================================================
RCS file: /cvsroot/src/sbin/disklabel/disklabel.c,v
retrieving revision 1.126
diff -u -p -r1.126 disklabel.c
--- disklabel.c	18 Jan 2004 22:34:22 -0000	1.126
+++ disklabel.c	28 Feb 2004 18:52:16 -0000
@@ -1458,12 +1458,7 @@ getasciilabel(FILE *f, struct disklabel 
 			continue;
 		}
 		if (!strcmp(cp, "total sectors")) {
-			v = atoi(tp);
-			if (v <= 0) {
-				warnx("line %d: bad %s: %s", lineno, cp, tp);
-				errors++;
-			} else
-				lp->d_secperunit = v;
+			lp->d_secperunit = strtoul(tp, NULL, 10);
 			continue;
 		}
 		if (!strcmp(cp, "rpm")) {
@@ -1545,11 +1540,11 @@ getasciilabel(FILE *f, struct disklabel 
 
 #define NXTXNUM(n) do { \
 	char	*ptr;							\
-	int	 m;							\
+	uint32_t m;							\
 									\
 	_CHECKLINE							\
 	cp = tp, tp = word(cp);						\
-	m = (int)strtol(cp, &ptr, 10);					\
+	m = strtoul(cp, &ptr, 10);					\
 	if (*ptr == '\0')						\
 		(n) = m;						\
 	else {								\
@@ -1559,32 +1554,21 @@ getasciilabel(FILE *f, struct disklabel 
 			break;						\
 		}							\
 		(n) = m * lp->d_secpercyl;				\
-		m = (int)strtol(ptr, &ptr, 10);				\
+		m = strtoul(ptr, &ptr, 10);				\
 		if (*ptr++ != '/') {					\
 			warnx("line %d: invalid format", lineno);	\
 			errors++;					\
 			break;						\
 		}							\
 		(n) += m * lp->d_nsectors;				\
-		m = (int)strtol(ptr, &ptr, 10);				\
+		m = strtoul(ptr, &ptr, 10);				\
 		(n) += m;						\
 	}								\
 } while (/* CONSTCOND */ 0)
 
-			NXTXNUM(v);
-			if (v < 0) {
-				warnx("line %d: bad partition size: %s",
-				    lineno, cp);
-				errors++;
-			} else
-				pp->p_size = v;
-			NXTXNUM(v);
-			if (v < 0) {
-				warnx("line %d: bad partition offset: %s",
-				    lineno, cp);
-				errors++;
-			} else
-				pp->p_offset = v;
+			/* Maybe check against pp->d_secperunit ?? */
+			NXTXNUM(pp->p_size);
+			NXTXNUM(pp->p_offset);
 			/* can't use word() here because of blanks
 			   in fstypenames[] */
 			_CHECKLINE
-- 
David Laight: david@l8s.co.uk