summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkrw <krw@openbsd.org>2015-11-21 16:45:41 +0000
committerkrw <krw@openbsd.org>2015-11-21 16:45:41 +0000
commit684c15929ab3ac3abbbcdba77d2d06b5fd9f917c (patch)
tree620ff0920a7a6eff58d018de27eae7ec3eccfd51
parentsync (diff)
downloadwireguard-openbsd-684c15929ab3ac3abbbcdba77d2d06b5fd9f917c.tar.xz
wireguard-openbsd-684c15929ab3ac3abbbcdba77d2d06b5fd9f917c.zip
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@
-rw-r--r--sbin/fdisk/cmd.c15
-rw-r--r--sbin/fdisk/misc.c8
-rw-r--r--sbin/fdisk/misc.h4
3 files changed, 14 insertions, 13 deletions
diff --git a/sbin/fdisk/cmd.c b/sbin/fdisk/cmd.c
index 103432b9f87..5481966566b 100644
--- a/sbin/fdisk/cmd.c
+++ b/sbin/fdisk/cmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd.c,v 1.89 2015/11/21 02:12:09 krw Exp $ */
+/* $OpenBSD: cmd.c,v 1.90 2015/11/21 16:45:41 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -187,10 +187,10 @@ Xgedit(char *args)
goto done;
}
- bs = getuint64("Partition offset", letoh64(gh.gh_lba_start),
- letoh64(gh.gh_lba_end));
- ns = getuint64("Partition size", letoh64(gh.gh_lba_end) - bs + 1,
- letoh64(gh.gh_lba_end) - bs + 1);
+ bs = getuint64("Partition offset", letoh64(gg->gp_lba_start),
+ letoh64(gh.gh_lba_start), letoh64(gh.gh_lba_end));
+ ns = getuint64("Partition size", letoh64(gg->gp_lba_end) - bs + 1,
+ 0, letoh64(gh.gh_lba_end) - bs + 1);
gg->gp_lba_start = htole64(bs);
gg->gp_lba_end = htole64(bs + ns - 1);
@@ -267,9 +267,8 @@ Xedit(char *args, struct mbr *mbr)
/* Fix up CHS values for LBA */
PRT_fix_CHS(pp);
} else {
- pp->bs = getuint64("Partition offset", pp->bs,
- disk.size);
- pp->ns = getuint64("Partition size", pp->ns,
+ pp->bs = getuint64("Partition offset", pp->bs, 0, disk.size);
+ pp->ns = getuint64("Partition size", pp->ns, 0,
disk.size - pp->bs);
/* Fix up CHS values */
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') {
diff --git a/sbin/fdisk/misc.h b/sbin/fdisk/misc.h
index 3724cdee928..e80ae59edda 100644
--- a/sbin/fdisk/misc.h
+++ b/sbin/fdisk/misc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.h,v 1.32 2015/11/12 15:07:41 krw Exp $ */
+/* $OpenBSD: misc.h,v 1.33 2015/11/21 16:45:41 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -35,7 +35,7 @@ int ask_num(const char *, int, int, int);
int ask_pid(int, struct uuid *);
char *ask_string(const char *, const char *);
int ask_yn(const char *);
-u_int64_t getuint64(char *, u_int64_t, u_int64_t);
+u_int64_t getuint64(char *, u_int64_t, u_int64_t, u_int64_t);
u_int32_t crc32(const u_char *, const u_int32_t);
char *utf16le_to_string(u_int16_t *);
u_int16_t *string_to_utf16le(char *);