fdisk: fix list types

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2013-04-18 14:38:49 +02:00
parent f67c524e59
commit 76f17cf260
1 changed files with 22 additions and 13 deletions

View File

@ -192,21 +192,24 @@ void print_menu(struct fdisk_context *cxt, enum menutype menu)
void list_partition_types(struct fdisk_context *cxt) void list_partition_types(struct fdisk_context *cxt)
{ {
struct fdisk_parttype *types; struct fdisk_parttype *types;
int i; size_t ntypes = 0;
if (!cxt || !cxt->label || !cxt->label->parttypes) if (!cxt || !cxt->label || !cxt->label->parttypes)
return; return;
types = cxt->label->parttypes; types = cxt->label->parttypes;
ntypes = cxt->label->nparttypes;
if (types[0].typestr == NULL) { if (types[0].typestr == NULL) {
/* /*
* Prints in 4 columns in format <hex> <name> * Prints in 4 columns in format <hex> <name>
*/ */
unsigned int last[4], done = 0, next = 0, size; size_t last[4], done = 0, next = 0, size;
int i;
for (i = 0; types[i].name; i++); size = ntypes;
size = i; if (types[ntypes - 1].name == NULL)
size--;
for (i = 3; i >= 0; i--) for (i = 3; i >= 0; i--)
last[3 - i] = done += (size + i - done) / (i + 1); last[3 - i] = done += (size + i - done) / (i + 1);
@ -219,6 +222,7 @@ void list_partition_types(struct fdisk_context *cxt)
struct fdisk_parttype *t = &types[next]; struct fdisk_parttype *t = &types[next];
size_t ret; size_t ret;
if (t->name) {
printf("%c%2x ", i ? ' ' : '\n', t->type); printf("%c%2x ", i ? ' ' : '\n', t->type);
ret = mbsalign(_(t->name), name, sizeof(name), ret = mbsalign(_(t->name), name, sizeof(name),
&width, MBS_ALIGN_LEFT, 0); &width, MBS_ALIGN_LEFT, 0);
@ -227,6 +231,7 @@ void list_partition_types(struct fdisk_context *cxt)
printf("%-15.15s", _(t->name)); printf("%-15.15s", _(t->name));
else else
fputs(name, stdout); fputs(name, stdout);
}
next = last[i++] + done; next = last[i++] + done;
if (i > 3 || next >= last[i]) { if (i > 3 || next >= last[i]) {
@ -240,9 +245,13 @@ void list_partition_types(struct fdisk_context *cxt)
* Prints 1 column in format <idx> <name> <typestr> * Prints 1 column in format <idx> <name> <typestr>
*/ */
struct fdisk_parttype *t; struct fdisk_parttype *t;
size_t i;
for (i = 0, t = types; t->name; t++, i++) for (i = 0, t = types; t && i < ntypes; t++, i++) {
printf("%3d %-30s %s\n", i + 1, t->name, t->typestr); if (t->name)
printf("%3zu %-30s %s\n", i + 1,
t->name, t->typestr);
}
} }
putchar('\n'); putchar('\n');
} }