152bd148e9
- parted: Allow empty string for partition name (aschnell) - libparted: Check devpath before passing to strlen (bcl)
126 lines
4.2 KiB
Diff
126 lines
4.2 KiB
Diff
From 72faef8673b5b1d00059608f0729e93cb21a7664 Mon Sep 17 00:00:00 2001
|
|
From: Arvin Schnell <aschnell@suse.com>
|
|
Date: Fri, 13 Aug 2021 13:02:27 +0000
|
|
Subject: [PATCH 33/34] parted: Allow empty string for partition name
|
|
|
|
This makes it possible to pass an empty string in script mode e.g. to
|
|
set no partition name (on GPT):
|
|
|
|
parted -s ./disk.img mklabel gpt mkpart '""' ext2 1 100M
|
|
|
|
Includes a new test for this feature.
|
|
|
|
Signed-off-by: Brian C. Lane <bcl@redhat.com>
|
|
---
|
|
parted/ui.c | 9 +++++++--
|
|
tests/Makefile.am | 1 +
|
|
tests/t0290-gpt-name.sh | 41 +++++++++++++++++++++++++++++++++++++++++
|
|
3 files changed, 49 insertions(+), 2 deletions(-)
|
|
create mode 100755 tests/t0290-gpt-name.sh
|
|
|
|
diff --git a/parted/ui.c b/parted/ui.c
|
|
index b5948d3..25ad4f1 100644
|
|
--- a/parted/ui.c
|
|
+++ b/parted/ui.c
|
|
@@ -16,7 +16,6 @@
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
-#include <config.h>
|
|
|
|
#include <config.h>
|
|
|
|
@@ -727,6 +726,7 @@ void
|
|
command_line_push_line (const char* line, int multi_word)
|
|
{
|
|
int quoted = 0;
|
|
+ int quotes_empty = 0;
|
|
char quote_char = 0;
|
|
char this_word [256];
|
|
int i;
|
|
@@ -754,6 +754,9 @@ command_line_push_line (const char* line, int multi_word)
|
|
|
|
if (quoted && *line == quote_char) {
|
|
quoted = 0;
|
|
+ /* allow empty partition name in script mode */
|
|
+ if (!i)
|
|
+ quotes_empty = 1;
|
|
continue;
|
|
}
|
|
|
|
@@ -761,9 +764,11 @@ command_line_push_line (const char* line, int multi_word)
|
|
if (quoted && line[0] == '\\' && line[1])
|
|
line++;
|
|
|
|
+ quotes_empty = 0;
|
|
this_word [i++] = *line;
|
|
}
|
|
- if (i || !multi_word) {
|
|
+ if (i || !multi_word || quotes_empty) {
|
|
+ quotes_empty = 0;
|
|
this_word [i] = 0;
|
|
command_line_push_word (this_word);
|
|
}
|
|
diff --git a/tests/Makefile.am b/tests/Makefile.am
|
|
index 3473e6b..9c4a79d 100644
|
|
--- a/tests/Makefile.am
|
|
+++ b/tests/Makefile.am
|
|
@@ -33,6 +33,7 @@ TESTS = \
|
|
t0281-gpt-grow.sh \
|
|
t0282-gpt-move-backup.sh \
|
|
t0283-overlap-partitions.sh \
|
|
+ t0290-gpt-name.sh \
|
|
t0300-dos-on-gpt.sh \
|
|
t0301-overwrite-gpt-pmbr.sh \
|
|
t0350-mac-PT-increases-sector-size.sh \
|
|
diff --git a/tests/t0290-gpt-name.sh b/tests/t0290-gpt-name.sh
|
|
new file mode 100755
|
|
index 0000000..26041b6
|
|
--- /dev/null
|
|
+++ b/tests/t0290-gpt-name.sh
|
|
@@ -0,0 +1,41 @@
|
|
+#!/bin/sh
|
|
+
|
|
+# Test setting empty GPT partition name in non-interactive mode
|
|
+
|
|
+# Copyright (C) 2021 SUSE LLC
|
|
+
|
|
+# This program is free software; you can redistribute it and/or modify
|
|
+# it under the terms of the GNU General Public License as published by
|
|
+# the Free Software Foundation; either version 3 of the License, or
|
|
+# (at your option) any later version.
|
|
+
|
|
+# This program is distributed in the hope that it will be useful,
|
|
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
+# GNU General Public License for more details.
|
|
+
|
|
+# You should have received a copy of the GNU General Public License
|
|
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
+
|
|
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted
|
|
+
|
|
+dev=loop-file
|
|
+
|
|
+truncate --size 50MiB "$dev" || fail=1
|
|
+
|
|
+# create partition with empty name
|
|
+parted --script "$dev" mklabel gpt mkpart '""' ext4 1MiB 49MiB > out 2>&1 || fail=1
|
|
+parted --script --machine "$dev" unit MiB print > out 2>&1 || fail=1
|
|
+grep 'MiB:::;' out || fail=1
|
|
+
|
|
+# set a non-empty name
|
|
+parted --script "$dev" name 1 "test" > out 2>&1 || fail=1
|
|
+parted --script --machine "$dev" unit MiB print > out 2>&1 || fail=1
|
|
+grep 'MiB::test:;' out || fail=1
|
|
+
|
|
+# set empty name
|
|
+parted --script "$dev" name 1 "''" > out 2>&1 || fail=1
|
|
+parted --script --machine "$dev" unit MiB print > out 2>&1 || fail=1
|
|
+grep 'MiB:::;' out || fail=1
|
|
+
|
|
+Exit $fail
|
|
--
|
|
2.31.1
|
|
|