summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2007-06-08 20:21:14 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2007-06-08 20:21:14 +0000
commitc8e98d492f726c6a9fc5c9ae2b9d2fc952912ae3 (patch)
treeb8cbfc164f0270cd713ef2098cb29fc58980cdfe /sbin
parent5f221b25fe0521d2a12455c7c4842674418d1f5b (diff)
Simplify rounding to cylinders.
Also, on systems with sun labels, don't allow the user to create a partition with fewer than a cylinder's worth of sectors. OK otto@
Diffstat (limited to 'sbin')
-rw-r--r--sbin/disklabel/editor.c40
1 files changed, 19 insertions, 21 deletions
diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c
index 97e0cfac4aa..df0196dd9a6 100644
--- a/sbin/disklabel/editor.c
+++ b/sbin/disklabel/editor.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: editor.c,v 1.120 2007/06/08 19:08:35 otto Exp $ */
+/* $OpenBSD: editor.c,v 1.121 2007/06/08 20:21:13 millert Exp $ */
/*
* Copyright (c) 1997-2000 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -17,7 +17,7 @@
*/
#ifndef lint
-static char rcsid[] = "$OpenBSD: editor.c,v 1.120 2007/06/08 19:08:35 otto Exp $";
+static char rcsid[] = "$OpenBSD: editor.c,v 1.121 2007/06/08 20:21:13 millert Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -438,7 +438,12 @@ editor_add(struct disklabel *lp, char **mp, u_int64_t *freep, char *p)
u_int64_t ui, old_offset, old_size, new_offset, new_size;
/* XXX - prompt user to steal space from another partition instead */
- if (*freep == 0) {
+#ifdef CYLCHECK
+ if (*freep < lp->d_secpercyl)
+#else
+ if (*freep == 0)
+#endif
+ {
fputs("No space left, you need to shrink a partition\n",
stderr);
return;
@@ -1108,28 +1113,21 @@ getuint(struct disklabel *lp, int partno, char *prompt, char *helpstring,
}
}
}
- if ((flags & DO_ROUNDING) && rval < ULLONG_MAX - lp->d_secpercyl / 2 &&
- lp->d_secpercyl != 0) {
-#ifndef CYLCHECK
+ if ((flags & DO_ROUNDING) && rval != ULLONG_MAX) {
/* Round to nearest cylinder unless given in sectors */
- if (mult != 1)
+ if (
+#ifndef CYLCHECK
+ mult != 1 &&
#endif
- {
+ (rval + offset) % lp->d_secpercyl != 0) {
u_int64_t cyls;
- /* If we round up past the end, round down instead */
- cyls = (rval + lp->d_secpercyl / 2) / lp->d_secpercyl;
- if (cyls != 0 && lp->d_secpercyl != 0) {
- if (maxval && cyls > 1 &&
- (cyls * lp->d_secpercyl) - offset > maxval)
- cyls--;
-
- if (rval != (cyls * lp->d_secpercyl) - offset) {
- rval = (cyls * lp->d_secpercyl) - offset;
- printf("Rounding to nearest cylinder: %llu\n",
- rval);
- }
- }
+ /* Round to higher cylinder but no more than maxval */
+ cyls = (rval / lp->d_secpercyl) + 1;
+ if ((cyls * lp->d_secpercyl) - offset > maxval)
+ cyls--;
+ rval = (cyls * lp->d_secpercyl) - offset;
+ printf("Rounding to cylinder: %llu\n", rval);
}
}