diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1998-10-11 20:49:18 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1998-10-11 20:49:18 +0000 |
commit | b25b6abb86b7987aa1119c6a1cb02c38382b85dc (patch) | |
tree | 9eaab7c0b05a348bbcaedbda31d9ea7ac6a0e9e4 /sbin | |
parent | baae0efc1b3fe750b81ab859113703f3e06be5c9 (diff) |
When rounding to cylinder boundaries check to make sure we don't round up past the end of the disk. Noticed by fries@
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/disklabel/editor.c | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c index b548cdcdea1..eafd1055fa6 100644 --- a/sbin/disklabel/editor.c +++ b/sbin/disklabel/editor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: editor.c,v 1.44 1998/08/07 00:06:00 millert Exp $ */ +/* $OpenBSD: editor.c,v 1.45 1998/10/11 20:49:17 millert Exp $ */ /* * Copyright (c) 1997-1998 Todd C. Miller <Todd.Miller@courtesan.com> @@ -28,7 +28,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: editor.c,v 1.44 1998/08/07 00:06:00 millert Exp $"; +static char rcsid[] = "$OpenBSD: editor.c,v 1.45 1998/10/11 20:49:17 millert Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -1243,27 +1243,25 @@ getuint(lp, partno, prompt, helpstring, oval, maxval, flags) } } if ((flags & DO_ROUNDING) && rval < UINT_MAX) { - u_int32_t cyls; - /* XXX - should use maxsize and round down if too big */ -#ifdef CYLCHECK - /* Always round to nearest cylinder, regardless of units */ - cyls = (u_int32_t)((rval / (double)lp->d_secpercyl) + 0.5); - if (rval != cyls * lp->d_secpercyl) { - rval = cyls * lp->d_secpercyl; - printf("Rounding to nearest cylinder: %u\n", rval); - } -#else +#ifndef CYLCHECK /* Round to nearest cylinder unless given in sectors */ - if (mult != 1) { + if (mult != 1) +#endif + { + u_int32_t cyls; + + /* If we round up past the end, round down instead */ cyls = (u_int32_t)((rval / (double)lp->d_secpercyl) + 0.5); + if (cyls * lp->d_secpercyl > maxval) + cyls--; + if (rval != cyls * lp->d_secpercyl) { rval = cyls * lp->d_secpercyl; printf("Rounding to nearest cylinder: %u\n", rval); } } -#endif } return(rval); |