The new --align commandline option can have the following values: none: Use the minimum alignment allowed by the disk type cyl: Align partitions to cylinders (the default) min: Use minimum alignment as given by the disk topology information opt: Use optimum alignment as given by the disk topology information
Note the min and opt values will use layout information provided by the disk to align the logical partition table addresses to actual physical blocks on the disks. The min value is the minimum aligment needed to align the partition properly to physical blocks, which avoids performance degradation. Where as the optimum aligment align's to a multiple of the physical block size in a way that guarantees optimal performance. The min and opt values will only work when compiled with libblkid >= 2.17 and running on a kernel >= 2.6.31, otherwise they will behave as the none --align value. * parted/parted.c(ALIGNMENT_ enum values): New enum. * parted/parted.c(options, options_help): Add --align option. * parted/parted.c(alignment): New global variable. * parted/parted.c(do_mkpart): Honor aligment variable. * parted/parted.c(_parse_options): handle --align option. --- parted/parted.c | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 42 insertions(+), 4 deletions(-) diff --git a/parted/parted.c b/parted/parted.c index 099bc94..f1c5cf0 100644 --- a/parted/parted.c +++ b/parted/parted.c @@ -74,6 +74,13 @@ enum PRETEND_INPUT_TTY = CHAR_MAX + 1, }; +enum +{ + ALIGNMENT_NONE, + ALIGNMENT_CYLINDER, + ALIGNMENT_MINIMAL, + ALIGNMENT_OPTIMAL, +}; typedef struct { time_t last_update; @@ -87,6 +94,7 @@ static struct option const options[] = { {"machine", 0, NULL, 'm'}, {"script", 0, NULL, 's'}, {"version", 0, NULL, 'v'}, + {"align", required_argument, NULL, 'a'}, {"-pretend-input-tty", 0, NULL, PRETEND_INPUT_TTY}, {NULL, 0, NULL, 0} }; @@ -97,6 +105,7 @@ static const char *const options_help [][2] = { {"machine", N_("displays machine parseable output")}, {"script", N_("never prompts for user intervention")}, {"version", N_("displays the version")}, + {"align=[none|cyl|min|opt]", N_("alignment for new partitions")}, {NULL, NULL} }; @@ -105,6 +114,7 @@ int pretend_input_tty = 0; int opt_machine_mode = 0; int disk_is_modified = 0; int is_toggle_mode = 0; +int alignment = ALIGNMENT_CYLINDER; static const char* number_msg = N_( "NUMBER is the partition number used by Linux. On MS-DOS disk labels, the " @@ -587,7 +597,7 @@ print_options_help () int i; for (i=0; options_help [i][0]; i++) { - printf (" -%c, --%-23.23s %s\n", + printf (" -%c, --%-25.25s %s\n", options_help [i][0][0], options_help [i][0], _(options_help [i][1])); @@ -719,6 +729,11 @@ do_mkpart (PedDevice** dev) if (!disk) goto error; + if (ped_disk_is_flag_available(disk, PED_DISK_CYLINDER_ALIGNMENT)) + if (!ped_disk_set_flag(disk, PED_DISK_CYLINDER_ALIGNMENT, + alignment == ALIGNMENT_CYLINDER)) + goto error_destroy_disk; + if (!ped_disk_type_check_feature (disk->type, PED_DISK_TYPE_EXTENDED)) { part_type = PED_PARTITION_NORMAL; } else { @@ -771,7 +786,14 @@ do_mkpart (PedDevice** dev) range_end); PED_ASSERT (user_constraint != NULL, return 0); - dev_constraint = ped_device_get_constraint (*dev); + if (alignment == ALIGNMENT_OPTIMAL) + dev_constraint = + ped_device_get_optimal_aligned_constraint(*dev); + else if (alignment == ALIGNMENT_MINIMAL) + dev_constraint = + ped_device_get_minimal_aligned_constraint(*dev); + else + dev_constraint = ped_device_get_constraint(*dev); PED_ASSERT (dev_constraint != NULL, return 0); final_constraint = ped_constraint_intersect (user_constraint, @@ -2451,7 +2473,7 @@ int opt, help = 0, list = 0, version = 0, wrong = 0; while (1) { - opt = getopt_long (*argc_ptr, *argv_ptr, "hlmsv", + opt = getopt_long (*argc_ptr, *argv_ptr, "hlmsva:", options, NULL); if (opt == -1) break; @@ -2462,6 +2484,22 @@ while (1) case 'm': opt_machine_mode = 1; break; case 's': opt_script_mode = 1; break; case 'v': version = 1; break; + case 'a': + if (!strcmp(optarg, "none")) + alignment = ALIGNMENT_NONE; + else if (!strcmp(optarg, "cyl")) + alignment = ALIGNMENT_CYLINDER; + else if (!strcmp(optarg, "min")) + alignment = ALIGNMENT_MINIMAL; + else if (!strcmp(optarg, "opt")) + alignment = ALIGNMENT_OPTIMAL; + else { + fprintf(stderr, + "%s: Invalid alignment value: %s\n", + program_name, optarg); + wrong = 1; + } + break; case PRETEND_INPUT_TTY: pretend_input_tty = 1; break; @@ -2471,7 +2509,7 @@ while (1) if (wrong == 1) { fprintf (stderr, - _("Usage: %s [-hlmsv] [DEVICE [COMMAND [PARAMETERS]]...]\n"), + _("Usage: %s [-hlmsv] [-a<align>] [DEVICE [COMMAND [PARAMETERS]]...]\n"), program_name); return 0; } -- 1.6.5.2 _______________________________________________ bug-parted mailing list bug-parted@gnu.org http://lists.gnu.org/mailman/listinfo/bug-parted