summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2013-11-27 14:33:01 +0100
committerKarel Zak2014-03-11 11:35:12 +0100
commitd6faa8e00d76bf54ee4c267354f940e7d11a1a99 (patch)
tree84b92d250ace4a68685de69df435786a52d554e7
parentlibfdisk: (bsd) use new get_part() API (diff)
downloadkernel-qcow2-util-linux-d6faa8e00d76bf54ee4c267354f940e7d11a1a99.tar.gz
kernel-qcow2-util-linux-d6faa8e00d76bf54ee4c267354f940e7d11a1a99.tar.xz
kernel-qcow2-util-linux-d6faa8e00d76bf54ee4c267354f940e7d11a1a99.zip
libfdisk: add new list() columns, cleanup
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--libfdisk/src/bsd.c2
-rw-r--r--libfdisk/src/fdiskP.h13
-rw-r--r--libfdisk/src/gpt.c12
-rw-r--r--libfdisk/src/label.c24
-rw-r--r--libfdisk/src/libfdisk.h19
-rw-r--r--libfdisk/src/partition.c18
6 files changed, 67 insertions, 21 deletions
diff --git a/libfdisk/src/bsd.c b/libfdisk/src/bsd.c
index ca1510264..94833c7ef 100644
--- a/libfdisk/src/bsd.c
+++ b/libfdisk/src/bsd.c
@@ -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 }
diff --git a/libfdisk/src/fdiskP.h b/libfdisk/src/fdiskP.h
index 152e88b5f..a948fb571 100644
--- a/libfdisk/src/fdiskP.h
+++ b/libfdisk/src/fdiskP.h
@@ -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() */
};
/*
diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c
index 8d808de05..cee9cb9f0 100644
--- a/libfdisk/src/gpt.c
+++ b/libfdisk/src/gpt.c
@@ -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 }
};
/*
diff --git a/libfdisk/src/label.c b/libfdisk/src/label.c
index b7c2964c0..0ed7e4ec9 100644
--- a/libfdisk/src/label.c
+++ b/libfdisk/src/label.c
@@ -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 */
diff --git a/libfdisk/src/libfdisk.h b/libfdisk/src/libfdisk.h
index 84b94e883..7f84c3ebf 100644
--- a/libfdisk/src/libfdisk.h
+++ b/libfdisk/src/libfdisk.h
@@ -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);
diff --git a/libfdisk/src/partition.c b/libfdisk/src/partition.c
index 12ac435fa..b7a63a5e6 100644
--- a/libfdisk/src/partition.c
+++ b/libfdisk/src/partition.c
@@ -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;
}