From: krw Date: Sun, 13 Jun 2021 14:39:05 +0000 (+0000) Subject: Tweak gsetpid() to restore partition info in case of an error, X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=142a1f8c4cfcac2a05dcf89563cb8b2896d72354;p=openbsd Tweak gsetpid() to restore partition info in case of an error, and mark the partition dirty only if something changed. More aligned with gedit() and safer when invoked directly from Xsetpid(). --- diff --git a/sbin/fdisk/cmd.c b/sbin/fdisk/cmd.c index e60d9ac0fad..8c151c6c89c 100644 --- a/sbin/fdisk/cmd.c +++ b/sbin/fdisk/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.112 2021/06/11 16:22:46 krw Exp $ */ +/* $OpenBSD: cmd.c,v 1.113 2021/06/13 14:39:05 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -301,10 +301,11 @@ int gsetpid(int pn) { struct uuid guid; - struct gpt_partition *gg; + struct gpt_partition *gg, oldgg; int num, status; gg = &gp[pn]; + oldgg = *gg; /* Print out current table entry */ GPT_print_parthdr(TERSE); @@ -321,12 +322,17 @@ gsetpid(int pn) uuid_create(&guid, &status); if (status != uuid_s_ok) { printf("could not create guid for partition\n"); - return (CMD_CONT); + goto done; } uuid_enc_le(&gg->gp_guid, &guid); } - return (CMD_DIRTY); + if (memcmp(gg, &oldgg, sizeof(*gg))) + return (CMD_DIRTY); + + done: + *gg = oldgg; + return (CMD_CONT); } int