From: krw Date: Thu, 9 Sep 2021 15:21:39 +0000 (+0000) Subject: Simplify logic in USER_edit() loop to eliminate unnecessary X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=711fb9d54186d1613047d26407591ea030b2dcc8;p=openbsd Simplify logic in USER_edit() loop to eliminate unnecessary goto's. Rename CMD_SAVE to CMD_QUIT to reflect actual command (Xquit) and help and man page verbiage. No intentional functional change. --- diff --git a/sbin/fdisk/cmd.c b/sbin/fdisk/cmd.c index c2763fb94c8..bc9ecbf524c 100644 --- a/sbin/fdisk/cmd.c +++ b/sbin/fdisk/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.144 2021/09/02 18:07:45 krw Exp $ */ +/* $OpenBSD: cmd.c,v 1.145 2021/09/09 15:21:39 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -462,7 +462,7 @@ Xwrite(char *args, struct mbr *mbr) int Xquit(char *args, struct mbr *mbr) { - return CMD_SAVE; + return CMD_QUIT; } int diff --git a/sbin/fdisk/cmd.h b/sbin/fdisk/cmd.h index 0997ba4ac6d..cb309f6e20e 100644 --- a/sbin/fdisk/cmd.h +++ b/sbin/fdisk/cmd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.h,v 1.24 2021/08/12 12:31:16 krw Exp $ */ +/* $OpenBSD: cmd.h,v 1.25 2021/09/09 15:21:39 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -20,7 +20,7 @@ #define _CMD_H #define CMD_EXIT 0x0000 -#define CMD_SAVE 0x0001 +#define CMD_QUIT 0x0001 #define CMD_CONT 0x0002 #define CMD_CLEAN 0x0003 #define CMD_DIRTY 0x0004 diff --git a/sbin/fdisk/user.c b/sbin/fdisk/user.c index 07b4fcd2864..e6ee2da78f4 100644 --- a/sbin/fdisk/user.c +++ b/sbin/fdisk/user.c @@ -1,4 +1,4 @@ -/* $OpenBSD: user.c,v 1.76 2021/08/25 23:47:36 krw Exp $ */ +/* $OpenBSD: user.c,v 1.77 2021/09/09 15:21:39 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -56,7 +56,6 @@ const struct cmd cmd_table[] = { {"abort", 1, Xabort, "Abort program without saving current changes"}, }; - int modified; int ask_cmd(const int, char **); @@ -69,20 +68,19 @@ USER_edit(const uint64_t lba_self, const uint64_t lba_firstembr) int i, st; static int editlevel; - editlevel += 1; - if (MBR_read(lba_self, lba_firstembr, &mbr)) - goto done; + return; + + editlevel += 1; if (editlevel == 1) GPT_read(ANYGPT); printf("Enter 'help' for information\n"); -again: - do { + for (;;) { if (letoh64(gh.gh_sig) == GPTSIGNATURE && editlevel > 1) - goto done; /* 'reinit gpt'. Unwind recursion! */ + break; /* 'reinit gpt'. Unwind recursion! */ i = ask_cmd(editlevel, &args); if (i == -1) @@ -90,25 +88,22 @@ again: st = cmd_table[i].cmd_fcn(args ? args : "", &mbr); - if (st == CMD_EXIT) + if (st == CMD_EXIT) { + if (modified) + printf("Aborting changes to current MBR\n"); break; - if (st == CMD_SAVE) + } + if (st == CMD_QUIT) { + if (modified && Xwrite(NULL, &mbr) == CMD_CONT) + continue; break; + } if (st == CMD_CLEAN) modified = 0; if (st == CMD_DIRTY) modified = 1; - } while (1); - - if (modified) { - if (st == CMD_SAVE) { - if (Xwrite(NULL, &mbr) == CMD_CONT) - goto again; - } else - printf("Aborting changes to current MBR.\n"); } -done: editlevel -= 1; }