[parted-devel] [PATCH 2/2] gpt_read: don't restore the primary/backup GPT in script mode

Hatayama, Daisuke d.hatayama at jp.fujitsu.com
Fri Nov 9 00:04:01 GMT 2018


With the previous patch, the primary/backup GPT is now restored when
their corruption is detected. However, there is still the issue that
the restoring is automatically performed without any confirmation from
users when parted command is running in script mode, even when using
parted sub-commands that are expected to be read-only such as print
command.

Natural idea to address this issue is restricting restoring of the
primary/backup GPT to read-only sub-commands, and to do that, we need
to first categorize parted sub-commands into read-only ones and the
others and then to modify interface from command.c to gpt.c to pass
such information. However, the latter part is not trivial.

Instead, this patch simply makes parted command not perform restoring
GPT in script mode, permitting restoring of the primary/backup GPT
from read-only sub-commands if there is explicit confirmation from
users.
---
 libparted/labels/gpt.c |   26 ++++++++++++++++----------
 1 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 914dfe3..2d45cb4 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -991,6 +991,8 @@ gpt_read (PedDisk *disk)
       return 0;
     }
 
+  PedExceptionOption ex_status;
+
   if (primary_gpt && backup_gpt)
     {
       /* Both are valid.  */
@@ -1034,11 +1036,13 @@ gpt_read (PedDisk *disk)
   else if (primary_gpt && !backup_gpt)
     {
       /* The primary header is ok, but backup is corrupt.  */
-      if (ped_exception_throw
-          (PED_EXCEPTION_ERROR, PED_EXCEPTION_OK_CANCEL,
-           _("The backup GPT table is corrupt, but the "
-             "primary appears OK, so that will be used."))
-          == PED_EXCEPTION_CANCEL)
+      ex_status = ped_exception_throw
+	(PED_EXCEPTION_ERROR, PED_EXCEPTION_OK_CANCEL,
+	 _("The backup GPT table is corrupt, but the "
+	   "primary appears OK, so that will be used."));
+
+      if (ex_status == PED_EXCEPTION_CANCEL ||
+          ex_status == PED_EXCEPTION_UNHANDLED)
         goto error_free_gpt;
 
       gpt = primary_gpt;
@@ -1047,11 +1051,13 @@ gpt_read (PedDisk *disk)
   else /* !primary_gpt && backup_gpt */
     {
       /* primary GPT corrupt, backup is ok.  */
-      if (ped_exception_throw
-          (PED_EXCEPTION_ERROR, PED_EXCEPTION_OK_CANCEL,
-           _("The primary GPT table is corrupt, but the "
-             "backup appears OK, so that will be used."))
-          == PED_EXCEPTION_CANCEL)
+      ex_status = ped_exception_throw
+        (PED_EXCEPTION_ERROR, PED_EXCEPTION_OK_CANCEL,
+         _("The primary GPT table is corrupt, but the "
+           "backup appears OK, so that will be used."));
+
+      if (ex_status == PED_EXCEPTION_CANCEL ||
+          ex_status == PED_EXCEPTION_UNHANDLED)
         goto error_free_gpt;
 
       gpt = backup_gpt;
-- 
1.7.1





More information about the parted-devel mailing list