diff options
Diffstat (limited to 'libfdisk/src')
| -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 |
10 files changed, 74 insertions, 164 deletions
diff --git a/libfdisk/src/Makemodule.am b/libfdisk/src/Makemodule.am index 99bddb2dad..d8cbffbe37 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 0a03338f70..d6dc4b7f95 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 58ddec8561..fc4ac7a801 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 ea6e291b1c..0e5f234d8f 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 d5acf95d04..8ebb915df1 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 f2cc255cdd..f6bef31d1d 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 a717f4ea3e..e7bc843387 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 b191176d26..8e8d3208e1 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 50bdf8668a..a4af4761b6 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 acdb365d09..61876d0efa 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; -} |
