]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: add new list() columns, cleanup
authorKarel Zak <kzak@redhat.com>
Wed, 27 Nov 2013 13:33:01 +0000 (14:33 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 11 Mar 2014 10:35:12 +0000 (11:35 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/bsd.c
libfdisk/src/fdiskP.h
libfdisk/src/gpt.c
libfdisk/src/label.c
libfdisk/src/libfdisk.h
libfdisk/src/partition.c

index ca15102648682e3019c2d6c49b44a0f3a2e85c00..94833c7ef11d4b28511d0538fd887684962b42d3 100644 (file)
@@ -866,13 +866,11 @@ static const struct fdisk_label_operations bsd_operations =
 
 static const struct fdisk_column bsd_columns[] =
 {
-       /* basic */
        { FDISK_COL_DEVICE,     N_("Slice"),      1,    0 },
        { FDISK_COL_START,      N_("Start"),      9,    TT_FL_RIGHT },
        { FDISK_COL_END,        N_("End"),        9,    TT_FL_RIGHT },
        { FDISK_COL_SIZE,       N_("Size"),       9,    TT_FL_RIGHT },
        { FDISK_COL_TYPE,       N_("Type"),       8,    0 },
-       /* expert */
        { FDISK_COL_FSIZE,      N_("Fsize"),      5,    TT_FL_RIGHT },
        { FDISK_COL_BSIZE,      N_("Bsize"),      5,    TT_FL_RIGHT },
        { FDISK_COL_CPG,        N_("Cpg"),        5,    TT_FL_RIGHT }
index 152e88b5f47439d38ca16560ee644f0295f1b5a4..a948fb571a2a5ab703b69d7d3b3e69719a85f862 100644 (file)
@@ -149,6 +149,9 @@ struct fdisk_partition {
        uint64_t        bsize;
        uint64_t        cpg;
 
+       char            boot;
+       char            *start_addr;
+       char            *end_addr;
 
        unsigned int    nested : 1,             /* logical partition */
                        used   : 1,             /* partition used */
@@ -229,9 +232,15 @@ struct fdisk_column {
        int             id;             /* FDISK_COL_* */
        const char      *name;          /* column header */
        double          width;
-       int             flags;          /* TT_FL_* */
+       int             tt_flags;       /* TT_FL_* */
 
-       unsigned int    detail;         /* if fdisk_context_display_details() */
+       int             flags;          /* FDISK_COLFL_* */
+};
+
+/* note that the defauls is to display a column always */
+enum {
+       FDISK_COLFL_DETAIL      = (1 << 1),     /* only display if fdisk_context_display_details() */
+       FDISK_COLFL_EYECANDY    = (1 << 2),     /* don't display if fdisk_context_display_details() */
 };
 
 /*
index 8d808de05599cb771ea98d57edbd1d247d9f874e..cee9cb9f006bf4eb1fc1129ce70351935ec20ad7 100644 (file)
@@ -2255,12 +2255,14 @@ static const struct fdisk_column gpt_columns[] =
        { FDISK_COL_DEVICE,     N_("Device"),    10,    0 },
        { FDISK_COL_START,      N_("Start"),      5,    TT_FL_RIGHT },
        { FDISK_COL_END,        N_("End"),        5,    TT_FL_RIGHT },
-       { FDISK_COL_SIZE,       N_("Size"),       5,    TT_FL_RIGHT },
-       { FDISK_COL_TYPE,       N_("Type"),     0.1,    TT_FL_TRUNC },
+       { FDISK_COL_SECTORS,    N_("Sectors"),    5,    TT_FL_RIGHT },
+       { FDISK_COL_SIZE,       N_("Size"),       5,    TT_FL_RIGHT, FDISK_COLFL_EYECANDY },
+       { FDISK_COL_TYPE,       N_("Type"),     0.1,    TT_FL_TRUNC, FDISK_COLFL_EYECANDY },
        /* expert */
-       { FDISK_COL_UUID,       N_("UUID"),      36,    0,           1 },
-       { FDISK_COL_NAME,       N_("Name"),     0.2,    TT_FL_TRUNC, 1 },
-       { FDISK_COL_ATTR,       N_("Attributes"), 0,    0,           1 }
+       { FDISK_COL_TYPEID,     N_("Type-UUID"), 36,    0,           FDISK_COLFL_DETAIL },
+       { FDISK_COL_UUID,       N_("UUID"),      36,    0,           FDISK_COLFL_DETAIL },
+       { FDISK_COL_NAME,       N_("Name"),     0.2,    TT_FL_TRUNC, FDISK_COLFL_DETAIL },
+       { FDISK_COL_ATTR,       N_("Attrs"),      0,    0,           FDISK_COLFL_DETAIL }
 };
 
 /*
index b7c2964c0211806e4cff884f8b714b112d8c687f..0ed7e4ec9acf33d9d1271379e7c0a759b591a4f8 100644 (file)
@@ -110,12 +110,19 @@ int fdisk_missing_geometry(struct fdisk_context *cxt)
 /**
  * fdisk_get_columns:
  * @cxt: fdisk context
- * @cols: returns allocated array with FDISK_COL_*
+ * @all: 1 or 0
+ * @cols: returns allocated array with FDISK_COL_* IDs
  * @ncols: returns number of items in cols
  *
+ * This function returns the default or all columns for the current label.  The
+ * library uses the columns for list operations (see fdisk_list_disklabel() and
+ * fdisk_list_partitions()). Note that the set of the default columns depends
+ * on fdisk_context_enable_details() function. If the details are eanable then
+ * this function usually returns more columns.
+ *
  * Returns 0 on success, otherwise, a corresponding error.
  */
-int fdisk_get_columns(struct fdisk_context *cxt, int **cols, size_t *ncols)
+int fdisk_get_columns(struct fdisk_context *cxt, int all, int **cols, size_t *ncols)
 {
        size_t i, n;
        int *c;
@@ -130,8 +137,11 @@ int fdisk_get_columns(struct fdisk_context *cxt, int **cols, size_t *ncols)
        if (!c)
                return -ENOMEM;
        for (n = 0, i = 0; i < cxt->label->ncolumns; i++) {
-               if (cxt->label->columns[i].detail
-                   && !fdisk_context_display_details(cxt))
+               if (!all &&
+                   ((fdisk_context_display_details(cxt) &&
+                               (cxt->label->columns[i].flags & FDISK_COLFL_EYECANDY))
+                    || (!fdisk_context_display_details(cxt) &&
+                               (cxt->label->columns[i].flags & FDISK_COLFL_DETAIL))))
                        continue;
                c[n++] = cxt->label->columns[i].id;
        }
@@ -253,7 +263,7 @@ int fdisk_list_disklabel(struct fdisk_context *cxt)
  * only partitons by FDISK_ASKTYPE_TABLE interface.
  *
  * If no @cols are specified then the default is printed (see
- * fdisk_label_get_columns() for the default columns).
+ * fdisk_get_columns() for the default columns).
 
  * Returns 0 on success, otherwise, a corresponding error.
  */
@@ -274,7 +284,7 @@ int fdisk_list_partitions(struct fdisk_context *cxt, int *cols, size_t ncols)
        DBG(LABEL, dbgprint("list partitions"));
 
        if (!cols || !ncols) {
-               rc = fdisk_get_columns(cxt, &cols, &ncols);
+               rc = fdisk_get_columns(cxt, 0, &cols, &ncols);
                if (rc)
                        return rc;
        }
@@ -295,7 +305,7 @@ int fdisk_list_partitions(struct fdisk_context *cxt, int *cols, size_t ncols)
                col = fdisk_label_get_column(cxt->label, cols[j]);
                if (!col)
                        continue;
-               tt_define_column(tb, col->name, col->width, col->flags);
+               tt_define_column(tb, col->name, col->width, col->tt_flags);
        }
 
        /* generate per-partition lines into table */
index 84b94e883f6107531f988a6f2cac1d7062cc584e..7f84c3ebf89dc6065aa76a6ec81445b18c68e8ef 100644 (file)
@@ -114,17 +114,26 @@ extern int fdisk_is_parttype_string(struct fdisk_context *cxt);
 /* label.c */
 enum {
        FDISK_COL_NONE = 0,
+
+       /* generic */
        FDISK_COL_DEVICE,
        FDISK_COL_START,
        FDISK_COL_END,
+       FDISK_COL_SECTORS,
        FDISK_COL_SIZE,
        FDISK_COL_TYPE,
-       FDISK_COL_UUID,
-       FDISK_COL_NAME,
+       FDISK_COL_TYPEID,
+
+       /* label specific */
        FDISK_COL_ATTR,
-       FDISK_COL_FSIZE,
+       FDISK_COL_BOOT,
        FDISK_COL_BSIZE,
-       FDISK_COL_CPG
+       FDISK_COL_CPG,
+       FDISK_COL_EADDR,
+       FDISK_COL_FSIZE,
+       FDISK_COL_NAME,
+       FDISK_COL_SADDR,
+       FDISK_COL_UUID,
 };
 
 extern int fdisk_require_geometry(struct fdisk_context *cxt);
@@ -153,7 +162,7 @@ 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_get_columns(struct fdisk_context *cxt, int all, 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);
index 12ac435fa9b791d5994dd030765d98a0ddff1d68..b7a63a5e62903867e8fb978442901cf90fadac14 100644 (file)
@@ -208,6 +208,9 @@ int fdisk_partition_to_string(struct fdisk_partition *pa,
                else
                        p = fdisk_partname(pa->cxt->dev_path, pa->partno + 1);
                break;
+       case FDISK_COL_BOOT:
+               rc = asprintf(&p, "%c", pa->boot);
+               break;
        case FDISK_COL_START:
                rc = pa->start_post ?
                                asprintf(&p, "%ju%c", pa->start, pa->start_post) :
@@ -229,6 +232,9 @@ int fdisk_partition_to_string(struct fdisk_partition *pa,
                                rc = -ENOMEM;
                }
                break;
+       case FDISK_COL_SECTORS:
+               rc = asprintf(&p, "%ju", pa->size / pa->cxt->sector_size);
+               break;
        case FDISK_COL_BSIZE:
                rc = asprintf(&p, "%ju", pa->bsize);
                break;
@@ -241,6 +247,12 @@ int fdisk_partition_to_string(struct fdisk_partition *pa,
        case FDISK_COL_TYPE:
                p = pa->type && pa->type->name ? strdup(pa->type->name) : NULL;
                break;
+       case FDISK_COL_TYPEID:
+               if (pa->type && pa->type->typestr)
+                       rc = asprintf(&p, "%s", pa->type->typestr);
+               else if (pa->type)
+                       rc = asprintf(&p, "%x", pa->type->type);
+               break;
        case FDISK_COL_UUID:
                p = pa->uuid ? strdup(pa->uuid) : NULL;
                break;
@@ -250,6 +262,12 @@ int fdisk_partition_to_string(struct fdisk_partition *pa,
        case FDISK_COL_ATTR:
                p = pa->attrs ? strdup(pa->attrs) : NULL;
                break;
+       case FDISK_COL_SADDR:
+               p = pa->start_addr ? strdup(pa->start_addr) : NULL;
+               break;
+       case FDISK_COL_EADDR:
+               p = pa->end_addr ? strdup(pa->end_addr) : NULL;
+               break;
        default:
                return -EINVAL;
        }