[parted-devel] [PATCH] fix for mklabel in parted
Amit K. Arora
aarora at linux.vnet.ibm.com
Thu Jan 15 14:22:24 UTC 2009
[Please note that I am not part of the mailing list, hence please do not
remove my id from the CC list. Thanks!]
Problem : "mklabel <label>" command in 'parted' tool is broken.
Currently, if "mklabel" command is passed an argument in interactive
format, it throws "parted: invalid token: <label arg>" warning message and
asks for the disk type again. If no argument is passed, it works as
expected.
For example:
# parted /dev/sdc
GNU Parted 1.8.8
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel msdos
Warning: The existing disk label on /dev/sdc will be destroyed and all
data on this disk will be lost. Do you want to continue?
parted: invalid token: msdos <<=== THIS
Yes/No? Yes
New disk label type? [gpt]? msdos
(parted)
According to the parted help and also the man page,
"mklabel <label name>" syntax is correct and should work.
The attached patch fixes this issue. Please accept it. Thanks!
Signed-off-by: Amit K Arora <aarora at linux.vnet.ibm.com>
diff -Nuarp parted-1.8.8.ORG/parted/parted.c parted-1.8.8/parted/parted.c
--- parted-1.8.8.ORG/parted/parted.c 2009-01-15 05:57:20.000000000 -0600
+++ parted-1.8.8/parted/parted.c 2009-01-15 06:56:04.000000000 -0600
@@ -597,11 +597,18 @@ do_mklabel (PedDevice** dev)
{
PedDisk* disk;
const PedDiskType* type = ped_disk_probe (*dev);
+ int ask_disk_type = 1;
ped_exception_fetch_all ();
disk = ped_disk_new (*dev);
if (!disk) ped_exception_catch ();
ped_exception_leave_all ();
+ /* Get the disk type from the command line, if provided by user */
+ if (command_line_get_word_count ()) {
+ if (!command_line_get_disk_type (_("New disk label type?"), &type))
+ goto error;
+ ask_disk_type = 0;
+ }
if (disk) {
if (!_disk_warn_busy (disk))
@@ -612,7 +619,9 @@ do_mklabel (PedDevice** dev)
ped_disk_destroy (disk);
}
- if (!command_line_get_disk_type (_("New disk label type?"), &type))
+ /* If user has already provided disk type, do not ask again! */
+ if (ask_disk_type &&
+ !command_line_get_disk_type (_("New disk label type?"), &type))
goto error;
disk = ped_disk_new_fresh (*dev, type);
--
Regards,
Amit Arora
More information about the parted-devel
mailing list