[parted-devel] [PATCH] fix for parted command arguments
Amit K. Arora
aarora at linux.vnet.ibm.com
Mon Jan 19 13:39:49 UTC 2009
Problem : Commands in parted tool when passed with arguments throw a warning
======== and asks for the same arguments again.
For example, 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.
Sample output:
# 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.
Solution:
========
This behavior is a side effect of the commit
0c2d6ba0757324c3975cbf10868f266fe6dbbbfe in git.
Whats happening today is that when a user passes an argument to a
command (eg. "mklabel msdos"), parted throws up a warning to user
asking whether to continue or not and expects "Yes" or "No" as the
answer. At this time the argument "msdos" has not been processed yet,
and when the warning exception handling code tries to get the user input
(yes/no), it finds "msdos" instead ! And hence throws error message of
"parted: invalid token: msdos"
This can be solved by changing the order of when the warning is thrown
and when the argument list of parted commands is tried to be read. The
attached patch reads the arguments first and then throws the warning.
Please accept this patch. Thanks!
--
Regards,
Amit Arora
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-19 03:20:37.000000000 -0600
+++ parted-1.8.8/parted/parted.c 2009-01-19 03:20:37.000000000 -0600
@@ -511,12 +511,11 @@ do_cp (PedDevice** dev)
_("Can't copy an extended partition."));
goto error_destroy_disk;
}
- if (!_partition_warn_busy (src))
- goto error_destroy_disk;
-
if (!command_line_get_partition (_("Destination partition number?"),
dst_disk, &dst))
goto error_destroy_disk;
+ if (!_partition_warn_busy (src))
+ goto error_destroy_disk;
if (!_partition_warn_busy (dst))
goto error_destroy_disk;
@@ -603,6 +602,9 @@ do_mklabel (PedDevice** dev)
if (!disk) ped_exception_catch ();
ped_exception_leave_all ();
+ if (!command_line_get_disk_type (_("New disk label type?"), &type))
+ goto error;
+
if (disk) {
if (!_disk_warn_busy (disk))
goto error_destroy_disk;
@@ -612,9 +614,6 @@ do_mklabel (PedDevice** dev)
ped_disk_destroy (disk);
}
- if (!command_line_get_disk_type (_("New disk label type?"), &type))
- goto error;
-
disk = ped_disk_new_fresh (*dev, type);
if (!disk)
goto error;
@@ -646,15 +645,15 @@ do_mkfs (PedDevice** dev)
if (!disk)
goto error;
+ if (!command_line_get_partition (_("Partition number?"), disk, &part))
+ goto error_destroy_disk;
+ if (!command_line_get_fs_type (_("File system type?"), &type))
+ goto error_destroy_disk;
if (!opt_script_mode && !_partition_warn_loss())
goto error_destroy_disk;
- if (!command_line_get_partition (_("Partition number?"), disk, &part))
- goto error_destroy_disk;
if (!_partition_warn_busy (part))
goto error_destroy_disk;
- if (!command_line_get_fs_type (_("File system type?"), &type))
- goto error_destroy_disk;
fs = ped_file_system_create (&part->geom, type, g_timer);
if (!fs)
@@ -1046,8 +1045,6 @@ do_move (PedDevice** dev)
if (!command_line_get_partition (_("Partition number?"), disk, &part))
goto error_destroy_disk;
- if (!_partition_warn_busy (part))
- goto error_destroy_disk;
if (part->type == PED_PARTITION_EXTENDED) {
ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
_("Can't move an extended partition."));
@@ -1064,6 +1061,8 @@ do_move (PedDevice** dev)
end = start + old_geom.length - 1;
if (!command_line_get_sector (_("End?"), *dev, &end, &range_end))
goto error_close_fs;
+ if (!_partition_warn_busy (part))
+ goto error_close_fs;
/* set / test on "disk" */
if (!ped_geometry_init (&new_geom, *dev, start, end - start + 1))
@@ -1817,10 +1816,6 @@ do_resize (PedDevice** dev)
if (!command_line_get_partition (_("Partition number?"), disk, &part))
goto error_destroy_disk;
- if (part->type != PED_PARTITION_EXTENDED) {
- if (!_partition_warn_busy (part))
- goto error_destroy_disk;
- }
start = part->geom.start;
end = part->geom.end;
@@ -1828,6 +1823,10 @@ do_resize (PedDevice** dev)
goto error_destroy_disk;
if (!command_line_get_sector (_("End?"), *dev, &end, &range_end))
goto error_destroy_disk;
+ if (part->type != PED_PARTITION_EXTENDED) {
+ if (!_partition_warn_busy (part))
+ goto error_destroy_disk;
+ }
if (!ped_geometry_init (&new_geom, *dev, start, end - start + 1))
goto error_destroy_disk;
More information about the parted-devel
mailing list