From bd85d11fbadfbf1b60e2dcfec5e12ad929641996 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 13 Aug 2014 11:12:27 +0200 Subject: [PATCH] libfdisk: rename fdisk_column to fdisk_field .. to make the API and fdisk(s) code more readable. Signed-off-by: Karel Zak --- disk-utils/cfdisk.c | 60 ++++++++++++++++++------------------- disk-utils/fdisk.c | 33 +++++++++------------ libfdisk/src/bsd.c | 26 ++++++++-------- libfdisk/src/dos.c | 30 +++++++++---------- libfdisk/src/fdiskP.h | 24 +++++++-------- libfdisk/src/gpt.c | 28 +++++++++--------- libfdisk/src/label.c | 64 ++++++++++++++++++++-------------------- libfdisk/src/libfdisk.h | 52 +++++++++++++++++--------------- libfdisk/src/partition.c | 38 ++++++++++++------------ libfdisk/src/sgi.c | 24 +++++++-------- libfdisk/src/sun.c | 25 ++++++++-------- 11 files changed, 199 insertions(+), 205 deletions(-) diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c index 453eafab0a..93331ebd7b 100644 --- a/disk-utils/cfdisk.c +++ b/disk-utils/cfdisk.c @@ -162,8 +162,8 @@ struct cfdisk { struct fdisk_table *table; /* partition table */ struct cfdisk_menu *menu; /* the current menu */ - int *cols; /* output columns */ - size_t ncols; /* number of columns */ + int *fields; /* output columns IDs */ + size_t nfields; /* number of columns IDs */ char *linesbuf; /* table as string */ size_t linesbufsz; /* size of the tb_buf */ @@ -179,18 +179,18 @@ struct cfdisk { zero_start :1; /* ignore existing partition table */ }; -/* Initialize output columns -- we follow libcfdisk columns (usually specific +/* Initialize output columns -- we follow libfdisk fields (usually specific * to the label type. */ static int cols_init(struct cfdisk *cf) { assert(cf); - free(cf->cols); - cf->cols = NULL; - cf->ncols = 0; + free(cf->fields); + cf->fields = NULL; + cf->nfields = 0; - return fdisk_get_columns(cf->cxt, 0, &cf->cols, &cf->ncols); + return fdisk_get_fields_ids(cf->cxt, 0, &cf->fields, &cf->nfields); } static void resize(void) @@ -237,7 +237,6 @@ static int partition_from_scols(struct fdisk_table *tb, static char *table_to_string(struct cfdisk *cf, struct fdisk_table *tb) { - const struct fdisk_column *col; struct fdisk_partition *pa; struct fdisk_label *lb; struct fdisk_iter *itr = NULL; @@ -252,7 +251,7 @@ static char *table_to_string(struct cfdisk *cf, struct fdisk_table *tb) assert(cf); assert(cf->cxt); - assert(cf->cols); + assert(cf->fields); assert(tb); lb = fdisk_context_get_label(cf->cxt, NULL); @@ -277,23 +276,24 @@ static char *table_to_string(struct cfdisk *cf, struct fdisk_table *tb) scols_table_enable_maxout(table, 1); /* headers */ - for (i = 0; i < cf->ncols; i++) { - col = fdisk_label_get_column(lb, cf->cols[i]); - if (col) { - int fl = 0; - - if (fdisk_column_is_number(col)) - fl |= SCOLS_FL_RIGHT; - if (fdisk_column_get_id(col) == FDISK_COL_TYPE) - fl |= SCOLS_FL_TRUNC; - if (tree && fdisk_column_get_id(col) == FDISK_COL_DEVICE) - fl |= SCOLS_FL_TREE; - - if (!scols_table_new_column(table, - fdisk_column_get_name(col), - fdisk_column_get_width(col), fl)) - goto done; - } + for (i = 0; i < cf->nfields; i++) { + int fl = 0; + const struct fdisk_field *field = + fdisk_label_get_field(lb, cf->fields[i]); + if (!field) + continue; + + if (fdisk_field_is_number(field)) + fl |= SCOLS_FL_RIGHT; + if (fdisk_field_get_id(field) == FDISK_FIELD_TYPE) + fl |= SCOLS_FL_TRUNC; + if (tree && fdisk_field_get_id(field) == FDISK_FIELD_DEVICE) + fl |= SCOLS_FL_TREE; + + if (!scols_table_new_column(table, + fdisk_field_get_name(field), + fdisk_field_get_width(field), fl)) + goto done; } /* data */ @@ -305,13 +305,11 @@ static char *table_to_string(struct cfdisk *cf, struct fdisk_table *tb) ln = scols_table_new_line(table, parent); if (!ln) goto done; - for (i = 0; i < cf->ncols; i++) { + for (i = 0; i < cf->nfields; i++) { char *cdata = NULL; - col = fdisk_label_get_column(lb, cf->cols[i]); - if (!col) - continue; + if (fdisk_partition_to_string(pa, cf->cxt, - fdisk_column_get_id(col), &cdata)) + cf->fields[i], &cdata)) continue; scols_line_refer_data(ln, i, cdata); } diff --git a/disk-utils/fdisk.c b/disk-utils/fdisk.c index 1e6b45d3c0..1dd7ed8a90 100644 --- a/disk-utils/fdisk.c +++ b/disk-utils/fdisk.c @@ -543,8 +543,8 @@ void list_disklabel(struct fdisk_context *cxt) struct fdisk_iter *itr = NULL; struct libscols_table *out = NULL; const char *bold = NULL; - int *cols = NULL; - size_t ncols = 0, i; + int *ids = NULL; /* IDs of fdisk_fields */ + size_t nids = 0, i; /* print label specific stuff by libfdisk FDISK_ASK_INFO API */ fdisk_list_disklabel(cxt); @@ -553,7 +553,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_columns(cxt, 0, &cols, &ncols)) + if (fdisk_get_fields_ids(cxt, 0, &ids, &nids)) goto done; itr = fdisk_new_iter(FDISK_ITER_FORWARD); @@ -574,21 +574,21 @@ void list_disklabel(struct fdisk_context *cxt) } /* define output table columns */ - for (i = 0; i < ncols; i++) { + for (i = 0; i < nids; i++) { int fl = 0; struct libscols_column *co; - const struct fdisk_column *col = - fdisk_label_get_column(cxt->label, cols[i]); - if (!col) + const struct fdisk_field *field = + fdisk_label_get_field(cxt->label, ids[i]); + if (!field) goto done; - if (fdisk_column_is_number(col)) + if (fdisk_field_is_number(field)) fl |= SCOLS_FL_RIGHT; - if (fdisk_column_get_id(col) == FDISK_COL_TYPE) + if (fdisk_field_get_id(field) == FDISK_FIELD_TYPE) fl |= SCOLS_FL_TRUNC; co = scols_table_new_column(out, - fdisk_column_get_name(col), - fdisk_column_get_width(col), fl); + fdisk_field_get_name(field), + fdisk_field_get_width(field), fl); if (!co) goto done; @@ -606,15 +606,10 @@ void list_disklabel(struct fdisk_context *cxt) goto done; } - for (i = 0; i < ncols; i++) { + for (i = 0; i < nids; i++) { char *data = NULL; - const struct fdisk_column *col = - fdisk_label_get_column(cxt->label, cols[i]); - - if (fdisk_partition_to_string(pa, cxt, - fdisk_column_get_id(col), - &data)) + if (fdisk_partition_to_string(pa, cxt, ids[i], &data)) continue; scols_line_refer_data(ln, i, data); } @@ -637,7 +632,7 @@ void list_disklabel(struct fdisk_context *cxt) if (fdisk_table_wrong_order(tb)) fdisk_info(cxt, _("Partition table entries are not in disk order.")); done: - free(cols); + free(ids); scols_unref_table(out); fdisk_unref_table(tb); fdisk_free_iter(itr); diff --git a/libfdisk/src/bsd.c b/libfdisk/src/bsd.c index d6dc4b7f95..e00cec5fdc 100644 --- a/libfdisk/src/bsd.c +++ b/libfdisk/src/bsd.c @@ -878,18 +878,18 @@ static const struct fdisk_label_operations bsd_operations = .part_is_used = bsd_partition_is_used, }; -static const struct fdisk_column bsd_columns[] = +static const struct fdisk_field bsd_fields[] = { - { FDISK_COL_DEVICE, N_("Slice"), 1, 0 }, - { FDISK_COL_START, N_("Start"), 5, FDISK_COLFL_NUMBER }, - { FDISK_COL_END, N_("End"), 5, FDISK_COLFL_NUMBER }, - { FDISK_COL_SECTORS, N_("Sectors"), 5, FDISK_COLFL_NUMBER }, - { FDISK_COL_CYLINDERS, N_("Cylinders"), 5, FDISK_COLFL_NUMBER }, - { FDISK_COL_SIZE, N_("Size"), 5, FDISK_COLFL_NUMBER }, - { FDISK_COL_TYPE, N_("Type"), 8, 0 }, - { FDISK_COL_FSIZE, N_("Fsize"), 5, FDISK_COLFL_NUMBER }, - { FDISK_COL_BSIZE, N_("Bsize"), 5, FDISK_COLFL_NUMBER }, - { FDISK_COL_CPG, N_("Cpg"), 5, FDISK_COLFL_NUMBER } + { FDISK_FIELD_DEVICE, N_("Slice"), 1, 0 }, + { FDISK_FIELD_START, N_("Start"), 5, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_END, N_("End"), 5, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_SECTORS, N_("Sectors"), 5, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_CYLINDERS,N_("Cylinders"), 5, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_SIZE, N_("Size"), 5, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_TYPE, N_("Type"), 8, 0 }, + { FDISK_FIELD_FSIZE, N_("Fsize"), 5, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_BSIZE, N_("Bsize"), 5, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_CPG, N_("Cpg"), 5, FDISK_FIELDFL_NUMBER } }; /* @@ -914,8 +914,8 @@ struct fdisk_label *fdisk_new_bsd_label(struct fdisk_context *cxt) lb->parttypes = bsd_fstypes; lb->nparttypes = ARRAY_SIZE(bsd_fstypes); - lb->columns = bsd_columns; - lb->ncolumns = ARRAY_SIZE(bsd_columns); + lb->fields = bsd_fields; + lb->nfields = ARRAY_SIZE(bsd_fields); lb->flags |= FDISK_LABEL_FL_INCHARS_PARTNO; lb->flags |= FDISK_LABEL_FL_REQUIRE_GEOMETRY; diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c index fc4ac7a801..4805102c79 100644 --- a/libfdisk/src/dos.c +++ b/libfdisk/src/dos.c @@ -1981,23 +1981,23 @@ static int dos_toggle_partition_flag( return 0; } -static const struct fdisk_column dos_columns[] = +static const struct fdisk_field dos_fields[] = { /* basic */ - { FDISK_COL_DEVICE, N_("Device"), 10, 0 }, - { FDISK_COL_BOOT, N_("Boot"), 1, 0 }, - { FDISK_COL_START, N_("Start"), 5, FDISK_COLFL_NUMBER }, - { FDISK_COL_END, N_("End"), 5, FDISK_COLFL_NUMBER }, - { FDISK_COL_SECTORS, N_("Sectors"), 5, FDISK_COLFL_NUMBER }, - { FDISK_COL_CYLINDERS, N_("Cylinders"), 5, FDISK_COLFL_NUMBER }, - { FDISK_COL_SIZE, N_("Size"), 5, FDISK_COLFL_NUMBER | FDISK_COLFL_EYECANDY }, - { FDISK_COL_TYPEID, N_("Id"), 2, FDISK_COLFL_NUMBER }, - { FDISK_COL_TYPE, N_("Type"), 0.1, 0 }, + { FDISK_FIELD_DEVICE, N_("Device"), 10, 0 }, + { FDISK_FIELD_BOOT, N_("Boot"), 1, 0 }, + { FDISK_FIELD_START, N_("Start"), 5, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_END, N_("End"), 5, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_SECTORS, N_("Sectors"), 5, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_CYLINDERS,N_("Cylinders"), 5, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_SIZE, N_("Size"), 5, FDISK_FIELDFL_NUMBER | FDISK_FIELDFL_EYECANDY }, + { FDISK_FIELD_TYPEID, N_("Id"), 2, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_TYPE, N_("Type"), 0.1, 0 }, /* expert mode */ - { FDISK_COL_SADDR, N_("Start-C/H/S"), 1, FDISK_COLFL_NUMBER | FDISK_COLFL_DETAIL }, - { FDISK_COL_EADDR, N_("End-C/H/S"), 1, FDISK_COLFL_NUMBER | FDISK_COLFL_DETAIL }, - { FDISK_COL_ATTR, N_("Attrs"), 2, FDISK_COLFL_NUMBER | FDISK_COLFL_DETAIL } + { FDISK_FIELD_SADDR, N_("Start-C/H/S"), 1, FDISK_FIELDFL_NUMBER | FDISK_FIELDFL_DETAIL }, + { FDISK_FIELD_EADDR, N_("End-C/H/S"), 1, FDISK_FIELDFL_NUMBER | FDISK_FIELDFL_DETAIL }, + { FDISK_FIELD_ATTR, N_("Attrs"), 2, FDISK_FIELDFL_NUMBER | FDISK_FIELDFL_DETAIL } }; @@ -2048,8 +2048,8 @@ struct fdisk_label *fdisk_new_dos_label(struct fdisk_context *cxt) lb->op = &dos_operations; lb->parttypes = dos_parttypes; lb->nparttypes = ARRAY_SIZE(dos_parttypes); - lb->columns = dos_columns; - lb->ncolumns = ARRAY_SIZE(dos_columns); + lb->fields = dos_fields; + lb->nfields = ARRAY_SIZE(dos_fields); return lb; } diff --git a/libfdisk/src/fdiskP.h b/libfdisk/src/fdiskP.h index 0e5f234d8f..12457eae2b 100644 --- a/libfdisk/src/fdiskP.h +++ b/libfdisk/src/fdiskP.h @@ -229,20 +229,20 @@ struct fdisk_label_operations { }; /* - * fdisk_label_operations->list() output column + * The fields describes how to display libfdisk_partition */ -struct fdisk_column { - int id; /* FDISK_COL_* */ - const char *name; /* column header */ - double width; - int flags; /* FDISK_COLFL_* */ +struct fdisk_field { + int id; /* FDISK_FIELD_* */ + const char *name; /* field name */ + double width; /* field width (compatible with libsmartcols whint) */ + int flags; /* FDISK_FIELDFL_* */ }; /* 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() */ - FDISK_COLFL_NUMBER = (1 << 3), /* column display numbers */ + FDISK_FIELDFL_DETAIL = (1 << 1), /* only display if fdisk_context_display_details() */ + FDISK_FIELDFL_EYECANDY = (1 << 2), /* don't display if fdisk_context_display_details() */ + FDISK_FIELDFL_NUMBER = (1 << 3), /* column display numbers */ }; /* @@ -262,8 +262,8 @@ 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_field *fields; /* all possible fields */ + size_t nfields; const struct fdisk_label_operations *op; }; @@ -426,8 +426,6 @@ extern char *fdisk_partname(const char *dev, size_t partno); /* label.c */ extern int fdisk_probe_labels(struct fdisk_context *cxt); extern void fdisk_deinit_label(struct fdisk_label *lb); -extern const struct fdisk_column *fdisk_label_get_column( - struct fdisk_label *lb, int id); /* ask.c */ extern int fdisk_ask_partnum(struct fdisk_context *cxt, size_t *partnum, int wantnew); diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c index 8ebb915df1..0fb5ac57ae 100644 --- a/libfdisk/src/gpt.c +++ b/libfdisk/src/gpt.c @@ -2395,21 +2395,21 @@ static const struct fdisk_label_operations gpt_operations = .reset_alignment = gpt_reset_alignment }; -static const struct fdisk_column gpt_columns[] = +static const struct fdisk_field gpt_fields[] = { /* basic */ - { FDISK_COL_DEVICE, N_("Device"), 10, 0 }, - { FDISK_COL_START, N_("Start"), 5, FDISK_COLFL_NUMBER }, - { FDISK_COL_END, N_("End"), 5, FDISK_COLFL_NUMBER }, - { FDISK_COL_SECTORS, N_("Sectors"), 5, FDISK_COLFL_NUMBER }, - { FDISK_COL_CYLINDERS, N_("Cylinders"), 5, FDISK_COLFL_NUMBER }, - { FDISK_COL_SIZE, N_("Size"), 5, FDISK_COLFL_NUMBER | FDISK_COLFL_EYECANDY }, - { FDISK_COL_TYPE, N_("Type"), 0.1, FDISK_COLFL_EYECANDY }, + { FDISK_FIELD_DEVICE, N_("Device"), 10, 0 }, + { FDISK_FIELD_START, N_("Start"), 5, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_END, N_("End"), 5, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_SECTORS, N_("Sectors"), 5, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_CYLINDERS,N_("Cylinders"), 5, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_SIZE, N_("Size"), 5, FDISK_FIELDFL_NUMBER | FDISK_FIELDFL_EYECANDY }, + { FDISK_FIELD_TYPE, N_("Type"), 0.1, FDISK_FIELDFL_EYECANDY }, /* expert */ - { FDISK_COL_TYPEID, N_("Type-UUID"), 36, FDISK_COLFL_DETAIL }, - { FDISK_COL_UUID, N_("UUID"), 36, FDISK_COLFL_DETAIL }, - { FDISK_COL_NAME, N_("Name"), 0.2, FDISK_COLFL_DETAIL }, - { FDISK_COL_ATTR, N_("Attrs"), 0, FDISK_COLFL_DETAIL } + { FDISK_FIELD_TYPEID, N_("Type-UUID"), 36, FDISK_FIELDFL_DETAIL }, + { FDISK_FIELD_UUID, N_("UUID"), 36, FDISK_FIELDFL_DETAIL }, + { FDISK_FIELD_NAME, N_("Name"), 0.2, FDISK_FIELDFL_DETAIL }, + { FDISK_FIELD_ATTR, N_("Attrs"), 0, FDISK_FIELDFL_DETAIL } }; /* @@ -2434,8 +2434,8 @@ struct fdisk_label *fdisk_new_gpt_label(struct fdisk_context *cxt) lb->parttypes = gpt_parttypes; lb->nparttypes = ARRAY_SIZE(gpt_parttypes); - lb->columns = gpt_columns; - lb->ncolumns = ARRAY_SIZE(gpt_columns); + lb->fields = gpt_fields; + lb->nfields = ARRAY_SIZE(gpt_fields); return lb; } diff --git a/libfdisk/src/label.c b/libfdisk/src/label.c index f6bef31d1d..0abda435a6 100644 --- a/libfdisk/src/label.c +++ b/libfdisk/src/label.c @@ -107,20 +107,21 @@ int fdisk_missing_geometry(struct fdisk_context *cxt) } /** - * fdisk_get_columns: + * fdisk_get_fields: * @cxt: fdisk context * @all: 1 or 0 - * @cols: returns allocated array with FDISK_COL_* IDs - * @ncols: returns number of items in cols + * @ids: returns allocated array with FDISK_FIELD_* IDs + * @nids: returns number of items in fields * - * This function returns the default or all columns for the current label. - * Note that the set of the default columns depends on + * This function returns the default or all fields for the current label. + * Note that the set of the default fields depends on * fdisk_context_enable_details() function. If the details are enabled then - * this function usually returns more columns. + * this function usually returns more fields. * * Returns 0 on success, otherwise, a corresponding error. */ -int fdisk_get_columns(struct fdisk_context *cxt, int all, int **cols, size_t *ncols) +int fdisk_get_fields_ids(struct fdisk_context *cxt, int all, + int **ids, size_t *nids) { size_t i, n; int *c; @@ -129,70 +130,69 @@ int fdisk_get_columns(struct fdisk_context *cxt, int all, int **cols, size_t *nc if (!cxt->label) return -EINVAL; - if (!cxt->label->columns || !cxt->label->ncolumns) + if (!cxt->label->fields || !cxt->label->nfields) return -ENOSYS; - c = calloc(cxt->label->ncolumns, sizeof(int)); + c = calloc(cxt->label->nfields, sizeof(int)); if (!c) return -ENOMEM; - for (n = 0, i = 0; i < cxt->label->ncolumns; i++) { - int id = cxt->label->columns[i].id; + for (n = 0, i = 0; i < cxt->label->nfields; i++) { + int id = cxt->label->fields[i].id; if (!all && ((fdisk_context_display_details(cxt) && - (cxt->label->columns[i].flags & FDISK_COLFL_EYECANDY)) + (cxt->label->fields[i].flags & FDISK_FIELDFL_EYECANDY)) || (!fdisk_context_display_details(cxt) && - (cxt->label->columns[i].flags & FDISK_COLFL_DETAIL)) - || (id == FDISK_COL_SECTORS && + (cxt->label->fields[i].flags & FDISK_FIELDFL_DETAIL)) + || (id == FDISK_FIELD_SECTORS && fdisk_context_use_cylinders(cxt)) - || (id == FDISK_COL_CYLINDERS && + || (id == FDISK_FIELD_CYLINDERS && !fdisk_context_use_cylinders(cxt)))) continue; c[n++] = id; } - if (cols) - *cols = c; + if (ids) + *ids = c; else free(c); - if (ncols) - *ncols = n; + if (nids) + *nids = n; return 0; } -const struct fdisk_column *fdisk_label_get_column( - struct fdisk_label *lb, int id) +const struct fdisk_field *fdisk_label_get_field(struct fdisk_label *lb, int id) { size_t i; assert(lb); assert(id > 0); - for (i = 0; i < lb->ncolumns; i++) { - if (lb->columns[i].id == id) - return &lb->columns[i]; + for (i = 0; i < lb->nfields; i++) { + if (lb->fields[i].id == id) + return &lb->fields[i]; } return NULL; } -int fdisk_column_get_id(const struct fdisk_column *col) +int fdisk_field_get_id(const struct fdisk_field *field) { - return col ? col->id : -EINVAL; + return field ? field->id : -EINVAL; } -const char *fdisk_column_get_name(const struct fdisk_column *col) +const char *fdisk_field_get_name(const struct fdisk_field *field) { - return col ? col->name : NULL; + return field ? field->name : NULL; } -double fdisk_column_get_width(const struct fdisk_column *col) +double fdisk_field_get_width(const struct fdisk_field *field) { - return col ? col->width : -EINVAL; + return field ? field->width : -EINVAL; } -int fdisk_column_is_number(const struct fdisk_column *col) +int fdisk_field_is_number(const struct fdisk_field *field) { - return col->flags ? col->flags & FDISK_COLFL_NUMBER : 0; + return field->flags ? field->flags & FDISK_FIELDFL_NUMBER : 0; } /** diff --git a/libfdisk/src/libfdisk.h b/libfdisk/src/libfdisk.h index e7bc843387..74e7e9957e 100644 --- a/libfdisk/src/libfdisk.h +++ b/libfdisk/src/libfdisk.h @@ -35,7 +35,7 @@ struct fdisk_partition; struct fdisk_ask; struct fdisk_iter; struct fdisk_table; -struct fdisk_column; +struct fdisk_field; /* * Supported partition table types (labels) @@ -118,28 +118,28 @@ extern int fdisk_is_parttype_string(struct fdisk_context *cxt); /* label.c */ enum { - FDISK_COL_NONE = 0, + FDISK_FIELD_NONE = 0, /* generic */ - FDISK_COL_DEVICE, - FDISK_COL_START, - FDISK_COL_END, - FDISK_COL_SECTORS, - FDISK_COL_CYLINDERS, - FDISK_COL_SIZE, - FDISK_COL_TYPE, - FDISK_COL_TYPEID, + FDISK_FIELD_DEVICE, + FDISK_FIELD_START, + FDISK_FIELD_END, + FDISK_FIELD_SECTORS, + FDISK_FIELD_CYLINDERS, + FDISK_FIELD_SIZE, + FDISK_FIELD_TYPE, + FDISK_FIELD_TYPEID, /* label specific */ - FDISK_COL_ATTR, - FDISK_COL_BOOT, - FDISK_COL_BSIZE, - FDISK_COL_CPG, - FDISK_COL_EADDR, - FDISK_COL_FSIZE, - FDISK_COL_NAME, - FDISK_COL_SADDR, - FDISK_COL_UUID, + FDISK_FIELD_ATTR, + FDISK_FIELD_BOOT, + FDISK_FIELD_BSIZE, + FDISK_FIELD_CPG, + FDISK_FIELD_EADDR, + FDISK_FIELD_FSIZE, + FDISK_FIELD_NAME, + FDISK_FIELD_SADDR, + FDISK_FIELD_UUID, }; extern int fdisk_require_geometry(struct fdisk_context *cxt); @@ -167,12 +167,16 @@ extern int fdisk_delete_partition(struct fdisk_context *cxt, size_t partnum); 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 all, int **cols, size_t *ncols); -extern int fdisk_column_get_id(const struct fdisk_column *col); -extern const char *fdisk_column_get_name(const struct fdisk_column *col); -extern double fdisk_column_get_width(const struct fdisk_column *col); -extern int fdisk_column_is_number(const struct fdisk_column *col); +extern int fdisk_get_fields_ids(struct fdisk_context *cxt, int all, + 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); +extern const char *fdisk_field_get_name(const struct fdisk_field *fl); +extern double fdisk_field_get_width(const struct fdisk_field *fl); +extern int fdisk_field_is_number(const struct fdisk_field *fl); + extern void fdisk_label_set_changed(struct fdisk_label *lb, int changed); extern int fdisk_label_is_changed(struct fdisk_label *lb); diff --git a/libfdisk/src/partition.c b/libfdisk/src/partition.c index 32473a3aba..24cbbc98b3 100644 --- a/libfdisk/src/partition.c +++ b/libfdisk/src/partition.c @@ -298,7 +298,7 @@ int fdisk_partition_next_partno( /** * fdisk_partition_to_string: * @pa: partition - * @id: column (FDISK_COL_*) + * @id: field (FDISK_FIELD_*) * @data: returns string with allocated data * * Returns info about partition converted to printable string. @@ -308,7 +308,7 @@ int fdisk_partition_next_partno( * struct fdisk_parition *pa; * * fdisk_get_partition(cxt, 0, &pa); - * fdisk_partition_to_string(pa, FDISK_COL_UUID, &data); + * fdisk_partition_to_string(pa, FDISK_FIELD_UUID, &data); * printf("first partition uuid: %s\n", data); * free(data); * fdisk_unref_partition(pa); @@ -331,7 +331,7 @@ int fdisk_partition_to_string(struct fdisk_partition *pa, return -EINVAL; switch (id) { - case FDISK_COL_DEVICE: + case FDISK_FIELD_DEVICE: if (pa->freespace) p = strdup(_("Free space")); else if (cxt->label->flags & FDISK_LABEL_FL_INCHARS_PARTNO) @@ -339,22 +339,22 @@ int fdisk_partition_to_string(struct fdisk_partition *pa, else p = fdisk_partname(cxt->dev_path, pa->partno + 1); break; - case FDISK_COL_BOOT: + case FDISK_FIELD_BOOT: rc = asprintf(&p, "%c", pa->boot); break; - case FDISK_COL_START: + case FDISK_FIELD_START: x = fdisk_cround(cxt, pa->start); rc = pa->start_post ? asprintf(&p, "%ju%c", x, pa->start_post) : asprintf(&p, "%ju", x); break; - case FDISK_COL_END: + case FDISK_FIELD_END: x = fdisk_cround(cxt, pa->end); rc = pa->end_post ? asprintf(&p, "%ju%c", x, pa->end_post) : asprintf(&p, "%ju", x); break; - case FDISK_COL_SIZE: + case FDISK_FIELD_SIZE: { uint64_t sz = pa->size * cxt->sector_size; @@ -369,44 +369,44 @@ int fdisk_partition_to_string(struct fdisk_partition *pa, } break; } - case FDISK_COL_CYLINDERS: + case FDISK_FIELD_CYLINDERS: rc = asprintf(&p, "%ju", (uintmax_t) fdisk_cround(cxt, pa->size)); break; - case FDISK_COL_SECTORS: + case FDISK_FIELD_SECTORS: rc = asprintf(&p, "%ju", pa->size); break; - case FDISK_COL_BSIZE: + case FDISK_FIELD_BSIZE: rc = asprintf(&p, "%ju", pa->bsize); break; - case FDISK_COL_FSIZE: + case FDISK_FIELD_FSIZE: rc = asprintf(&p, "%ju", pa->fsize); break; - case FDISK_COL_CPG: + case FDISK_FIELD_CPG: rc = asprintf(&p, "%ju", pa->cpg); break; - case FDISK_COL_TYPE: + case FDISK_FIELD_TYPE: p = pa->type && pa->type->name ? strdup(pa->type->name) : NULL; break; - case FDISK_COL_TYPEID: + case FDISK_FIELD_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: + case FDISK_FIELD_UUID: p = pa->uuid ? strdup(pa->uuid) : NULL; break; - case FDISK_COL_NAME: + case FDISK_FIELD_NAME: p = pa->name ? strdup(pa->name) : NULL; break; - case FDISK_COL_ATTR: + case FDISK_FIELD_ATTR: p = pa->attrs ? strdup(pa->attrs) : NULL; break; - case FDISK_COL_SADDR: + case FDISK_FIELD_SADDR: p = pa->start_addr ? strdup(pa->start_addr) : NULL; break; - case FDISK_COL_EADDR: + case FDISK_FIELD_EADDR: p = pa->end_addr ? strdup(pa->end_addr) : NULL; break; default: diff --git a/libfdisk/src/sgi.c b/libfdisk/src/sgi.c index 8e8d3208e1..8f2bce8d5a 100644 --- a/libfdisk/src/sgi.c +++ b/libfdisk/src/sgi.c @@ -1080,17 +1080,17 @@ static int sgi_toggle_partition_flag(struct fdisk_context *cxt, size_t i, unsign return 0; } -static const struct fdisk_column sgi_columns[] = +static const struct fdisk_field sgi_fields[] = { - { FDISK_COL_DEVICE, N_("Device"), 10, 0 }, - { FDISK_COL_START, N_("Start"), 5, FDISK_COLFL_NUMBER }, - { FDISK_COL_END, N_("End"), 5, FDISK_COLFL_NUMBER }, - { FDISK_COL_SECTORS, N_("Sectors"), 5, FDISK_COLFL_NUMBER }, - { FDISK_COL_CYLINDERS, N_("Cylinders"), 5, FDISK_COLFL_NUMBER }, - { FDISK_COL_SIZE, N_("Size"), 5, FDISK_COLFL_NUMBER | FDISK_COLFL_EYECANDY }, - { FDISK_COL_TYPEID, N_("Id"), 2, FDISK_COLFL_NUMBER }, - { FDISK_COL_TYPE, N_("Type"), 0.1, FDISK_COLFL_EYECANDY }, - { FDISK_COL_ATTR, N_("Attrs"), 0, FDISK_COLFL_NUMBER } + { FDISK_FIELD_DEVICE, N_("Device"), 10, 0 }, + { FDISK_FIELD_START, N_("Start"), 5, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_END, N_("End"), 5, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_SECTORS, N_("Sectors"), 5, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_CYLINDERS,N_("Cylinders"), 5, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_SIZE, N_("Size"), 5, FDISK_FIELDFL_NUMBER | FDISK_FIELDFL_EYECANDY }, + { FDISK_FIELD_TYPEID, N_("Id"), 2, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_TYPE, N_("Type"), 0.1, FDISK_FIELDFL_EYECANDY }, + { FDISK_FIELD_ATTR, N_("Attrs"), 0, FDISK_FIELDFL_NUMBER } }; static const struct fdisk_label_operations sgi_operations = @@ -1130,8 +1130,8 @@ struct fdisk_label *fdisk_new_sgi_label(struct fdisk_context *cxt) lb->op = &sgi_operations; lb->parttypes = sgi_parttypes; lb->nparttypes = ARRAY_SIZE(sgi_parttypes); - lb->columns = sgi_columns; - lb->ncolumns = ARRAY_SIZE(sgi_columns); + lb->fields = sgi_fields; + lb->nfields = ARRAY_SIZE(sgi_fields); lb->flags |= FDISK_LABEL_FL_REQUIRE_GEOMETRY; diff --git a/libfdisk/src/sun.c b/libfdisk/src/sun.c index a4af4761b6..b6390ca2d2 100644 --- a/libfdisk/src/sun.c +++ b/libfdisk/src/sun.c @@ -992,18 +992,17 @@ static int sun_partition_is_used( return sunlabel->partitions[i].num_sectors ? 1 : 0; } - -static const struct fdisk_column sun_columns[] = +static const struct fdisk_field sun_fields[] = { - { FDISK_COL_DEVICE, N_("Device"), 10, 0 }, - { FDISK_COL_START, N_("Start"), 5, FDISK_COLFL_NUMBER }, - { FDISK_COL_END, N_("End"), 5, FDISK_COLFL_NUMBER }, - { FDISK_COL_SECTORS, N_("Sectors"), 5, FDISK_COLFL_NUMBER }, - { FDISK_COL_CYLINDERS, N_("Cylinders"), 5, FDISK_COLFL_NUMBER }, - { FDISK_COL_SIZE, N_("Size"), 5, FDISK_COLFL_NUMBER }, - { FDISK_COL_TYPEID, N_("Id"), 2, FDISK_COLFL_NUMBER }, - { FDISK_COL_TYPE, N_("Type"), 0.1, 0 }, - { FDISK_COL_ATTR, N_("Flags"), 0, FDISK_COLFL_NUMBER } + { FDISK_FIELD_DEVICE, N_("Device"), 10, 0 }, + { FDISK_FIELD_START, N_("Start"), 5, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_END, N_("End"), 5, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_SECTORS, N_("Sectors"), 5, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_CYLINDERS,N_("Cylinders"), 5, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_SIZE, N_("Size"), 5, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_TYPEID, N_("Id"), 2, FDISK_FIELDFL_NUMBER }, + { FDISK_FIELD_TYPE, N_("Type"), 0.1, 0 }, + { FDISK_FIELD_ATTR, N_("Flags"), 0, FDISK_FIELDFL_NUMBER } }; const struct fdisk_label_operations sun_operations = @@ -1047,8 +1046,8 @@ struct fdisk_label *fdisk_new_sun_label(struct fdisk_context *cxt) lb->op = &sun_operations; lb->parttypes = sun_parttypes; lb->nparttypes = ARRAY_SIZE(sun_parttypes); - lb->columns = sun_columns; - lb->ncolumns = ARRAY_SIZE(sun_columns); + lb->fields = sun_fields; + lb->nfields = ARRAY_SIZE(sun_fields); lb->flags |= FDISK_LABEL_FL_REQUIRE_GEOMETRY; return lb; -- 2.39.2