[parted-devel] [PATCH] parted/ui: Count empty strings as words in multi_word mode

Sebastian Parschauer sparschauer at suse.de
Thu Aug 10 14:23:56 UTC 2017


In non-interactive mode, the command line arguments are appended
to a string list with command_line_push_line() in multi_word mode.
That mode does not count empty strings as a word.
For mkpart and a GPT disk label, the partition name is picked up
from that string list. The partition name is mandatory and we
cannot make it optional. So it is not possible to set an empty
partition name from command line this way.
Also setting a default name is no option as this causes duplicate
/dev/disk/by-partlabel/ symlinks and systemd errors this way.

So count empty strings as words in multi_word mode to allow the
the following commands to set an empty partition name.

parted -s /dev/vdb mkpart "" 1MiB 100%
parted -s /dev/vdb mkpart "" ext3 1MiB 100%

This does not break any other parts as these all check if the
provided string is a valid value.

Signed-off-by: Sebastian Parschauer <sparschauer at suse.de>
---
 parted/ui.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/parted/ui.c b/parted/ui.c
index 752860baa087..b7e593bf12da 100644
--- a/parted/ui.c
+++ b/parted/ui.c
@@ -712,8 +712,8 @@ _str_is_spaces (const char* str)
  *         In single-word mode, only one word is parsed per line.
  * Leading and trailing spaces are removed.  For example: " a b c "
  * is a single word "a b c".  The motivation for this mode is partition
- * names, etc.  In single-word mode, the empty string is a word.
- * (but not in multi-word mode).
+ * names, etc. The empty string is always a word to allow empty
+ * partition names in non-interactive mode.
  */
 void
 command_line_push_line (const char* line, int multi_word)
@@ -755,10 +755,9 @@ command_line_push_line (const char* line, int multi_word)
 
                         this_word [i++] = *line;
                 }
-                if (i || !multi_word) {
-                        this_word [i] = 0;
-                        command_line_push_word (this_word);
-                }
+                this_word [i] = 0;
+                command_line_push_word (this_word);
+
         } while (*line && multi_word);
 }
 
-- 
2.12.3




More information about the parted-devel mailing list