[parted-devel] [PATCH v3 1/2] parted: Add '-f', '--force' option

Sebastian Parschauer sparschauer at suse.de
Tue Nov 7 16:23:55 UTC 2017


There are dangerous actions like e.g. shrinking a busy partition
which should be possible in script mode but not without using an
option to enforce that. This is meant to prevent buggy scripts
from doing those actions unintentionally.

Suggested-by: Phillip Susi <psusi at ubuntu.com>
Signed-off-by: Sebastian Parschauer <sparschauer at suse.de>
---
 doc/C/parted.8  | 3 +++
 parted/parted.c | 8 ++++++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/doc/C/parted.8 b/doc/C/parted.8
index eb7cd980c6e7..dcc0fe25c800 100644
--- a/doc/C/parted.8
+++ b/doc/C/parted.8
@@ -15,6 +15,9 @@ This manual page documents \fBparted\fP briefly.  Complete documentation is
 distributed with the package in GNU Info format.
 .SH OPTIONS
 .TP
+.B -f, --force
+enforces a dangerous action
+.TP
 .B -h, --help
 displays a help message
 .TP
diff --git a/parted/parted.c b/parted/parted.c
index c471d4976d06..cf6b68b2a72d 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -111,6 +111,7 @@ typedef struct {
 
 static struct option const options[] = {
         /* name, has-arg, string-return-val, char-return-val */
+        {"force",       0, NULL, 'f'},
         {"help",        0, NULL, 'h'},
         {"list",        0, NULL, 'l'},
         {"machine",     0, NULL, 'm'},
@@ -122,6 +123,7 @@ static struct option const options[] = {
 };
 
 static const char *const options_help [][2] = {
+        {"force",       N_("enforces a dangerous action")},
         {"help",        N_("displays this help message")},
         {"list",        N_("lists partition layout on all block devices")},
         {"machine",     N_("displays machine parseable output")},
@@ -137,6 +139,7 @@ int     opt_machine_mode = 0;
 int     disk_is_modified = 0;
 int     is_toggle_mode = 0;
 int     alignment = ALIGNMENT_OPTIMAL;
+int     force = 0;
 
 static const char* number_msg = N_(
 "NUMBER is the partition number used by Linux.  On MS-DOS disk labels, the "
@@ -2175,12 +2178,13 @@ int     opt, help = 0, list = 0, version = 0, wrong = 0;
 
 while (1)
 {
-        opt = getopt_long (*argc_ptr, *argv_ptr, "hlmsva:",
+        opt = getopt_long (*argc_ptr, *argv_ptr, "fhlmsva:",
                            options, NULL);
         if (opt == -1)
                 break;
 
         switch (opt) {
+                case 'f': force = 1; break;
                 case 'h': help = 1; break;
                 case 'l': list = 1; break;
                 case 'm': opt_machine_mode = 1; break;
@@ -2201,7 +2205,7 @@ while (1)
 
 if (wrong == 1) {
         fprintf (stderr,
-                 _("Usage: %s [-hlmsv] [-a<align>] [DEVICE [COMMAND [PARAMETERS]]...]\n"),
+                 _("Usage: %s [-fhlmsv] [-a<align>] [DEVICE [COMMAND [PARAMETERS]]...]\n"),
                  program_name);
         return 0;
 }
-- 
2.13.6




More information about the parted-devel mailing list