Here's the start of the UI removals I mentioned recently. It removes all FS-aware sub-commands except resize. We have to retain resize at least for FAT16/32, since there seems to be no other unix-oriented tool that can do that. I'm leaving the resize command in the UI to ease shell-based testing.
This series isn't complete, since it still allows resizing of file systems of types other than FAT16/32. That's next. I'll add a few tests of resizing, along the way. I'll push these or something close on Monday.
>From 3b9cbae47d1424a4c856164ab2c59afebbfc6fec Mon Sep 17 00:00:00 2001 From: Jim Meyering <[email protected]> Date: Thu, 17 Sep 2009 16:20:56 +0200 Subject: [PATCH 1/4] UI: remove file-system-aware sub-commands, but not "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 = NULL; - - disk = 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 = 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 = NULL; - PedPartition* dst = NULL; - PedFileSystem* src_fs; - PedFileSystem* dst_fs; - PedFileSystemType* dst_fs_type; - - dst_disk = ped_disk_new (*dev); - if (!dst_disk) - goto error; - - src_disk = dst_disk; - if (!command_line_is_integer ()) { - if (!command_line_get_disk (_("Source device?"), &src_disk)) - goto error_destroy_disk; - } - - if (!command_line_get_partition (_("Source partition number?"), - src_disk, &src)) - goto error_destroy_disk; - if (src->type == 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 = ped_file_system_open (&src->geom); - if (!src_fs) - goto error_destroy_disk; - dst_fs = ped_file_system_copy (src_fs, &dst->geom, g_timer); - if (!dst_fs) - goto error_close_src_fs; - dst_fs_type = 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 != dst_disk) - ped_disk_destroy (src_disk); - ped_disk_destroy (dst_disk); - - if ((*dev)->type != PED_DEVICE_FILE) - disk_is_modified = 1; - - return 1; - -error_close_src_fs: - ped_file_system_close (src_fs); -error_destroy_disk: - if (src_disk && src_disk != 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 = NULL; - const PedFileSystemType* type = ped_file_system_type_get ("ext2"); - PedFileSystem* fs; - - disk = 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 = 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 != PED_DEVICE_FILE) - disk_is_modified = 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 values is fatal. * However, in interactive mode, it merely elicits a warning - * and a prompt for whether to proceed. The same 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 = ped_file_system_type_get ("ext2"); - PedSector start = 0, end = 0; - PedGeometry *range_start = NULL, *range_end = NULL; - PedConstraint* user_constraint; - PedConstraint* dev_constraint; - PedConstraint* final_constraint; - PedFileSystem* fs; - char* part_name = NULL; - char *start_usr = NULL, *end_usr = NULL; - char *start_sol = NULL, *end_sol = NULL; - - disk = ped_disk_new (*dev); - if (!disk) - goto error; - - if (!ped_disk_type_check_feature (disk->type, PED_DISK_TYPE_EXTENDED)) { - part_type = 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 = command_line_get_word (_("Partition name?"), - "", NULL, 1); - - if (part_type == PED_PARTITION_EXTENDED) { - ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL, - _("An extended partition cannot hold a file system. " - "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 = 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 = constraint_from_start_end (*dev, range_start, - range_end); - PED_ASSERT (user_constraint != NULL, return 0); - - dev_constraint = ped_device_get_constraint (*dev); - PED_ASSERT (dev_constraint != NULL, return 0); - - final_constraint = 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 = 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 = ped_unit_format (*dev, start); - end_usr = ped_unit_format (*dev, end); - start_sol = ped_unit_format (*dev, part->geom.start); - end_sol = 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 = 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 != NULL) - ped_geometry_destroy (range_start); - if (range_end != NULL) - ped_geometry_destroy (range_end); - - free (start_usr); - free (end_usr); - free (start_sol); - free (end_sol); - - if ((*dev)->type != PED_DEVICE_FILE) - disk_is_modified = 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 != NULL) - ped_geometry_destroy (range_start); - if (range_end != 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 = NULL; - PedFileSystem* fs; - PedFileSystem* fs_copy; - PedConstraint* constraint; - PedSector start = 0, end = 0; - PedGeometry *range_start = NULL, *range_end = NULL; - PedGeometry old_geom, new_geom; - - disk = 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 == PED_PARTITION_EXTENDED) { - ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL, - _("Can't move an extended partition.")); - goto error_destroy_disk; - } - old_geom = part->geom; - fs = 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 = 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_end); - - constraint = 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 using " - "resize, perhaps?")); - goto error_close_fs; - } - - /* do the move */ - fs_copy = 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 != NULL) - ped_geometry_destroy (range_start); - if (range_end != NULL) - ped_geometry_destroy (range_end); - - if ((*dev)->type != PED_DEVICE_FILE) - disk_is_modified = 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 != NULL) - ped_geometry_destroy (range_start); - if (range_end != 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 file " - "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), NULL), 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 new 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, -- 1.6.5.rc1.192.g63b0 >From 8541829f9163fd92d7d03c1bc5dc944b7150b97c Mon Sep 17 00:00:00 2001 From: Jim Meyering <[email protected]> Date: Thu, 17 Sep 2009 20:12:50 +0200 Subject: [PATCH 2/4] tests: remove tests that are too FS-centric * tests/t1000-mkpartfs.sh: Remove file. * tests/t1500-small-ext2.sh: Likewise. * tests/t2000-mkfs.sh: Likewise. * tests/t3100-resize-ext2-partion.sh: Likewise. * tests/t3000-constraints.sh: Likewise. * tests/Makefile.am (TESTS): Remove them here, too. --- tests/Makefile.am | 4 - tests/t1000-mkpartfs.sh | 70 ---------------- tests/t1500-small-ext2.sh | 64 --------------- tests/t2000-mkfs.sh | 152 ------------------------------------ tests/t3000-constraints.sh | 54 ------------- tests/t3100-resize-ext2-partion.sh | 55 ------------- 6 files changed, 0 insertions(+), 399 deletions(-) delete mode 100755 tests/t1000-mkpartfs.sh delete mode 100755 tests/t1500-small-ext2.sh delete mode 100755 tests/t2000-mkfs.sh delete mode 100755 tests/t3000-constraints.sh delete mode 100755 tests/t3100-resize-ext2-partion.sh diff --git a/tests/Makefile.am b/tests/Makefile.am index 399653b..326ccb4 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -9,14 +9,10 @@ TESTS = \ t0400-loop-clobber-infloop.sh \ t1000-mkpartfs.sh \ t1100-busy-label.sh \ - t1500-small-ext2.sh \ t1700-ext-probe.sh \ - t2000-mkfs.sh \ t2100-mkswap.sh \ t2200-dos-label-recog.sh \ t2300-dos-label-extended-bootcode.sh \ - t3000-constraints.sh \ - t3100-resize-ext2-partion.sh \ t4000-sun-raid-type.sh \ t4100-msdos-partition-limits.sh \ t4100-dvh-partition-limits.sh \ diff --git a/tests/t1000-mkpartfs.sh b/tests/t1000-mkpartfs.sh deleted file mode 100755 index 96bb274..0000000 --- a/tests/t1000-mkpartfs.sh +++ /dev/null @@ -1,70 +0,0 @@ -#!/bin/sh - -# Copyright (C) 2007, 2009 Free Software Foundation, Inc. - -# 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/>. - -test_description='Create some file systems using mkpartfs.' - -: ${srcdir=.} -. $srcdir/test-lib.sh - -require_512_byte_sector_size_ - -N=500k -dev=loop-file -test_expect_success \ - 'create a file too small to hold a fat32 file system' \ - 'dd if=/dev/null of=$dev bs=1 seek=$N 2> /dev/null' - -test_expect_success \ - 'label the test disk' \ - 'parted -s $dev mklabel msdos > out 2>&1' -test_expect_success 'expect no output' 'compare out /dev/null' - -# Expect parted's mkpartfs command to fail. -test_expect_failure \ - 'try/fail to create a file system in too small a space' \ - 'parted -s $dev mkpartfs primary fat32 0 1 > out 2>&1' - -test_expect_success \ - 'create expected output file' \ - 'echo "Error: Partition too big/small for a fat32 file system." > exp' - -test_expect_success \ - 'check for expected failure diagnostic' \ - 'compare out exp' - -test_expect_success 'clean up, preparing for next test' 'rm $dev out' - -#==================================================================== -# Similar, but with a file that's large enough, so mkpartfs succeeds. -N=40M - -test_expect_success \ - 'create a file large enough to hold a fat32 file system' \ - 'dd if=/dev/null of=$dev bs=1 seek=$N 2> /dev/null' - -test_expect_success \ - 'label the test disk' \ - 'parted -s $dev mklabel msdos > out 2>&1' -test_expect_success 'expect no output' 'compare out /dev/null' - -test_expect_success \ - 'create an msdos file system' \ - 'parted -s $dev mkpartfs primary fat32 1 40 > out 2>&1' - -test_expect_success 'expect no output' 'compare out /dev/null' - -test_done diff --git a/tests/t1500-small-ext2.sh b/tests/t1500-small-ext2.sh deleted file mode 100755 index c07d3f8..0000000 --- a/tests/t1500-small-ext2.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/sh - -# Copyright (C) 2007, 2009 Free Software Foundation, Inc. - -# 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/>. - -test_description='Create very small ext2 file systems.' - -: ${srcdir=.} -. $srcdir/test-lib.sh - -require_512_byte_sector_size_ - -dev=loop-file -test_expect_success \ - 'setup' ' - dd if=/dev/null of=$dev bs=1 seek=10M 2> /dev/null && - parted -s $dev mklabel msdos' - -test_expect_failure \ - 'try to create an ext2 partition that is one byte too small' ' - parted -s $dev mkpartfs primary ext2 10KB 29695B > out 2>&1' - -test_expect_success \ - 'check for expected diagnostic' ' - echo Error: File system too small for ext2. > exp && - compare out exp' - -test_expect_success \ - 'create the smallest ext2 partition' ' - parted -s $dev mkpartfs primary ext2 10KB 29696B > out 2>&1 - compare out /dev/null' - -# Restore $dev to initial state by writing 1KB of zeroes at the beginning. -# Then relabel. -test_expect_success \ - 'setup' ' - dd if=/dev/zero of=$dev bs=1K count=1 conv=notrunc 2> /dev/null && - parted -s $dev mklabel msdos' - -test_expect_success \ - 'create another ext2 file system (this would fail for parted-1.8.7)' ' - parted -s $dev mkpartfs primary ext2 2 10 > out 2>&1' -test_expect_success 'expect no output' 'compare out /dev/null' - -test_expect_success \ - 'create a smaller one; this would succeed for parted-1.8.7' ' - dd if=/dev/zero of=$dev bs=1K count=1 conv=notrunc 2> /dev/null && - parted -s $dev mklabel msdos && - parted -s $dev mkpartfs primary ext2 2 9 > out 2>&1' -test_expect_success 'expect no output' 'compare out /dev/null' - -test_done diff --git a/tests/t2000-mkfs.sh b/tests/t2000-mkfs.sh deleted file mode 100755 index faf80a7..0000000 --- a/tests/t2000-mkfs.sh +++ /dev/null @@ -1,152 +0,0 @@ -#!/bin/sh - -# Copyright (C) 2007, 2009 Free Software Foundation, Inc. - -# 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/>. - -test_description='Create some file systems using mkfs.' - -: ${srcdir=.} -. $srcdir/test-lib.sh - -require_512_byte_sector_size_ - -N=40M -dev=loop-file -test_expect_success \ - 'create a file large enough to hold a fat32 file system' \ - 'dd if=/dev/null of=$dev bs=1 seek=$N 2> /dev/null' - -test_expect_success \ - 'label the test disk' \ - 'parted -s $dev mklabel msdos > out 2>&1' -test_expect_success 'expect no output' 'compare out /dev/null' - -test_expect_success \ - 'create a partition' \ - 'parted -s $dev mkpart primary 1 40 > out 2>&1' - -test_expect_success \ - 'create an msdos file system' \ - 'parted -s $dev mkfs 1 fat32 > out 2>&1' - -test_expect_success 'expect no output' 'compare out /dev/null' - -N=10M -test_expect_success \ - 'create a file large enough to hold a fat32 file system' \ - 'dd if=/dev/null of=$dev bs=1 seek=$N 2> /dev/null' - -test_expect_success \ - 'label the test disk' \ - 'parted -s $dev mklabel msdos > out 2>&1' -test_expect_success 'expect no output' 'compare out /dev/null' - -# test if can create a partition and a filesystem in the same session. -fail=0 -cat <<EOF >in || fail=1 -mkpart -primary -ext2 -0 -10 -mkfs -No -quit -EOF -test_expect_success 'create input file' 'test $fail = 0' - -test_expect_success \ - 'create a partition and a filesystem in the same session' \ - 'parted ---pretend-input-tty $dev < in > out 2>&1' - -test_expect_success \ - 'normalize the actual output' \ - 'sed -n "s/.*\(Warning: The existing.*\)$/\1/p" out > out2' - -test_expect_success \ - 'check for expected prompt' \ - 'echo "Warning: The existing file system will be destroyed and all" \ - "data on the partition will be lost. Do you want to continue?" > exp && - compare out2 exp' - -############################################################# -# Ensure that an invalid file system type elicits a diagnostic. -# Before parted 1.8.8, this would fail silently. - -dev=loop-file - -test_expect_success \ - "setup: create and label a device" \ - 'dd if=/dev/null of=$dev bs=1 seek=1M 2>/dev/null && - parted -s $dev mklabel msdos' - -test_expect_failure \ - 'try to create a file system with invalid type name' \ - 'parted -s $dev mkpartfs primary bogus 1 1 >out 2>&1' - -test_expect_success \ - 'normalize the actual output' \ - 'mv out o2 && sed -e "s, * ,,;s, $,," \ - -e "s,^.*/lt-parted: ,parted: ," o2 > out' - -test_expect_success \ - 'check for expected diagnostic' \ - '{ echo "parted: invalid token: bogus" - echo "Error: Expecting a file system type."; } > exp && - compare out exp' - -############################################################# -# Demonstrate 3-block-group failure for 16+MB EXT2 file system. -# This test would fail with parted-1.8.7. - -dev=loop-file - -mkfs() -{ - size=$1 - test_expect_success \ - "setup: create and label a device" \ - 'dd if=/dev/null of=$dev bs=1 seek=30M 2>/dev/null && - parted -s $dev mklabel gpt' - - test_expect_success \ - "try to create an ext2 file system of size $size" \ - 'parted -s $dev mkpartfs primary ext2 0 ${size}B >out 2>&1' - test_expect_success 'check for empty output' 'compare out /dev/null' -} - - -# size in bytes #block groups last_group_blocks (in ext2_mkfs) -mkfs 16795000 # 2 8191 -mkfs 16796000 # 2 8192 -mkfs 16796160 # 2 (was 3) 1 -mkfs 16797000 # 2 (was 3) 1 -mkfs 16798000 # 2 (was 3) 2 -# ... -mkfs 17154000 # 2 (was 3) 350 -mkfs 17155000 # 2 (was 3) 351 last_group_admin == last_group_blocks -mkfs 17156000 # 2 (was 3) 352 -mkfs 17157000 # 3 353 -mkfs 17158000 # 3 354 -# ... -mkfs 25184000 # 3 8192 -mkfs 25185000 # 3 (was 4) 1 (last_group_admin = 387) -mkfs 25186000 # 3 (was 4) 2 (last_group_admin = 387) -# ... -mkfs 25589000 # 3 (was 4) 394 (last_group_admin = 394) -mkfs 25589000 # 3 (was 4) 395 (last_group_admin = 394) -mkfs 25590000 # 4 396 - -test_done diff --git a/tests/t3000-constraints.sh b/tests/t3000-constraints.sh deleted file mode 100755 index 1673b09..0000000 --- a/tests/t3000-constraints.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/sh - -# Copyright (C) 2007-2009 Free Software Foundation, Inc. - -# 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/>. - -test_description="exercise Parted's constraint-management code" - -: ${srcdir=.} -. $srcdir/test-lib.sh - -require_512_byte_sector_size_ - -dev=loop-file -N=2 -t=ext2 - -test_expect_success \ - "setup: label and create a small $t partition" \ - 'dd if=/dev/null of=$dev bs=1 seek=${N}M 2>/dev/null && - { echo y; echo c; } > in && - { emit_superuser_warning - echo "Warning: You requested a partition from 1000kB to 2000kB." - echo "The closest location we can manage is 15.9kB to 15.9kB." - echo "Is this still acceptable to you?" - echo "Yes/No? y" - echo "Error: File system too small for ext2."; } > exp && - parted -s $dev mklabel msdos && - parted -s $dev mkpartfs primary $t 1 $N' - -# Before parted-1.9, this would fail with a buffer overrun -# leading to a segfault. -test_expect_failure \ - 'try to create another partition in the same place' \ - 'parted ---pretend-input-tty $dev mkpartfs primary $t 1 $N <in >out 2>&1' - -test_expect_success \ - 'normalize the actual output' \ - 'sed "s, * ,,;s, $,," out > o2 && mv -f o2 out' - -test_expect_success 'check for expected output' 'compare out exp' - -test_done diff --git a/tests/t3100-resize-ext2-partion.sh b/tests/t3100-resize-ext2-partion.sh deleted file mode 100755 index d1f47d8..0000000 --- a/tests/t3100-resize-ext2-partion.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/sh -# Exercise an EXT2-resizing bug. - -# Copyright (C) 2007, 2009 Free Software Foundation, Inc. - -# 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/>. - -test_description='Exercise an EXT2-resize bug in at least 1.8.7' - -: ${srcdir=.} -. $srcdir/test-lib.sh - -require_512_byte_sector_size_ - -dev=loop-file -# The "device size", $N, must be larger than $NEW_SIZE. -N=1500M - -# To trigger the bug, the target size must be 269M or larger. -NEW_SIZE=269M - -# $ORIG_SIZE may be just about anything smaller than $NEW_SIZE. -ORIG_SIZE=1M - -test_expect_success \ - 'create the test file' \ - 'dd if=/dev/null of=$dev bs=1 seek=$N 2> /dev/null' - -test_expect_success \ - 'run parted -s FILE mklabel msdos' \ - 'parted -s $dev mklabel msdos > out 2>&1' -test_expect_success 'check for empty output' 'compare out /dev/null' - -test_expect_success \ - 'make an ext2 primary partition' \ - 'parted -s $dev mkpartfs primary ext2 0 $ORIG_SIZE > out 2>&1' -test_expect_success 'check for empty output' 'compare out /dev/null' - -test_expect_success \ - 'resize ext2 primary partition' \ - 'parted -s $dev resize 1 0 $NEW_SIZE > out 2>&1' -test_expect_success 'check for empty output' 'compare out /dev/null' - -test_done -- 1.6.5.rc1.192.g63b0 >From 8856a9448de4ba9e6ec9cc013dae1c7ecac12c92 Mon Sep 17 00:00:00 2001 From: Jim Meyering <[email protected]> Date: Fri, 18 Sep 2009 08:23:09 +0200 Subject: [PATCH 3/4] tests: t2100: use mkswap command, not parted's mkfs Now that we've removed mkfs, we must deal with the consequences. Create swap file systems using mkswap. Perhaps more troublesome, this test must now be run as root and with an actual device that it can erase: parted could create a swap file system on the first partition in a file, but mkswap cannot. * tests/t2100-mkswap.sh: Rework not to perof --- tests/t2100-mkswap.sh | 64 +++++++++++++++++++----------------------------- 1 files changed, 25 insertions(+), 39 deletions(-) diff --git a/tests/t2100-mkswap.sh b/tests/t2100-mkswap.sh index 7650e53..95382b0 100755 --- a/tests/t2100-mkswap.sh +++ b/tests/t2100-mkswap.sh @@ -17,19 +17,21 @@ test_description='create linux-swap partitions' +privileges_required_=1 +erasable_device_required_=1 + : ${srcdir=.} . $srcdir/test-lib.sh require_512_byte_sector_size_ +dev=$DEVICE_TO_ERASE ###################################################################### # When creating a partition of type linux-swap(v1) in a DOS partition # table, ensure that the proper file system type (0x82) is used. # Some releases, e.g. parted-1.8.8 would mistakenly use 0x83. ###################################################################### -N=1M -dev=loop-file -dev2=loop-file-2 +N=5M test_expect_success \ 'create a file to simulate the underlying device' \ 'dd if=/dev/null of=$dev bs=1 seek=$N 2> /dev/null' @@ -41,13 +43,22 @@ test_expect_success 'expect no output' 'compare out /dev/null' test_expect_success \ 'create a partition' \ - 'parted -s $dev mkpart primary 0 1 > out 2>&1' + 'parted -s $dev mkpart primary "linux-swap(v1)" 0 2 > out 2>&1' test_expect_success 'expect no output' 'compare out /dev/null' +# There's a race condition here: on udev-based systems, the partition#1 +# device, ${dev}1 (i.e., /dev/sde1) is not created immediately, and +# without some delay, this mount command would fail. Using a flash card +# as $dev, the loop below typically iterates 7-20 times. +test_expect_success \ + 'wait for new partition device to appear' \ + 'i=0; while :; do + test -e "${dev}1" && break; test $i = 90 && break; + i=$(expr $i + 1); done' + test_expect_success \ 'create a linux-swap file system' \ - 'parted -s $dev mkfs 1 "linux-swap(v1)" > out 2>&1' -test_expect_success 'expect no output' 'compare out /dev/null' + 'mkswap ${dev}1' # Extract the byte at offset 451. It must be 0x82, not 0x83. test_expect_success \ @@ -55,51 +66,26 @@ test_expect_success \ 'od -t x1 -An -j450 -N1 $dev > out && echo " 82" > exp' test_expect_success 'expect it to be 82, not 83' 'compare out exp' +# partition starts at offset 16384; swap UUID is 1036 bytes in +# Save its UUID for later. test_expect_success \ - 'create another file to simulate the underlying device' \ - 'dd if=/dev/null of=$dev2 bs=1 seek=$N 2> /dev/null' - -test_expect_success \ - 'label another test disk' \ - 'parted -s $dev2 mklabel msdos > out 2>&1' -test_expect_success 'expect no output' 'compare out /dev/null' - -test_expect_success \ - 'create another partition' \ - 'parted -s $dev2 mkpart primary 0 1 > out 2>&1' -test_expect_success 'expect no output' 'compare out /dev/null' + 'extract UUID 1' \ + 'od -t x1 -An -j1036 -N16 ${dev}1 > uuid1' test_expect_success \ 'create another linux-swap file system' \ - 'parted -s $dev2 mkfs 1 "linux-swap(v1)" > out 2>&1' -test_expect_success 'expect no output' 'compare out /dev/null' + 'mkswap ${dev}1' -# partition starts at offset 16384; swap UUID is 1036 bytes in -test_expect_success \ - 'extract UUID 1' \ - 'od -t x1 -An -j17420 -N16 $dev > uuid1' test_expect_success \ 'extract UUID 2' \ - 'od -t x1 -An -j17420 -N16 $dev2 > uuid2' + 'od -t x1 -An -j1036 -N16 ${dev}1 > uuid2' test_expect_failure \ 'two linux-swap file systems have different UUIDs' \ 'compare uuid1 uuid2' test_expect_success \ - 'check linux-swap file system' \ - 'parted -s $dev2 check 1 > out 2>&1' -test_expect_success 'expect no output' 'compare out /dev/null' - -test_expect_success \ - 'extract new UUID 2' \ - 'od -t x1 -An -j17420 -N16 $dev2 > uuid2-new' -test_expect_success \ - 'check preserves linux-swap UUID' \ - 'compare uuid2 uuid2-new' - -test_expect_success \ - 'create a linux-swap file system via alias' \ - 'parted -s $dev mkfs 1 linux-swap > out 2>&1' + 'create a partition, and specify its type via the alias, linux-swap' \ + 'parted -s $dev mkpart primary linux-swap 2 3 > out 2>&1' test_expect_success 'expect no output' 'compare out /dev/null' test_done -- 1.6.5.rc1.192.g63b0 >From 8e310800dfe2bed077e963a3167e78adadb389ca Mon Sep 17 00:00:00 2001 From: Jim Meyering <[email protected]> Date: Fri, 18 Sep 2009 08:40:54 +0200 Subject: [PATCH 4/4] tests: t7000: remove mkpartfs tests This test tested both mkpart and mkpartfs. * tests/t7000-scripting.sh: Remove the mkpartfs tests. --- tests/t7000-scripting.sh | 8 +++----- 1 files changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/t7000-scripting.sh b/tests/t7000-scripting.sh index 21cd344..1a70c1e 100755 --- a/tests/t7000-scripting.sh +++ b/tests/t7000-scripting.sh @@ -45,11 +45,9 @@ normalize_part_diag_ errS || fail=1 sed s/Error/Warning/ errS printf 'Is this still acceptable to you?\nYes/No?'; } >> errI || fail=1 -for mkpart in mkpart mkpartfs; do - # With larger sector size, skip FS-related use of mkpartfs. - test $sector_size_ -gt 512 && test $mkpart = mkpartfs && continue +for mkpart in mkpart; do - # Test for mkpart/mkpartfs in scripting mode + # Test for mkpart in scripting mode test_expect_success \ 'Create the test file' \ 'dd if=/dev/zero of=testfile bs=${ss}c count=$N 2> /dev/null' @@ -65,7 +63,7 @@ for mkpart in mkpart mkpartfs; do compare out errS ' - # Test mkpart/mkpartfsin interactive mode. + # Test mkpart interactive mode. test_expect_success \ 'Create the test file' \ ' -- 1.6.5.rc1.192.g63b0
_______________________________________________ parted-devel mailing list [email protected] http://lists.alioth.debian.org/mailman/listinfo/parted-devel

