diff options
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | disk-utils/Makemodule.am | 5 | ||||
-rw-r--r-- | disk-utils/cfdisk.c | 20 | ||||
-rw-r--r-- | disk-utils/fdisk.c | 109 | ||||
-rw-r--r-- | libfdisk/src/Makemodule.am | 10 | ||||
-rw-r--r-- | libfdisk/src/bsd.c | 17 | ||||
-rw-r--r-- | libfdisk/src/dos.c | 21 | ||||
-rw-r--r-- | libfdisk/src/fdiskP.h | 3 | ||||
-rw-r--r-- | libfdisk/src/gpt.c | 21 | ||||
-rw-r--r-- | libfdisk/src/label.c | 27 | ||||
-rw-r--r-- | libfdisk/src/libfdisk.h | 10 | ||||
-rw-r--r-- | libfdisk/src/sgi.c | 17 | ||||
-rw-r--r-- | libfdisk/src/sun.c | 18 | ||||
-rw-r--r-- | libfdisk/src/table.c | 94 |
14 files changed, 178 insertions, 196 deletions
diff --git a/configure.ac b/configure.ac index dd6194849..5b558ec11 100644 --- a/configure.ac +++ b/configure.ac @@ -823,11 +823,11 @@ dnl libfdisk is enabled at all times if possible dnl UL_BUILD_INIT([libfdisk], [check]) UL_REQUIRES_BUILD([libfdisk], [libuuid]) -UL_REQUIRES_BUILD([libfdisk], [libsmartcols]) AM_CONDITIONAL([BUILD_LIBFDISK], [test "x$build_libfdisk" = xyes]) UL_BUILD_INIT([fdisk], [check]) UL_REQUIRES_BUILD([fdisk], [libfdisk]) +UL_REQUIRES_BUILD([fdisk], [libsmartcols]) AM_CONDITIONAL([BUILD_FDISK], [test "x$build_fdisk" = xyes]) diff --git a/disk-utils/Makemodule.am b/disk-utils/Makemodule.am index 995e08552..04118c73b 100644 --- a/disk-utils/Makemodule.am +++ b/disk-utils/Makemodule.am @@ -142,6 +142,11 @@ fdisk_CFLAGS += -I$(ul_libuuid_incdir) fdisk_LDADD += libuuid.la endif +if BUILD_LIBSMARTCOLS +fdisk_CFLAGS += -I$(ul_libsmartcols_incdir) +fdisk_LDADD += libsmartcols.la +endif + if HAVE_STATIC_FDISK sbin_PROGRAMS += fdisk.static fdisk_static_SOURCES = $(fdisk_SOURCES) diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c index eff793355..453eafab0 100644 --- a/disk-utils/cfdisk.c +++ b/disk-utils/cfdisk.c @@ -235,9 +235,6 @@ static int partition_from_scols(struct fdisk_table *tb, return 0; } -/* It would be possible to use fdisk_table_to_string(), but we want some - * extension to the output format, so let's do it without libfdisk - */ static char *table_to_string(struct cfdisk *cf, struct fdisk_table *tb) { const struct fdisk_column *col; @@ -283,10 +280,18 @@ static char *table_to_string(struct cfdisk *cf, struct fdisk_table *tb) for (i = 0; i < cf->ncols; i++) { col = fdisk_label_get_column(lb, cf->cols[i]); if (col) { - int fl = col->scols_flags; - if (tree && col->id == FDISK_COL_DEVICE) + 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, col->name, col->width, fl)) + + if (!scols_table_new_column(table, + fdisk_column_get_name(col), + fdisk_column_get_width(col), fl)) goto done; } } @@ -305,7 +310,8 @@ static char *table_to_string(struct cfdisk *cf, struct fdisk_table *tb) col = fdisk_label_get_column(lb, cf->cols[i]); if (!col) continue; - if (fdisk_partition_to_string(pa, cf->cxt, col->id, &cdata)) + if (fdisk_partition_to_string(pa, cf->cxt, + fdisk_column_get_id(col), &cdata)) continue; scols_line_refer_data(ln, i, cdata); } diff --git a/disk-utils/fdisk.c b/disk-utils/fdisk.c index fed7a5745..1e6b45d3c 100644 --- a/disk-utils/fdisk.c +++ b/disk-utils/fdisk.c @@ -21,6 +21,7 @@ #include <sys/time.h> #include <time.h> #include <limits.h> +#include <libsmartcols.h> #include "c.h" #include "xalloc.h" @@ -539,45 +540,105 @@ void list_disklabel(struct fdisk_context *cxt) { struct fdisk_table *tb = NULL; struct fdisk_partition *pa = NULL; - struct fdisk_iter *itr; - - char *str; + struct fdisk_iter *itr = NULL; + struct libscols_table *out = NULL; + const char *bold = NULL; + int *cols = NULL; + size_t ncols = 0, i; /* print label specific stuff by libfdisk FDISK_ASK_INFO API */ fdisk_list_disklabel(cxt); - /* print partitions */ - if (fdisk_get_partitions(cxt, &tb)) - return; - if (fdisk_table_to_string(tb, cxt, NULL, 0, &str) == 0) { - fputc('\n', stdout); - if (str) { - char *p = str; - char *next = strchr(str, '\n'); - if (next && colors_wanted()) { - *next = '\0'; - color_scheme_enable("header", UL_COLOR_BOLD); - fputs(p, stdout); - color_disable(); - fputc('\n', stdout); - p = ++next; - } - fputs(p, stdout); - free(str); + /* get partitions and generate output */ + if (fdisk_get_partitions(cxt, &tb) || fdisk_table_get_nents(tb) <= 0) + goto done; + + if (fdisk_get_columns(cxt, 0, &cols, &ncols)) + goto done; + + itr = fdisk_new_iter(FDISK_ITER_FORWARD); + if (!itr) { + fdisk_warn(cxt, _("faild to allocate iterator")); + goto done; + } + + out = scols_new_table(); + if (!out) { + fdisk_warn(cxt, _("faild to allocate output table")); + goto done; + } + + if (colors_wanted()) { + scols_table_enable_colors(out, 1); + bold = color_scheme_get_sequence("header", UL_COLOR_BOLD); + } + + /* define output table columns */ + for (i = 0; i < ncols; i++) { + int fl = 0; + struct libscols_column *co; + const struct fdisk_column *col = + fdisk_label_get_column(cxt->label, cols[i]); + if (!col) + goto done; + if (fdisk_column_is_number(col)) + fl |= SCOLS_FL_RIGHT; + if (fdisk_column_get_id(col) == FDISK_COL_TYPE) + fl |= SCOLS_FL_TRUNC; + + co = scols_table_new_column(out, + fdisk_column_get_name(col), + fdisk_column_get_width(col), fl); + if (!co) + goto done; + + /* set colum header color */ + if (bold) + scols_cell_set_color(scols_column_get_header(co), bold); + } + + /* fill-in output table */ + while (fdisk_table_next_partition(tb, itr, &pa) == 0) { + struct libscols_line *ln = scols_table_new_line(out, NULL); + + if (!ln) { + fdisk_warn(cxt, _("faild to allocate output line")); + goto done; + } + + for (i = 0; i < ncols; 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)) + continue; + scols_line_refer_data(ln, i, data); } } - fputc('\n', stdout); + /* print */ + if (!scols_table_is_empty(out)) { + fputc('\n', stdout); + scols_print_table(out); + } - itr = fdisk_new_iter(FDISK_ITER_FORWARD); + fputc('\n', stdout); + + /* print warnings */ while (itr && fdisk_table_next_partition(tb, itr, &pa) == 0) fdisk_warn_alignment(cxt, fdisk_partition_get_start(pa), fdisk_partition_get_partno(pa) + 1); if (fdisk_table_wrong_order(tb)) fdisk_info(cxt, _("Partition table entries are not in disk order.")); - +done: + free(cols); + scols_unref_table(out); fdisk_unref_table(tb); fdisk_free_iter(itr); } diff --git a/libfdisk/src/Makemodule.am b/libfdisk/src/Makemodule.am index 99bddb2da..d8cbffbe3 100644 --- a/libfdisk/src/Makemodule.am +++ b/libfdisk/src/Makemodule.am @@ -49,12 +49,6 @@ libfdisk_la_DEPENDENCIES += libuuid.la libfdisk_la_CFLAGS += -I$(ul_libuuid_incdir) endif -if BUILD_LIBSMARTCOLS -libfdisk_la_LIBADD += libsmartcols.la -libfdisk_la_DEPENDENCIES += libsmartcols.la -libfdisk_la_CFLAGS += -I$(ul_libsmartcols_incdir) -endif - check_PROGRAMS += \ test_fdisk_ask \ test_fdisk_utils @@ -71,10 +65,6 @@ if BUILD_LIBUUID libfdisk_tests_ldflags += libuuid.la endif -if BUILD_LIBSMARTCOLS -libfdisk_tests_ldflags += libsmartcols.la -endif - test_fdisk_ask_SOURCES = libfdisk/src/ask.c test_fdisk_ask_CFLAGS = $(libfdisk_tests_cflags) test_fdisk_ask_LDFLAGS = $(libfdisk_tests_ldflags) diff --git a/libfdisk/src/bsd.c b/libfdisk/src/bsd.c index 0a03338f7..d6dc4b7f9 100644 --- a/libfdisk/src/bsd.c +++ b/libfdisk/src/bsd.c @@ -15,7 +15,6 @@ #include <fcntl.h> #include <errno.h> #include <sys/param.h> -#include <libsmartcols.h> #include "nls.h" #include "blkdev.h" @@ -882,15 +881,15 @@ static const struct fdisk_label_operations bsd_operations = static const struct fdisk_column bsd_columns[] = { { FDISK_COL_DEVICE, N_("Slice"), 1, 0 }, - { FDISK_COL_START, N_("Start"), 5, SCOLS_FL_RIGHT }, - { FDISK_COL_END, N_("End"), 5, SCOLS_FL_RIGHT }, - { FDISK_COL_SECTORS, N_("Sectors"), 5, SCOLS_FL_RIGHT }, - { FDISK_COL_CYLINDERS, N_("Cylinders"), 5, SCOLS_FL_RIGHT }, - { FDISK_COL_SIZE, N_("Size"), 5, SCOLS_FL_RIGHT }, + { 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, SCOLS_FL_RIGHT }, - { FDISK_COL_BSIZE, N_("Bsize"), 5, SCOLS_FL_RIGHT }, - { FDISK_COL_CPG, N_("Cpg"), 5, SCOLS_FL_RIGHT } + { 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 } }; /* diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c index 58ddec856..fc4ac7a80 100644 --- a/libfdisk/src/dos.c +++ b/libfdisk/src/dos.c @@ -15,7 +15,6 @@ #include "fdiskP.h" #include <ctype.h> -#include <libsmartcols.h> #define MAXIMUM_PARTS 60 #define ACTIVE_FLAG 0x80 @@ -1987,18 +1986,18 @@ static const struct fdisk_column dos_columns[] = /* basic */ { FDISK_COL_DEVICE, N_("Device"), 10, 0 }, { FDISK_COL_BOOT, N_("Boot"), 1, 0 }, - { FDISK_COL_START, N_("Start"), 5, SCOLS_FL_RIGHT }, - { FDISK_COL_END, N_("End"), 5, SCOLS_FL_RIGHT }, - { FDISK_COL_SECTORS, N_("Sectors"), 5, SCOLS_FL_RIGHT }, - { FDISK_COL_CYLINDERS, N_("Cylinders"), 5, SCOLS_FL_RIGHT }, - { FDISK_COL_SIZE, N_("Size"), 5, SCOLS_FL_RIGHT, FDISK_COLFL_EYECANDY }, - { FDISK_COL_TYPEID, N_("Id"), 2, SCOLS_FL_RIGHT }, - { FDISK_COL_TYPE, N_("Type"), 0.1, SCOLS_FL_TRUNC }, + { 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 }, /* expert mode */ - { FDISK_COL_SADDR, N_("Start-C/H/S"), 1, SCOLS_FL_RIGHT, FDISK_COLFL_DETAIL }, - { FDISK_COL_EADDR, N_("End-C/H/S"), 1, SCOLS_FL_RIGHT, FDISK_COLFL_DETAIL }, - { FDISK_COL_ATTR, N_("Attrs"), 2, SCOLS_FL_RIGHT, FDISK_COLFL_DETAIL } + { 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 } }; diff --git a/libfdisk/src/fdiskP.h b/libfdisk/src/fdiskP.h index ea6e291b1..0e5f234d8 100644 --- a/libfdisk/src/fdiskP.h +++ b/libfdisk/src/fdiskP.h @@ -235,8 +235,6 @@ struct fdisk_column { int id; /* FDISK_COL_* */ const char *name; /* column header */ double width; - int scols_flags; /* SCOLS_FL_* */ - int flags; /* FDISK_COLFL_* */ }; @@ -244,6 +242,7 @@ struct fdisk_column { 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 */ }; /* diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c index d5acf95d0..8ebb915df 100644 --- a/libfdisk/src/gpt.c +++ b/libfdisk/src/gpt.c @@ -18,7 +18,6 @@ #include <errno.h> #include <ctype.h> #include <uuid.h> -#include <libsmartcols.h> #include "fdiskP.h" @@ -2400,17 +2399,17 @@ static const struct fdisk_column gpt_columns[] = { /* basic */ { FDISK_COL_DEVICE, N_("Device"), 10, 0 }, - { FDISK_COL_START, N_("Start"), 5, SCOLS_FL_RIGHT }, - { FDISK_COL_END, N_("End"), 5, SCOLS_FL_RIGHT }, - { FDISK_COL_SECTORS, N_("Sectors"), 5, SCOLS_FL_RIGHT }, - { FDISK_COL_CYLINDERS, N_("Cylinders"), 5, SCOLS_FL_RIGHT }, - { FDISK_COL_SIZE, N_("Size"), 5, SCOLS_FL_RIGHT, FDISK_COLFL_EYECANDY }, - { FDISK_COL_TYPE, N_("Type"), 0.1, SCOLS_FL_TRUNC, FDISK_COLFL_EYECANDY }, + { 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 }, /* expert */ - { 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, SCOLS_FL_TRUNC, FDISK_COLFL_DETAIL }, - { FDISK_COL_ATTR, N_("Attrs"), 0, 0, FDISK_COLFL_DETAIL } + { 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 } }; /* diff --git a/libfdisk/src/label.c b/libfdisk/src/label.c index f2cc255cd..f6bef31d1 100644 --- a/libfdisk/src/label.c +++ b/libfdisk/src/label.c @@ -113,10 +113,9 @@ int fdisk_missing_geometry(struct fdisk_context *cxt) * @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 returns the default or all columns for the current label. + * Note that the set of the default columns depends on + * fdisk_context_enable_details() function. If the details are enabled then * this function usually returns more columns. * * Returns 0 on success, otherwise, a corresponding error. @@ -176,6 +175,26 @@ const struct fdisk_column *fdisk_label_get_column( return NULL; } +int fdisk_column_get_id(const struct fdisk_column *col) +{ + return col ? col->id : -EINVAL; +} + +const char *fdisk_column_get_name(const struct fdisk_column *col) +{ + return col ? col->name : NULL; +} + +double fdisk_column_get_width(const struct fdisk_column *col) +{ + return col ? col->width : -EINVAL; +} + +int fdisk_column_is_number(const struct fdisk_column *col) +{ + return col->flags ? col->flags & FDISK_COLFL_NUMBER : 0; +} + /** * fdisk_verify_disklabel: * @cxt: fdisk context diff --git a/libfdisk/src/libfdisk.h b/libfdisk/src/libfdisk.h index a717f4ea3..e7bc84338 100644 --- a/libfdisk/src/libfdisk.h +++ b/libfdisk/src/libfdisk.h @@ -35,6 +35,7 @@ struct fdisk_partition; struct fdisk_ask; struct fdisk_iter; struct fdisk_table; +struct fdisk_column; /* * Supported partition table types (labels) @@ -168,6 +169,11 @@ extern int fdisk_set_partition_type(struct fdisk_context *cxt, size_t partnum, 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 void fdisk_label_set_changed(struct fdisk_label *lb, int changed); extern int fdisk_label_is_changed(struct fdisk_label *lb); @@ -245,10 +251,6 @@ extern int fdisk_table_sort_partitions(struct fdisk_table *tb, int (*cmp)(struct fdisk_partition *, struct fdisk_partition *)); -extern int fdisk_table_to_string(struct fdisk_table *tb, - struct fdisk_context *cxt, - int *cols, size_t ncols, char **data); - extern int fdisk_table_next_partition( struct fdisk_table *tb, struct fdisk_iter *itr, diff --git a/libfdisk/src/sgi.c b/libfdisk/src/sgi.c index b191176d2..8e8d3208e 100644 --- a/libfdisk/src/sgi.c +++ b/libfdisk/src/sgi.c @@ -11,7 +11,6 @@ * Phillip Kesling <pkesling@sgi.com>, Mar 2003. */ -#include <libsmartcols.h> #include "c.h" #include "nls.h" #include "all-io.h" @@ -1084,14 +1083,14 @@ static int sgi_toggle_partition_flag(struct fdisk_context *cxt, size_t i, unsign static const struct fdisk_column sgi_columns[] = { { FDISK_COL_DEVICE, N_("Device"), 10, 0 }, - { FDISK_COL_START, N_("Start"), 5, SCOLS_FL_RIGHT }, - { FDISK_COL_END, N_("End"), 5, SCOLS_FL_RIGHT }, - { FDISK_COL_SECTORS, N_("Sectors"), 5, SCOLS_FL_RIGHT }, - { FDISK_COL_CYLINDERS, N_("Cylinders"), 5, SCOLS_FL_RIGHT }, - { FDISK_COL_SIZE, N_("Size"), 5, SCOLS_FL_RIGHT, FDISK_COLFL_EYECANDY }, - { FDISK_COL_TYPEID, N_("Id"), 2, SCOLS_FL_RIGHT }, - { FDISK_COL_TYPE, N_("Type"), 0.1, SCOLS_FL_TRUNC, FDISK_COLFL_EYECANDY }, - { FDISK_COL_ATTR, N_("Attrs"), 0, SCOLS_FL_RIGHT } + { 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 } }; static const struct fdisk_label_operations sgi_operations = diff --git a/libfdisk/src/sun.c b/libfdisk/src/sun.c index 50bdf8668..a4af4761b 100644 --- a/libfdisk/src/sun.c +++ b/libfdisk/src/sun.c @@ -12,8 +12,6 @@ #include <unistd.h> /* write */ #include <sys/ioctl.h> /* ioctl */ -#include <libsmartcols.h> - #include "nls.h" #include "blkdev.h" #include "bitops.h" @@ -998,14 +996,14 @@ static int sun_partition_is_used( static const struct fdisk_column sun_columns[] = { { FDISK_COL_DEVICE, N_("Device"), 10, 0 }, - { FDISK_COL_START, N_("Start"), 5, SCOLS_FL_RIGHT }, - { FDISK_COL_END, N_("End"), 5, SCOLS_FL_RIGHT }, - { FDISK_COL_SECTORS, N_("Sectors"), 5, SCOLS_FL_RIGHT }, - { FDISK_COL_CYLINDERS, N_("Cylinders"), 5, SCOLS_FL_RIGHT }, - { FDISK_COL_SIZE, N_("Size"), 5, SCOLS_FL_RIGHT }, - { FDISK_COL_TYPEID, N_("Id"), 2, SCOLS_FL_RIGHT }, - { FDISK_COL_TYPE, N_("Type"), 0.1, SCOLS_FL_TRUNC }, - { FDISK_COL_ATTR, N_("Flags"), 0, SCOLS_FL_RIGHT } + { 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 } }; const struct fdisk_label_operations sun_operations = diff --git a/libfdisk/src/table.c b/libfdisk/src/table.c index acdb365d0..61876d0ef 100644 --- a/libfdisk/src/table.c +++ b/libfdisk/src/table.c @@ -1,5 +1,4 @@ -#include <libsmartcols.h> #include "fdiskP.h" /** @@ -547,96 +546,3 @@ int fdisk_table_wrong_order(struct fdisk_table *tb) } return 0; } - -/** - * fdisk_table_to_string - * @tb: table - * @cxt: fdisk context - * @cols: array with wanted FDISK_COL_* columns - * @ncols: number of items in the cols array - * @data: returns table as a newlly allocated string or NULL for empty PT - * - * If no @cols are specified then the default is printed (see - * fdisk_get_columns() for the default columns). - - * Returns 0 on success, otherwise, a corresponding error. - */ -int fdisk_table_to_string(struct fdisk_table *tb, - struct fdisk_context *cxt, - int *cols, - size_t ncols, - char **data) -{ - int *org_cols = cols, rc = 0; - struct libscols_table *table = NULL; - const struct fdisk_column *col; - struct fdisk_partition *pa = NULL; - struct fdisk_iter itr; - size_t j; - - if (!cxt || !tb || !data) - return -EINVAL; - - DBG(TAB, ul_debugobj(tb, "generate string")); - *data = NULL; - - if (!fdisk_table_get_nents(tb)) - return 0; - - if (!cols || !ncols) { - rc = fdisk_get_columns(cxt, 0, &cols, &ncols); - if (rc) - return rc; - } - - table = scols_new_table(); - if (!table) { - rc = -ENOMEM; - goto done; - } - - /* define columns */ - for (j = 0; j < ncols; j++) { - col = fdisk_label_get_column(cxt->label, cols[j]); - if (col) - if (!scols_table_new_column(table, col->name, col->width, col->scols_flags)) - goto done; - } - - fdisk_reset_iter(&itr, FDISK_ITER_FORWARD); - - /* convert partition to string and add to table */ - while (fdisk_table_next_partition(tb, &itr, &pa) == 0) { - struct libscols_line *ln = scols_table_new_line(table, NULL); - if (!ln) { - rc = -ENOMEM; - goto done; - } - - DBG(TAB, ul_debugobj(tb, " string from part #%zu [%p]", - pa->partno + 1, pa)); - - /* set data for the columns */ - for (j = 0; j < ncols; j++) { - char *cdata = NULL; - - col = fdisk_label_get_column(cxt->label, cols[j]); - if (!col) - continue; - if (fdisk_partition_to_string(pa, cxt, col->id, &cdata)) - continue; - scols_line_refer_data(ln, j, cdata); - } - } - - rc = 0; - if (!scols_table_is_empty(table)) - rc = scols_print_table_to_string(table, data); - else - DBG(TAB, ul_debugobj(tb, "table empty")); -done: - if (org_cols != cols) - free(cols); - scols_unref_table(table); - return rc; -} |