diff options
-rw-r--r-- | fdisks/fdisk.c | 79 | ||||
-rw-r--r-- | fdisks/fdisk.h | 5 | ||||
-rw-r--r-- | fdisks/fdiskbsdlabel.c | 2 |
3 files changed, 55 insertions, 31 deletions
diff --git a/fdisks/fdisk.c b/fdisks/fdisk.c index fe1996698..b7e350f75 100644 --- a/fdisks/fdisk.c +++ b/fdisks/fdisk.c @@ -241,38 +241,61 @@ char *partition_type(struct fdisk_context *cxt, unsigned char type) return NULL; } -void list_types(struct fdisk_context *cxt) +void list_partition_types(struct fdisk_context *cxt) { - struct fdisk_parttype *sys = cxt->label->parttypes; - unsigned int last[4], done = 0, next = 0, size; + struct fdisk_parttype *types; int i; - for (i = 0; sys[i].name; i++); - size = i; + if (!cxt || !cxt->label || !cxt->label->parttypes) + return; - for (i = 3; i >= 0; i--) - last[3 - i] = done += (size + i - done) / (i + 1); - i = done = 0; + types = cxt->label->parttypes; - do { - #define NAME_WIDTH 15 - char name[NAME_WIDTH * MB_LEN_MAX]; - size_t width = NAME_WIDTH; - - printf("%c%2x ", i ? ' ' : '\n', sys[next].type); - size_t ret = mbsalign(_(sys[next].name), name, sizeof(name), - &width, MBS_ALIGN_LEFT, 0); - if (ret == (size_t)-1 || ret >= sizeof(name)) - printf("%-15.15s", _(sys[next].name)); - else - fputs(name, stdout); + if (types[0].typestr == NULL) { + /* + * Prints in 4 columns in format <hex> <name> + */ + unsigned int last[4], done = 0, next = 0, size; - next = last[i++] + done; - if (i > 3 || next >= last[i]) { - i = 0; - next = ++done; - } - } while (done < last[0]); + for (i = 0; types[i].name; i++); + size = i; + + for (i = 3; i >= 0; i--) + last[3 - i] = done += (size + i - done) / (i + 1); + i = done = 0; + + do { + #define NAME_WIDTH 15 + char name[NAME_WIDTH * MB_LEN_MAX]; + size_t width = NAME_WIDTH; + struct fdisk_parttype *t = &types[next]; + size_t ret; + + printf("%c%2x ", i ? ' ' : '\n', t->type); + ret = mbsalign(_(t->name), name, sizeof(name), + &width, MBS_ALIGN_LEFT, 0); + + if (ret == (size_t)-1 || ret >= sizeof(name)) + printf("%-15.15s", _(t->name)); + else + fputs(name, stdout); + + next = last[i++] + done; + if (i > 3 || next >= last[i]) { + i = 0; + next = ++done; + } + } while (done < last[0]); + + } else { + /* + * Prints 1 column in format <idx> <name> <typestr> + */ + struct fdisk_parttype *t; + + for (i = 0, t = types; t->name; t++, i++) + printf("%3d %-30s %s\n", i + 1, t->name, t->typestr); + } putchar('\n'); } @@ -567,7 +590,7 @@ read_hex(struct fdisk_context *cxt) { read_char(_("Hex code (type L to list codes): ")); if (tolower(*line_ptr) == 'l') - list_types(cxt); + list_partition_types(cxt); else if (isxdigit (*line_ptr)) { hex = 0; @@ -1740,7 +1763,7 @@ static void command_prompt(struct fdisk_context *cxt) unknown_command(c); break; case 'l': - list_types(cxt); + list_partition_types(cxt); break; case 'm': print_menu(MAIN_MENU); diff --git a/fdisks/fdisk.h b/fdisks/fdisk.h index 8221cd9a3..631c47fc8 100644 --- a/fdisks/fdisk.h +++ b/fdisks/fdisk.h @@ -104,7 +104,8 @@ typedef unsigned long long sector_t; */ struct fdisk_parttype { unsigned int type; /* type as number or zero */ - char *name; /* description */ + char *name; /* description */ + char *typestr; /* type as string or NULL */ }; /* @@ -200,7 +201,7 @@ extern void check(struct fdisk_context *cxt, int n, unsigned int h, unsigned int extern void change_units(struct fdisk_context *cxt); extern void fatal(struct fdisk_context *cxt, enum failure why); extern int get_partition(struct fdisk_context *cxt, int warn, int max); -extern void list_types(struct fdisk_context *cxt); +extern void list_partition_types(struct fdisk_context *cxt); extern int read_line (int *asked); extern char read_char(char *mesg); extern int read_hex(struct fdisk_context *cxt); diff --git a/fdisks/fdiskbsdlabel.c b/fdisks/fdiskbsdlabel.c index c7c13b1b1..adcdc2f23 100644 --- a/fdisks/fdiskbsdlabel.c +++ b/fdisks/fdiskbsdlabel.c @@ -274,7 +274,7 @@ bsd_command_prompt (struct fdisk_context *cxt) xbsd_write_bootstrap (cxt); break; case 'l': - list_types (cxt); + list_partition_types (cxt); break; case 'n': xbsd_add_part (cxt, 0, 0); |