[parted-devel] Re: Parted 2.0 plans

Debarshi 'Rishi' Ray debarshi.ray at gmail.com
Thu Nov 23 05:33:36 CET 2006


> It looks good to me but please send a uniq patch. Your current patch
> need to be applied above the first one.

Please find it attached. It is against the stable-1.8.x branch.

Happy hacking,
Debarshi
-- 
I only work when I am not doing any assignments.
-------------- next part --------------
From af2250f131afbd07b8748564037559ebcedc9f59 Mon Sep 17 00:00:00 2001
From: Debarshi Ray <rishi at gnu.org>
Date: Thu, 23 Nov 2006 10:05:23 +0000
Subject: Implement --list switch.

---
 parted/parted.c |   41 ++++++++++++++++++++++++++---------------
 1 files changed, 26 insertions(+), 15 deletions(-)

diff --git a/parted/parted.c b/parted/parted.c
index 8b21a8a..ac7dcdf 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -66,6 +66,7 @@ static struct option    options[] = {
         /* name, has-arg, string-return-val, char-return-val */
         {"help",        0, NULL, 'h'},
         {"interactive", 0, NULL, 'i'},
+        {"list",        0, NULL, 'l'},
         {"script",      0, NULL, 's'},
         {"version",     0, NULL, 'v'},
         {NULL,          0, NULL, 0}
@@ -75,6 +76,7 @@ #endif
 static char*    options_help [][2] = {
         {"help",        N_("displays this help message")},
         {"interactive", N_("where necessary, prompts for user intervention")},
+        {"list",        N_("lists the partition tables of all available devices")},
         {"script",      N_("never prompts for user intervention")},
         {"version",     N_("displays the version")},
         {NULL,          NULL}
@@ -124,6 +126,7 @@ static Command* commands [256] = {NULL};
 static PedTimer* timer;
 static TimerContext timer_context;
 
+static int _print_all (int cli);
 static void _done (PedDevice* dev);
 
 static void
@@ -1234,19 +1237,8 @@ do_print (PedDevice** dev)
                 return status;
         }
 
-        if (has_all_arg) {
-                int first_device;
-                PedDevice *current_dev = NULL;
-
-                ped_device_probe_all();
-
-                while ((current_dev = ped_device_get_next(current_dev))) {
-                        do_print (&current_dev);
-                        printf ("\n");
-                }    
-
-                return 1;
-        }
+        if (has_all_arg) 
+                return _print_all (0);
 
         start = ped_unit_format (*dev, 0);
         end = ped_unit_format_byte (*dev, (*dev)->length * (*dev)->sector_size
@@ -1380,6 +1372,24 @@ error:
 }
 
 static int
+_print_all (int cli)
+{
+        PedDevice *current_dev = NULL;
+
+        ped_device_probe_all();
+
+        while ((current_dev = ped_device_get_next(current_dev))) {
+                do_print (&current_dev);
+                printf ("\n");
+        }    
+
+        if(cli)
+                exit(0);
+
+        return 1;
+}
+
+static int
 do_quit (PedDevice** dev)
 {
         _done (*dev);
@@ -2113,10 +2123,10 @@ int     opt;
 while (1)
 {
 #ifdef HAVE_GETOPT_H
-        opt = getopt_long (*argc_ptr, *argv_ptr, "hisv",
+        opt = getopt_long (*argc_ptr, *argv_ptr, "hilsv",
                            options, NULL);
 #else
-        opt = getopt (*argc_ptr, *argv_ptr, "hisv");
+        opt = getopt (*argc_ptr, *argv_ptr, "hilsv");
 #endif
         if (opt == -1)
                 break;
@@ -2124,6 +2134,7 @@ #endif
         switch (opt) {
                 case 'h': help_msg (); break;
                 case 'i': opt_script_mode = 0; break;
+                case 'l': _print_all(1); break;
                 case 's': opt_script_mode = 1; break;
                 case 'v': _version (); break;
         }
-- 
1.4.2.4


More information about the parted-devel mailing list