diff --exclude libtool --exclude config.* --exclude Makefile* -urN parted-1.4.24/parted/parted.c parted-1.4.24.new/parted/parted.c --- parted-1.4.24/parted/parted.c Sun Sep 30 09:45:38 2001 +++ parted-1.4.24.new/parted/parted.c Mon May 19 11:05:16 2003 @@ -77,6 +77,7 @@ static char* state_msg = N_("STATE is one of: on, off\n"); static char* device_msg = N_("DEVICE is usually /dev/hda or /dev/sda\n"); static char* name_msg = N_("NAME is any word you want\n"); +static char* unit_msg = N_("UNIT is one of M)egabytes, K)ilobytes or S)ectors\n"); static char* label_type_msg; static char* fs_type_msg; @@ -749,9 +750,10 @@ if (!disk) goto error; - printf (_("Disk geometry for %s: 0.000-%.3f megabytes\n"), + printf (_("Disk geometry for %s: 0.000-%.3f %s\n"), disk->dev->path, - (disk->dev->length-1) * 1.0 / MEGABYTE_SECTORS); + calc_user_sector((disk->dev->length-1), 0), + get_sector_unit_desc(0)); printf (_("Disk label type: %s\n"), disk->type->name); has_extended = ped_disk_type_check_feature (disk->type, @@ -778,9 +780,11 @@ printf ("%-5d ", part->num); - printf ("%10.3f %10.3f ", - (int) part->geom.start * 1.0 / MEGABYTE_SECTORS, - (int) part->geom.end * 1.0 / MEGABYTE_SECTORS); + printf ("%10.3f%c %10.3f%c ", + calc_user_sector((int) part->geom.start * 1.0, 0), + get_sector_unit(0), + calc_user_sector((int) part->geom.end * 1.0, 0), + get_sector_unit(0)); if (has_extended) printf ("%-9s ", @@ -813,6 +817,20 @@ } static int +do_unit(PedDevice** dev) +{ + char *unit; + + unit = get_word(); + if (!unit) { + help_on("unit"); + return 0; + } + sector_unit = unit[0]; + return 1; +} + +static int do_quit (PedDevice** dev) { _done (*dev); @@ -1216,6 +1234,14 @@ NULL), str_list_create (_(minor_msg), _(flag_msg), _(state_msg), NULL))); + + command_register (commands, command_create ( + str_list_create_unique ("unit", _("unit"), NULL), + do_unit, + str_list_create ( +_("unit UNIT set sector unit"), +NULL), + str_list_create (_(unit_msg), NULL))); } static void diff --exclude libtool --exclude config.* --exclude Makefile* -urN parted-1.4.24/parted/ui.c parted-1.4.24.new/parted/ui.c --- parted-1.4.24/parted/ui.c Sun Jan 13 15:44:33 2002 +++ parted-1.4.24.new/parted/ui.c Mon May 19 10:58:33 2003 @@ -85,6 +85,7 @@ static Command** commands; static StrList* ex_opt_str [64]; static PedExceptionOption current_exception_opt = 0; +int sector_unit = 'M'; int screen_width () @@ -351,12 +352,92 @@ return atoi (words [word_num++]); } +double +calc_user_sector(PedSector sector, int unit) +{ + double unit_mul; + + if (unit == 0) + unit = sector_unit; + + if (unit == 'S') { + unit_mul = 1; + } + else if (unit == 'M') { + unit_mul = MEGABYTE_SECTORS; + } + else if (unit == 'K') { + unit_mul = MEGABYTE_SECTORS / 1024; + } + return ((double) sector) / unit_mul; +} + +/* converts from user to system sector */ +PedSector +calc_system_sector(double sector, int unit) +{ + double unit_mul; + + if (unit == 0) + unit = sector_unit; + + if (unit == 'S') { + unit_mul = 1; + } + else if (unit == 'M') { + unit_mul = MEGABYTE_SECTORS; + } + else if (unit == 'K') { + unit_mul = MEGABYTE_SECTORS / 1024; + } + return (PedSector) (sector * unit_mul); +} + +const char * +get_sector_unit_desc(int unit) +{ + if (unit == 0) + unit = sector_unit; + + if (unit == 'S') + return "sectors"; + else if (unit == 'M') + return "MB"; + else if (unit == 'K') + return "KB"; + + return NULL; +} + +int +get_sector_unit(int unit) +{ + if (unit == 0) + unit = sector_unit; + + return toupper(unit); +} + /* input (from command) is in megabytes (possibly with decimals), output is in * sectors */ PedSector get_sector () { - return atof (words [word_num++]) * MEGABYTE_SECTORS; + char *w = words[word_num++], *last_char; + char unit; + unsigned long unit_mul; + + last_char = (w + strlen(w) - 1); + if (*last_char >= '0' && *last_char <= '9') { + /* default case */ + unit = 0; + } + else { + unit = toupper(*last_char); + *last_char = 0; + } + + return calc_system_sector(atof (w), unit); } int @@ -398,8 +479,14 @@ if (!word) return 0; for (; *word; word++) { - if (!isdigit (*word) && *word != '.') + if (!isdigit (*word) && *word != '.') { + if (*(word+1) == 0 && + (toupper(*word) == 'K' || + toupper(*word) == 'M' || + toupper(*word) == 'S')) + return 1; return 0; + } } return 1; } diff --exclude libtool --exclude config.* --exclude Makefile* -urN parted-1.4.24/parted/ui.h parted-1.4.24.new/parted/ui.h --- parted-1.4.24/parted/ui.h Sun Sep 30 09:45:49 2001 +++ parted-1.4.24.new/parted/ui.h Mon May 19 11:01:27 2003 @@ -24,6 +24,7 @@ #define MEGABYTE_SECTORS (MEGABYTE / 512) extern char* prog_name; +extern int sector_unit; extern int init_ui (); extern int non_interactive_mode (PedDevice** dev, Command* cmd_list[], @@ -41,6 +42,11 @@ extern int is_integer (); extern int is_sector (); extern int count_words (); + +extern int get_sector_unit(int unit); +extern const char *get_sector_unit_desc(int unit); +extern double calc_user_sector(PedSector sector, int unit); +extern PedSector calc_system_sector(double sector, int unit); extern void help_msg ();