parted/parted-add-ignore-busy-option.patch

107 lines
3.7 KiB
Diff

From: Sebastian Parschauer <sparschauer@suse.de>
Date: Mon, 20 Nov 2017 18:01:56 +0100
Subject: parted: Add '--ignore-busy' option
References: bsc#1058667
Patch-mainline: not yet, based on v3 submitted on 2017-11-07
There are dangerous actions like e.g. shrinking or removing 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.
Also add proper printing of the help text for a long option without
a short option.
Suggested-by: Phillip Susi <psusi@ubuntu.com>
Signed-off-by: Sebastian Parschauer <sparschauer@suse.de>
---
doc/C/parted.8 | 3 +++
parted/parted.c | 16 ++++++++++++++--
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/doc/C/parted.8 b/doc/C/parted.8
index e2a24dc..ff01162 100644
--- a/doc/C/parted.8
+++ b/doc/C/parted.8
@@ -30,6 +30,9 @@ never prompts for user intervention
.B -v, --version
displays the version
.TP
+.B --ignore-busy
+perform the requested action in script mode although a partition is busy
+.TP
.B --wipesignatures
mkpart wipes the superblock signatures from the disk region where it is
about to create the partition
diff --git a/parted/parted.c b/parted/parted.c
index 3d7ec4b..3cc8f77 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -76,7 +76,8 @@ static int MEGABYTE_SECTORS (PedDevice* dev)
enum
{
PRETEND_INPUT_TTY = CHAR_MAX + 1,
- WIPESIGNATURES = CHAR_MAX + 2,
+ IGNORE_BUSY = CHAR_MAX + 2,
+ WIPESIGNATURES = CHAR_MAX + 3,
};
enum
@@ -118,6 +119,7 @@ static struct option const options[] = {
{"script", 0, NULL, 's'},
{"version", 0, NULL, 'v'},
{"align", required_argument, NULL, 'a'},
+ {"ignore-busy", 0, NULL, IGNORE_BUSY},
{"wipesignatures", 0, NULL, WIPESIGNATURES},
{"-pretend-input-tty", 0, NULL, PRETEND_INPUT_TTY},
{NULL, 0, NULL, 0}
@@ -130,10 +132,13 @@ static const char *const options_help [][2] = {
{"script", N_("never prompts for user intervention")},
{"version", N_("displays the version")},
{"align=[none|cyl|min|opt]", N_("alignment for new partitions")},
+ {"ignore-busy", N_("perform action although partition is busy")},
{"wipesignatures", N_("wipe superblock signatures when creating partition")},
{NULL, NULL}
};
+#define LONGOPT_HELP_START 6 /* index to first long option help */
+
int opt_script_mode = 0;
int pretend_input_tty = 0;
int wipesignatures = 0;
@@ -141,6 +146,7 @@ int opt_machine_mode = 0;
int disk_is_modified = 0;
int is_toggle_mode = 0;
int alignment = ALIGNMENT_OPTIMAL;
+int ignore_busy = 0;
static const char* number_msg = N_(
"NUMBER is the partition number used by Linux. On MS-DOS disk labels, the "
@@ -513,12 +519,17 @@ print_options_help ()
{
int i;
- for (i=0; options_help [i][0]; i++) {
+ for (i=0; i < LONGOPT_HELP_START; i++) {
printf (" -%c, --%-25.25s %s\n",
options_help [i][0][0],
options_help [i][0],
_(options_help [i][1]));
}
+ for (i=LONGOPT_HELP_START; options_help [i][0]; i++) {
+ printf (" --%-29.25s %s\n",
+ options_help [i][0],
+ _(options_help [i][1]));
+ }
}
int
@@ -2244,6 +2255,7 @@ while (1)
alignment = XARGMATCH ("--align", optarg,
align_args, align_types);
break;
+ case IGNORE_BUSY: ignore_busy = 1; break;
case PRETEND_INPUT_TTY:
pretend_input_tty = 1;
break;