]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: extend API definition to list info about partitions
authorKarel Zak <kzak@redhat.com>
Fri, 22 Nov 2013 09:08:37 +0000 (10:08 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 11 Mar 2014 10:35:12 +0000 (11:35 +0100)
This change adds a struct fdisk_column to provide generic description
for information about partitions. The struct is used for tt tables as
well as lists of possible columns for specified label driver.

We use the same concept in all applications linked with tt.c (lsblk,
findmnt, partx, ...) where is possible to dynamically change columns,
order of the columns etc. Now it will be possible to do the same with
fdisk.

And it's also possible to use FDISK_COL_* Ids to address data, for
example:

   fdisk_partition_get_data(cxt, FDISK_COL_SIZE, 1, &data);

returns a string with human readable size (<num>{MGT}) of the second
partition.

Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/fdiskP.h
libfdisk/src/libfdisk.h

index feaab3d0aca5b20c585875c495eeb1c5c5f850a6..8c780faeb4101853cb01ce4cc2f43e4dce560230 100644 (file)
@@ -176,6 +176,12 @@ struct fdisk_label_operations {
                                                size_t partnum,
                                                int *status);
 
+       /* get data according to id (FDISK_COL_*) */
+       int (*part_get_data)(struct fdisk_context *cxt,
+                                               int id,
+                                               size_t n,
+                                               char **data);
+
        int (*part_toggle_flag)(struct fdisk_context *cxt, size_t i, unsigned long flag);
 
        /* refresh alignment setting */
@@ -188,6 +194,18 @@ struct fdisk_label_operations {
        void (*deinit)(struct fdisk_label *lb);
 };
 
+/*
+ * fdisk_label_operations->list() output column
+ */
+struct fdisk_column {
+       int             id;             /* FDISK_COL_* */
+       const char      *name;          /* column header */
+       double          width;
+       int             flags;          /* TT_FL_* */
+
+       unsigned int    detail;         /* if fdisk_context_display_details() */
+};
+
 /*
  * Generic label
  */
@@ -205,9 +223,13 @@ struct fdisk_label {
        unsigned int            changed:1,      /* label has been modified */
                                disabled:1;     /* this driver is disabled at all */
 
+       const struct fdisk_column *columns;     /* all possible columns */
+       size_t                  ncolumns;
+
        const struct fdisk_label_operations *op;
 };
 
+
 /* label driver flags */
 enum {
        FDISK_LABEL_FL_ADDPART_NOPARTNO = (1 << 1),
index f653b48b1f0816f3b35c9d778b2ad026a78f121d..b0ce5c00f674706b006b5ef6ecf3f26c263c4285 100644 (file)
@@ -116,6 +116,18 @@ extern size_t fdisk_get_nparttypes(struct fdisk_context *cxt);
 extern int fdisk_is_parttype_string(struct fdisk_context *cxt);
 
 /* label.c */
+enum {
+       FDISK_COL_NONE = 0,
+       FDISK_COL_DEVICE,
+       FDISK_COL_START,
+       FDISK_COL_END,
+       FDISK_COL_SIZE,
+       FDISK_COL_TYPE,
+       FDISK_COL_UUID,
+       FDISK_COL_NAME,
+       FDISK_COL_ATTR
+};
+
 extern int fdisk_require_geometry(struct fdisk_context *cxt);
 extern int fdisk_missing_geometry(struct fdisk_context *cxt);
 
@@ -132,6 +144,7 @@ extern int fdisk_locate_disklabel(struct fdisk_context *cxt, int n, const char *
 
 extern int fdisk_get_disklabel_id(struct fdisk_context *cxt, char **id);
 extern int fdisk_set_disklabel_id(struct fdisk_context *cxt);
+extern int fdisk_partition_get_data(struct fdisk_context *cxt, int id, size_t partnum, char **data);
 
 extern int fdisk_add_partition(struct fdisk_context *cxt, struct fdisk_parttype *t);
 extern int fdisk_delete_partition(struct fdisk_context *cxt, size_t partnum);
@@ -140,6 +153,9 @@ extern struct fdisk_parttype *fdisk_get_partition_type(struct fdisk_context *cxt
 extern int fdisk_set_partition_type(struct fdisk_context *cxt, size_t partnum,
                             struct fdisk_parttype *t);
 
+extern int fdisk_get_columns(struct fdisk_context *cxt, int **cols, size_t *ncols);
+extern int fdisk_list_partitions(struct fdisk_context *cxt, int *cols, size_t ncols);
+
 extern void fdisk_label_set_changed(struct fdisk_label *lb, int changed);
 extern int fdisk_label_is_changed(struct fdisk_label *lb);