[PATCH 1/4] UI: remove file-system-aware sub-commands, but not "=
Jim Meyering
meyering at redhat.com
Thu Sep 17 14:20:56 UTC 2009
resize"
Note that we are *not* removing the resize command,
because parted appears to be the only tool that provides
the ability to resize FAT16 and FAT32 file systems.
* parted/parted.c (do_mkfs, do_cp, do_mkpartfs): Remove functions.
(do_move, do_check): Likewise.
(_init_commands): Remove each command-definition clause.
---
parted/parted.c | 462 +------------------------------------------------=
------
1 files changed, 1 insertions(+), 461 deletions(-)
diff --git a/parted/parted.c b/parted/parted.c
index addd775..a7253d2 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -445,115 +445,6 @@ help_on (char* topic)
command_print_help (cmd);
}
-static int
-do_check (PedDevice** dev)
-{
- PedDisk* disk;
- PedFileSystem* fs;
- PedPartition* part =3D NULL;
-
- disk =3D ped_disk_new (*dev);
- if (!disk)
- goto error;
-
- if (!command_line_get_partition (_("Partition number?"), disk, &=
part))
- goto error_destroy_disk;
- if (!_partition_warn_busy (part))
- goto error_destroy_disk;
-
- if (!ped_disk_check (disk))
- goto error_destroy_disk;
-
- fs =3D ped_file_system_open (&part->geom);
- if (!fs)
- goto error_destroy_disk;
- if (!ped_file_system_check (fs, g_timer))
- goto error_close_fs;
- ped_file_system_close (fs);
- ped_disk_destroy (disk);
- return 1;
-
-error_close_fs:
- ped_file_system_close (fs);
-error_destroy_disk:
- ped_disk_destroy (disk);
-error:
- return 0;
-}
-
-static int
-do_cp (PedDevice** dev)
-{
- PedDisk* src_disk;
- PedDisk* dst_disk;
- PedPartition* src =3D NULL;
- PedPartition* dst =3D NULL;
- PedFileSystem* src_fs;
- PedFileSystem* dst_fs;
- PedFileSystemType* dst_fs_type;
-
- dst_disk =3D ped_disk_new (*dev);
- if (!dst_disk)
- goto error;
-
- src_disk =3D dst_disk;
- if (!command_line_is_integer ()) {
- if (!command_line_get_disk (_("Source device?"), &src_di=
sk))
- goto error_destroy_disk;
- }
-
- if (!command_line_get_partition (_("Source partition number?"),
- src_disk, &src))
- goto error_destroy_disk;
- if (src->type =3D=3D PED_PARTITION_EXTENDED) {
- ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_=
CANCEL,
- _("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 (dst))
- goto error_destroy_disk;
-
-/* do the copy */
- src_fs =3D ped_file_system_open (&src->geom);
- if (!src_fs)
- goto error_destroy_disk;
- dst_fs =3D ped_file_system_copy (src_fs, &dst->geom, g_timer);
- if (!dst_fs)
- goto error_close_src_fs;
- dst_fs_type =3D dst_fs->type; /* may be different to src_fs-=
>type */
- ped_file_system_close (src_fs);
- ped_file_system_close (dst_fs);
-
-/* update the partition table, close disks */
- if (!ped_partition_set_system (dst, dst_fs_type))
- goto error_destroy_disk;
- if (!ped_disk_commit (dst_disk))
- goto error_destroy_disk;
- if (src_disk !=3D dst_disk)
- ped_disk_destroy (src_disk);
- ped_disk_destroy (dst_disk);
-
- if ((*dev)->type !=3D PED_DEVICE_FILE)
- disk_is_modified =3D 1;
-
- return 1;
-
-error_close_src_fs:
- ped_file_system_close (src_fs);
-error_destroy_disk:
- if (src_disk && src_disk !=3D dst_disk)
- ped_disk_destroy (src_disk);
- ped_disk_destroy (dst_disk);
-error:
- return 0;
-}
-
void
print_commands_help ()
{
@@ -634,52 +525,6 @@ error:
}
static int
-do_mkfs (PedDevice** dev)
-{
- PedDisk* disk;
- PedPartition* part =3D NULL;
- const PedFileSystemType* type =3D ped_file_system_type_get ("ext=
2");
- PedFileSystem* fs;
-
- disk =3D ped_disk_new (*dev);
- if (!disk)
- goto error;
-
- 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 =3D ped_file_system_create (&part->geom, type, g_timer);
- if (!fs)
- goto error_destroy_disk;
- ped_file_system_close (fs);
-
- if (!ped_partition_set_system (part, type))
- goto error_destroy_disk;
- if (ped_partition_is_flag_available (part, PED_PARTITION_LBA))
- ped_partition_set_flag (part, PED_PARTITION_LBA, 1);
- if (!ped_disk_commit (disk))
- goto error_destroy_disk;
- ped_disk_destroy (disk);
-
- if ((*dev)->type !=3D PED_DEVICE_FILE)
- disk_is_modified =3D 1;
-
- return 1;
-
-error_destroy_disk:
- ped_disk_destroy (disk);
-error:
- return 0;
-}
-
-static int
do_mkpart (PedDevice** dev)
{
PedDisk* disk;
@@ -778,8 +623,7 @@ do_mkpart (PedDevice** dev)
/* In script mode failure to use specified value=
s is fatal.
* However, in interactive mode, it merely elici=
ts a warning
- * and a prompt for whether to proceed. The sam=
e appies for
- * do_mkpartfs function.
+ * and a prompt for whether to proceed.
*/
switch (ped_exception_throw (
(opt_script_mode
@@ -862,266 +706,6 @@ error:
}
static int
-do_mkpartfs (PedDevice** dev)
-{
- PedDisk* disk;
- PedPartition* part;
- PedPartitionType part_type;
- const PedFileSystemType* fs_type =3D ped_file_system_type_get ("=
ext2");
- PedSector start =3D 0, end =3D 0;
- PedGeometry *range_start =3D NULL, *range_end =3D NULL;
- PedConstraint* user_constraint;
- PedConstraint* dev_constraint;
- PedConstraint* final_constraint;
- PedFileSystem* fs;
- char* part_name =3D NULL;
- char *start_usr =3D NULL, *end_usr =3D NULL;
- char *start_sol =3D NULL, *end_sol =3D NULL;
-
- disk =3D ped_disk_new (*dev);
- if (!disk)
- goto error;
-
- if (!ped_disk_type_check_feature (disk->type, PED_DISK_TYPE_EXTE=
NDED)) {
- part_type =3D PED_PARTITION_NORMAL;
- } else {
- if (!command_line_get_part_type (_("Partition type?"),
- disk, &part_type))
- goto error_destroy_disk;
- }
-
- if (ped_disk_type_check_feature (disk->type,
- PED_DISK_TYPE_PARTITION_NAME))
- part_name =3D command_line_get_word (_("Partition name?"=
),
- "", NULL, 1);
-
- if (part_type =3D=3D PED_PARTITION_EXTENDED) {
- ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_=
CANCEL,
- _("An extended partition cannot hold a file syst=
em. "
- "Did you want mkpart?"));
- goto error_destroy_disk;
- }
-
- if (!command_line_get_fs_type (_("File system type?"), &fs_type)=
)
- goto error_destroy_disk;
- if (!command_line_get_sector (_("Start?"), *dev, &start,
- &range_start))
- goto error_destroy_disk;
- if (!command_line_get_sector (_("End?"), *dev, &end, &range_end)=
)
- goto error_destroy_disk;
-
- /* attempt to create the partition now */
- part =3D ped_partition_new (disk, part_type, fs_type, start, end=
);
- if (!part)
- goto error_destroy_disk;
-
- snap_to_boundaries (&part->geom, NULL, disk, range_start, range_=
end);
-
- /* create constraints */
- user_constraint =3D constraint_from_start_end (*dev, range_start=
,
- range_en=
d);
- PED_ASSERT (user_constraint !=3D NULL, return 0);
-
- dev_constraint =3D ped_device_get_constraint (*dev);
- PED_ASSERT (dev_constraint !=3D NULL, return 0);
-
- final_constraint =3D ped_constraint_intersect (user_constraint,
- dev_constraint);
- ped_constraint_destroy (user_constraint);
- ped_constraint_destroy (dev_constraint);
- if (!final_constraint)
- goto error_destroy_simple_constraints;
-
- /* subject to partition constraint */
- ped_exception_fetch_all();
- bool added_ok =3D ped_disk_add_partition (disk, part, final_constraint)=
;
- ped_constraint_destroy (final_constraint);
- if (!added_ok) {
- ped_exception_leave_all();
-
- if (ped_disk_add_partition (disk, part,
- ped_constraint_any (*dev))) {
- start_usr =3D ped_unit_format (*dev, start);
- end_usr =3D ped_unit_format (*dev, end);
- start_sol =3D ped_unit_format (*dev, part->geom.=
start);
- end_sol =3D ped_unit_format (*dev, part->geom.=
end);
-
- switch (ped_exception_throw (
- (opt_script_mode
- ? PED_EXCEPTION_ERROR
- : PED_EXCEPTION_WARNING),
- (opt_script_mode
- ? PED_EXCEPTION_CANCEL
- : PED_EXCEPTION_YES_NO),
- _("You requested a partition from %s to =
%s.\n"
- "The closest location we can manage is=
"
- "%s to %s.%s"),
- start_usr, end_usr, start_sol, end_sol,
- (opt_script_mode ? ""
- : _("\nIs this still acceptable to you?=
"))))
- {
- case PED_EXCEPTION_YES:
- /* all is well in this state */
- break;
- case PED_EXCEPTION_NO:
- case PED_EXCEPTION_UNHANDLED:
- default:
- /* undo partition addition */
- goto error_remove_part;
- }
- } else {
- goto error_remove_part;
- }
- } else {
- ped_exception_leave_all();
- }
- ped_exception_catch();
-
- /* set LBA flag automatically if available */
- if (ped_partition_is_flag_available (part, PED_PARTITION_LBA))
- ped_partition_set_flag (part, PED_PARTITION_LBA, 1);
-
- /* fs creation */
- fs =3D ped_file_system_create (&part->geom, fs_type, g_timer);
- if (!fs)
- goto error_destroy_disk;
- ped_file_system_close (fs);
-
- if (!ped_partition_set_system (part, fs_type))
- goto error_destroy_disk;
-
- if (!ped_disk_commit (disk))
- goto error_destroy_disk;
-
- /* clean up */
-
- ped_disk_destroy (disk);
-
- if (range_start !=3D NULL)
- ped_geometry_destroy (range_start);
- if (range_end !=3D NULL)
- ped_geometry_destroy (range_end);
-
- free (start_usr);
- free (end_usr);
- free (start_sol);
- free (end_sol);
-
- if ((*dev)->type !=3D PED_DEVICE_FILE)
- disk_is_modified =3D 1;
-
- return 1;
-
-error_remove_part:
- ped_disk_remove_partition (disk, part);
-error_destroy_simple_constraints:
- ped_partition_destroy (part);
-error_destroy_disk:
- ped_disk_destroy (disk);
-error:
- if (range_start !=3D NULL)
- ped_geometry_destroy (range_start);
- if (range_end !=3D NULL)
- ped_geometry_destroy (range_end);
-
- free (start_usr);
- free (end_usr);
- free (start_sol);
- free (end_sol);
-
- return 0;
-}
-
-static int
-do_move (PedDevice** dev)
-{
- PedDisk* disk;
- PedPartition* part =3D NULL;
- PedFileSystem* fs;
- PedFileSystem* fs_copy;
- PedConstraint* constraint;
- PedSector start =3D 0, end =3D 0;
- PedGeometry *range_start =3D NULL, *range_end =3D NULL;
- PedGeometry old_geom, new_geom;
-
- disk =3D ped_disk_new (*dev);
- if (!disk)
- goto error;
-
- 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 =3D=3D PED_PARTITION_EXTENDED) {
- ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_=
CANCEL,
- _("Can't move an extended partition."));
- goto error_destroy_disk;
- }
- old_geom =3D part->geom;
- fs =3D ped_file_system_open (&old_geom);
- if (!fs)
- goto error_destroy_disk;
-
- /* get new target */
- if (!command_line_get_sector (_("Start?"), *dev, &start, &range_=
start))
- goto error_close_fs;
- end =3D start + old_geom.length - 1;
- if (!command_line_get_sector (_("End?"), *dev, &end, &range_end)=
)
- goto error_close_fs;
-
- /* set / test on "disk" */
- if (!ped_geometry_init (&new_geom, *dev, start, end - start + 1)=
)
- goto error_close_fs;
- snap_to_boundaries (&new_geom, NULL, disk, range_start, range_en=
d);
-
- constraint =3D constraint_intersect_and_destroy (
- ped_file_system_get_copy_constraint (fs, *dev),
- constraint_from_start_end(*dev,range_start,range=
_end));
- if (!ped_disk_set_partition_geom (disk, part, constraint,
- new_geom.start, new_geom.end))
- goto error_destroy_constraint;
- ped_constraint_destroy (constraint);
- if (ped_geometry_test_overlap (&old_geom, &part->geom)) {
- ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_=
CANCEL,
- _("Can't move a partition onto itself. Try usin=
g "
- "resize, perhaps?"));
- goto error_close_fs;
- }
-
- /* do the move */
- fs_copy =3D ped_file_system_copy (fs, &part->geom, g_timer);
- if (!fs_copy)
- goto error_close_fs;
- ped_file_system_close (fs_copy);
- ped_file_system_close (fs);
- if (!ped_disk_commit (disk))
- goto error_destroy_disk;
- ped_disk_destroy (disk);
- if (range_start !=3D NULL)
- ped_geometry_destroy (range_start);
- if (range_end !=3D NULL)
- ped_geometry_destroy (range_end);
-
- if ((*dev)->type !=3D PED_DEVICE_FILE)
- disk_is_modified =3D 1;
-
- return 1;
-
-error_destroy_constraint:
- ped_constraint_destroy (constraint);
-error_close_fs:
- ped_file_system_close (fs);
-error_destroy_disk:
- ped_disk_destroy (disk);
-error:
- if (range_start !=3D NULL)
- ped_geometry_destroy (range_start);
- if (range_end !=3D NULL)
- ped_geometry_destroy (range_end);
- return 0;
-}
-
-static int
do_name (PedDevice** dev)
{
PedDisk* disk;
@@ -2142,24 +1726,6 @@ static void
_init_commands ()
{
command_register (commands, command_create (
- str_list_create_unique ("check", _("check"), NULL),
- do_check,
- str_list_create (
-_("check NUMBER do a simple check on the fil=
e "
- "system"),
-NULL),
- str_list_create (_(number_msg), NULL), 1));
-
- command_register (commands, command_create (
- str_list_create_unique ("cp", _("cp"), NULL),
- do_cp,
- str_list_create (
-_("cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER copy file system to another =
"
- "partition"),
-NULL),
- str_list_create (_(number_msg), _(device_msg), NULL), 1)=
);
-
- command_register (commands, command_create (
str_list_create_unique ("help", _("help"), NULL),
do_help,
str_list_create (
@@ -2178,15 +1744,6 @@ NULL),
str_list_create (label_type_msg, NULL), 1));
command_register (commands, command_create (
- str_list_create_unique ("mkfs", _("mkfs"), NULL),
- do_mkfs,
- str_list_create (
-_("mkfs NUMBER FS-TYPE make a FS-TYPE file "
- "system on partition NUMBER"),
-NULL),
- str_list_create (_(number_msg), _(mkfs_fs_type_msg), NUL=
L), 1));
-
- command_register (commands, command_create (
str_list_create_unique ("mkpart", _("mkpart"), NULL),
do_mkpart,
str_list_create (
@@ -2200,23 +1757,6 @@ _("'mkpart' makes a partition without creating a n=
ew file system on the "
"partition. FS-TYPE may be specified to set an appropriate partition =
ID.\n"),
NULL), 1));
- command_register (commands, command_create (
- str_list_create_unique ("mkpartfs", _("mkpartfs"), NULL)=
,
- do_mkpartfs,
- str_list_create (
-_("mkpartfs PART-TYPE FS-TYPE START END make a partition with a "
- "file system"),
-NULL),
- str_list_create (_(part_type_msg), _(start_end_msg), NULL), 1));
-
-command_register (commands, command_create (
- str_list_create_unique ("move", _("move"), NULL),
- do_move,
- str_list_create (
-_("move NUMBER START END move partition NUMBER"),
-NULL),
- str_list_create (_(number_msg), _(start_end_msg), NULL), 1));
-
command_register (commands, command_create (
str_list_create_unique ("name", _("name"), NULL),
do_name,
--=20
1.6.5.rc1.192.g63b0
More information about the parted-devel
mailing list