diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2015-11-21 16:45:42 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2015-11-21 16:45:42 +0000 |
commit | 03c72494429f9cc7314132717045991abe94f7e6 (patch) | |
tree | fc82eddb50f835369a0e4761d8aa140e3245b2de /sbin/fdisk/misc.c | |
parent | 66c71dba70aec4ad1776d0f3350f9c81a308d9e4 (diff) |
Bring GPT partition editing into line with MBR partition editing
by presenting the existing offset and size as the defaults. Enhance
getuint64() to take a minimum value as ask_num() does. Use this to
ensure that GPT partitions are constrained to the valid area of the
disk. Leave MBR partition constraints alone for the moment.
Original problem(s) noted by tim@
Diffstat (limited to 'sbin/fdisk/misc.c')
-rw-r--r-- | sbin/fdisk/misc.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/sbin/fdisk/misc.c b/sbin/fdisk/misc.c index 754128e47c6..0203b17a0d7 100644 --- a/sbin/fdisk/misc.c +++ b/sbin/fdisk/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.58 2015/11/19 16:14:08 krw Exp $ */ +/* $OpenBSD: misc.c,v 1.59 2015/11/21 16:45:41 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -203,7 +203,7 @@ ask_yn(const char *str) * adapted from sbin/disklabel/editor.c */ u_int64_t -getuint64(char *prompt, u_int64_t oval, u_int64_t maxval) +getuint64(char *prompt, u_int64_t oval, u_int64_t minval, u_int64_t maxval) { const int secsize = unit_types[SECTORS].conversion; char buf[BUFSIZ], *endptr, *p, operator = '\0'; @@ -215,6 +215,8 @@ getuint64(char *prompt, u_int64_t oval, u_int64_t maxval) if (oval > maxval) oval = maxval; + if (oval < minval) + oval = minval; secpercyl = disk.sectors * disk.heads; @@ -304,7 +306,7 @@ getuint64(char *prompt, u_int64_t oval, u_int64_t maxval) d2 = d; } - if (saveerr == ERANGE || d > maxval || d < 0 || d < d2) { + if (saveerr == ERANGE || d > maxval || d < minval || d < d2) { printf("%s is out of range: %c%s%c\n", prompt, operator, p, unit); } else if (*endptr != '\0') { |