From e65b98a142f78ed32246495f2063b4a885afa357 Mon Sep 17 00:00:00 2001 From: Kenneth R Westerback Date: Sun, 4 Mar 2018 19:56:11 +0000 Subject: Add if (D_VENDOR) check to last SUN_CYLCHECK block lacking it. While there move local variable declaration inside the 'if' and eliminate separate SUN_CYLCHECK block containing said local variable declaration. Add check for attempt to resize a partition to 0, and simplify logic a bit by recognizing that this means the number of sectors will always be > 0. ok otto@ --- sbin/disklabel/editor.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'sbin/disklabel/editor.c') diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c index 5ec32ff6a82..4c38c005259 100644 --- a/sbin/disklabel/editor.c +++ b/sbin/disklabel/editor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: editor.c,v 1.320 2018/03/02 12:49:59 krw Exp $ */ +/* $OpenBSD: editor.c,v 1.321 2018/03/04 19:56:10 krw Exp $ */ /* * Copyright (c) 1997-2000 Todd C. Miller @@ -692,9 +692,6 @@ editor_resize(struct disklabel *lp, char *p) struct disklabel label; struct partition *pp, *prev; u_int64_t secs, sz, off; -#ifdef SUN_CYLCHECK - u_int64_t cylsecs; -#endif int partno, i; label = *lp; @@ -735,14 +732,17 @@ editor_resize(struct disklabel *lp, char *p) } else if (secs == ULLONG_MAX) { fputs("Invalid entry\n", stderr); return; + } else if (secs == 0) { + fputs("The size must be > 0 sectors\n", stderr); + return; } #ifdef SUN_CYLCHECK - cylsecs = lp->d_secpercyl; - if (secs > 0) + if (lp->d_secpercyl & D_VENDOR) { + u_int64_t cylsecs; + cylsecs = lp->d_secpercyl; secs = ((secs + cylsecs - 1) / cylsecs) * cylsecs; - else - secs = ((secs - cylsecs + 1) / cylsecs) * cylsecs; + } #endif if (DL_GETPOFFSET(pp) + secs > ending_sector) { fputs("Amount too big\n", stderr); -- cgit v1.2.3