[parted-devel] mklabel & mkfs warning

Debarshi 'Rishi' Ray debarshi.ray at gmail.com
Tue Nov 28 17:41:55 CET 2006


Please find attached a patch to implement the 'warn user before
mklabel and mkfs' feature.

Your feedback is awaited.

Happy hacking,
Debarshi
-- 
I only work when I am not doing any assignments.
-------------- next part --------------
From 04f29bb87bfcf4bcc388b5c3959abf72ea90cf54 Mon Sep 17 00:00:00 2001
From: Debarshi Ray <rishi at gnu.org>
Date: Wed, 29 Nov 2006 03:43:05 +0530
Subject: Warn before mklabel and mkfs.

---
 parted/parted.c |   44 ++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/parted/parted.c b/parted/parted.c
index e6bfe8b..2c2a1f9 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -195,6 +195,38 @@ _disk_warn_busy (PedDisk* disk)
         return 1;
 }
 
+static int
+_partition_warn_loss ()
+{
+        if (ped_exception_throw (
+                PED_EXCEPTION_WARNING,
+                PED_EXCEPTION_YES_NO,
+                _("The existing file system will be destroyed and "
+                  "all data on the partition will be lost. Do "
+                  "you want to continue?"), 
+                NULL)
+                       != PED_EXCEPTION_YES)
+                return 0;
+
+        return 1;
+}
+
+static int
+_disk_warn_loss (PedDisk* disk)
+{
+        if (ped_exception_throw (
+                PED_EXCEPTION_WARNING,
+                PED_EXCEPTION_YES_NO,
+                _("The existing disk label on %s will be destroyed "
+                  "and all data on this disk will be lost. Do you "
+                  "want to continue?"), 
+                disk->dev->path)
+                        != PED_EXCEPTION_YES)
+                return 0;
+
+        return 1;
+}
+
 /* This function changes "sector" to "new_sector" if the new value lies
  * within the required range.
  */
@@ -556,11 +588,12 @@ do_mklabel (PedDevice** dev)
         if (!disk) ped_exception_catch ();
         ped_exception_leave_all ();
 
+	if (!_disk_warn_loss (disk))
+                goto error_destroy_disk;
+
         if (disk) {
-                if (!_disk_warn_busy (disk)) {
-                        ped_disk_destroy (disk);
-                        goto error;
-                }
+                if (!_disk_warn_busy (disk))
+                        goto error_destroy_disk;
                 ped_disk_destroy (disk);
         }
 
@@ -594,6 +627,9 @@ do_mkfs (PedDevice** dev)
         if (!disk)
                 goto error;
 
+        if  (!_partition_warn_loss())
+                goto error_destroy_disk;
+
         if (!command_line_get_partition (_("Partition number?"), disk, &part))
                 goto error_destroy_disk;
         if (!_partition_warn_busy (part))
-- 
1.4.2.4


More information about the parted-devel mailing list