summaryrefslogtreecommitdiffstats
path: root/disk-utils/fdisk-list.c
diff options
context:
space:
mode:
authorKarel Zak2014-10-09 12:03:32 +0200
committerKarel Zak2014-10-09 12:03:32 +0200
commit6d812a4859326b6f6d3ba214f117d759b35b181a (patch)
tree91078a04b84251b71e04dbecf0105bbdfe3d0b36 /disk-utils/fdisk-list.c
parentlibfdisk: allow to specify partition size by explicit number of sectors (diff)
downloadkernel-qcow2-util-linux-6d812a4859326b6f6d3ba214f117d759b35b181a.tar.gz
kernel-qcow2-util-linux-6d812a4859326b6f6d3ba214f117d759b35b181a.tar.xz
kernel-qcow2-util-linux-6d812a4859326b6f6d3ba214f117d759b35b181a.zip
fdisk: reset cached output fields when change disk label
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils/fdisk-list.c')
-rw-r--r--disk-utils/fdisk-list.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/disk-utils/fdisk-list.c b/disk-utils/fdisk-list.c
index 67b03ad8e..46d50a7f3 100644
--- a/disk-utils/fdisk-list.c
+++ b/disk-utils/fdisk-list.c
@@ -128,7 +128,7 @@ void list_disklabel(struct fdisk_context *cxt)
const struct fdisk_field *field =
fdisk_label_get_field(lb, ids[i]);
if (!field)
- goto done;
+ continue;
if (fdisk_field_is_number(field))
fl |= SCOLS_FL_RIGHT;
if (fdisk_field_get_id(field) == FDISK_FIELD_TYPE)
@@ -335,16 +335,26 @@ static int fieldname_to_id(const char *name, size_t namesz)
int *init_fields(struct fdisk_context *cxt, const char *str, size_t *n)
{
int *dflt_ids = NULL;
+ struct fdisk_label *lb;
if (!fields_string)
fields_string = str;
+ if (!cxt)
+ goto done;
- if (!cxt || fields_nids)
- goto done;
+ lb = fdisk_get_label(cxt, NULL);
+
+ if (!lb || fields_label != lb) { /* label changed: reset */
+ free(fields_ids);
+ fields_ids = NULL;
+ fields_label = lb;
+ fields_nids = 0;
+ }
- fields_label = fdisk_get_label(cxt, NULL);
- if (!fields_label)
+ if (!fields_label) /* no label */
goto done;
+ if (fields_nids)
+ goto done; /* already initialized */
/* library default */
if (fdisk_label_get_fields_ids(NULL, cxt, &dflt_ids, &fields_nids))