]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: make it possible to get fields for all labes
authorKarel Zak <kzak@redhat.com>
Wed, 13 Aug 2014 22:27:28 +0000 (00:27 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 13 Aug 2014 22:27:28 +0000 (00:27 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/cfdisk.c
disk-utils/fdisk.c
libfdisk/src/label.c
libfdisk/src/libfdisk.h

index 7f02c0625690895ea0a1a2e140580ebb1f013c2c..b86b609efbd866f009419241649a6b000398b9dd 100644 (file)
@@ -212,7 +212,7 @@ static int cols_init(struct cfdisk *cf)
        cf->fields = NULL;
        cf->nfields = 0;
 
-       return fdisk_get_fields_ids(cf->cxt, 0, &cf->fields, &cf->nfields);
+       return fdisk_label_get_fields_ids(NULL, cf->cxt, &cf->fields, &cf->nfields);
 }
 
 static void resize(void)
index 4a9262905fa8ed4d2b734080fd7e2c8724675f23..ed008e703894ca474e3b0480b315e0917a8d7482 100644 (file)
@@ -554,7 +554,7 @@ void list_disklabel(struct fdisk_context *cxt)
        if (fdisk_get_partitions(cxt, &tb) || fdisk_table_get_nents(tb) <= 0)
                goto done;
 
-       if (fdisk_get_fields_ids(cxt, 0, &ids, &nids))
+       if (fdisk_label_get_fields_ids(NULL, cxt, &ids, &nids))
                goto done;
 
        itr = fdisk_new_iter(FDISK_ITER_FORWARD);
index c69bc170a150d37c079ee32ebb65ed4fe9e13429..186ffba6b5b9d407748f736e395aaeedbadaff26 100644 (file)
@@ -66,66 +66,50 @@ int fdisk_label_require_geometry(struct fdisk_label *lb)
        return lb->flags & FDISK_LABEL_FL_REQUIRE_GEOMETRY ? 1 : 0;
 }
 
-
 /**
- * fdisk_write_disklabel:
- * @cxt: fdisk context
- *
- * Write in-memory changes to disk
- *
- * Returns 0 on success, otherwise, a corresponding error.
- */
-int fdisk_write_disklabel(struct fdisk_context *cxt)
-{
-       if (!cxt || !cxt->label || cxt->readonly)
-               return -EINVAL;
-       if (!cxt->label->op->write)
-               return -ENOSYS;
-       return cxt->label->op->write(cxt);
-}
-
-
-/**
- * fdisk_get_fields:
- * @cxt: fdisk context
- * @all: 1 or 0
+ * fdisk_label_get_fields_ids
+ * @lb: label (or NULL for the current label)
  * @ids: returns allocated array with FDISK_FIELD_* IDs
  * @nids: returns number of items in fields
  *
- * This function returns the default or all fields for the current label.
- * Note that the set of the default fields depends on
- * fdisk_enable_details() function. If the details are enabled then
- * this function usually returns more fields.
+ * This function returns the default fields for the label.
+ *
+ * Note that the set of the default fields depends on fdisk_enable_details()
+ * function. If the details are enabled then this function usually returns more
+ * fields.
  *
  * Returns 0 on success, otherwise, a corresponding error.
  */
-int fdisk_get_fields_ids(struct fdisk_context *cxt, int all,
-                        int **ids, size_t *nids)
+int fdisk_label_get_fields_ids(
+               struct fdisk_label *lb,
+               struct fdisk_context *cxt,
+               int **ids, size_t *nids)
 {
        size_t i, n;
        int *c;
 
        assert(cxt);
 
-       if (!cxt->label)
+       if (!lb)
+               lb = cxt->label;
+       if (!lb)
                return -EINVAL;
-       if (!cxt->label->fields || !cxt->label->nfields)
+       if (!lb->fields || !lb->nfields)
                return -ENOSYS;
-       c = calloc(cxt->label->nfields, sizeof(int));
+       c = calloc(lb->nfields, sizeof(int));
        if (!c)
                return -ENOMEM;
-       for (n = 0, i = 0; i < cxt->label->nfields; i++) {
-               int id = cxt->label->fields[i].id;
+       for (n = 0, i = 0; i < lb->nfields; i++) {
+               int id = lb->fields[i].id;
 
-               if (!all &&
-                   ((fdisk_is_details(cxt) &&
-                               (cxt->label->fields[i].flags & FDISK_FIELDFL_EYECANDY))
+               if ((fdisk_is_details(cxt) &&
+                               (lb->fields[i].flags & FDISK_FIELDFL_EYECANDY))
                     || (!fdisk_is_details(cxt) &&
-                               (cxt->label->fields[i].flags & FDISK_FIELDFL_DETAIL))
+                               (lb->fields[i].flags & FDISK_FIELDFL_DETAIL))
                     || (id == FDISK_FIELD_SECTORS &&
                                 fdisk_use_cylinders(cxt))
                     || (id == FDISK_FIELD_CYLINDERS &&
-                                !fdisk_use_cylinders(cxt))))
+                                !fdisk_use_cylinders(cxt)))
                        continue;
 
                c[n++] = id;
@@ -174,6 +158,26 @@ int fdisk_field_is_number(const struct fdisk_field *field)
        return field->flags ? field->flags & FDISK_FIELDFL_NUMBER : 0;
 }
 
+
+/**
+ * fdisk_write_disklabel:
+ * @cxt: fdisk context
+ *
+ * Write in-memory changes to disk
+ *
+ * Returns 0 on success, otherwise, a corresponding error.
+ */
+int fdisk_write_disklabel(struct fdisk_context *cxt)
+{
+       if (!cxt || !cxt->label || cxt->readonly)
+               return -EINVAL;
+       if (!cxt->label->op->write)
+               return -ENOSYS;
+       return cxt->label->op->write(cxt);
+}
+
+
+
 /**
  * fdisk_verify_disklabel:
  * @cxt: fdisk context
index 1db04b7796053cb15437ce794d3fe48017c732fb..3d9d58efd473e3807533ec90a5d7c9e7073039ef 100644 (file)
@@ -181,8 +181,10 @@ extern int fdisk_set_partition_type(struct fdisk_context *cxt, size_t partnum,
                             struct fdisk_parttype *t);
 
 
-extern int fdisk_get_fields_ids(struct fdisk_context *cxt, int all,
-                               int **ids, size_t *nids);
+extern int fdisk_label_get_fields_ids(
+                       struct fdisk_label *lb,
+                       struct fdisk_context *cxt,
+                       int **ids, size_t *nids);
 extern const struct fdisk_field *fdisk_label_get_field(struct fdisk_label *lb, int id);
 
 extern int fdisk_field_get_id(const struct fdisk_field *fl);