summaryrefslogtreecommitdiffstats
path: root/disk-utils/partx.c
diff options
context:
space:
mode:
authorOndrej Oprala2014-03-27 15:18:20 +0100
committerKarel Zak2014-04-03 12:29:18 +0200
commit016aa0ac943c040b3797ef89f0ed7a65a9e402b0 (patch)
treef6d371ecd160194bb265b73f6ec7d7797ae254c1 /disk-utils/partx.c
parentUse libsmartcols in libfdisk and cfdisk (diff)
downloadkernel-qcow2-util-linux-016aa0ac943c040b3797ef89f0ed7a65a9e402b0.tar.gz
kernel-qcow2-util-linux-016aa0ac943c040b3797ef89f0ed7a65a9e402b0.tar.xz
kernel-qcow2-util-linux-016aa0ac943c040b3797ef89f0ed7a65a9e402b0.zip
partx: use libsmartcols
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Diffstat (limited to 'disk-utils/partx.c')
-rw-r--r--disk-utils/partx.c68
1 files changed, 39 insertions, 29 deletions
diff --git a/disk-utils/partx.c b/disk-utils/partx.c
index 44d38fd0e..d8d056f40 100644
--- a/disk-utils/partx.c
+++ b/disk-utils/partx.c
@@ -21,11 +21,11 @@
#include <dirent.h>
#include <blkid.h>
+#include <libsmartcols.h>
#include "c.h"
#include "pathnames.h"
#include "nls.h"
-#include "tt.h"
#include "blkdev.h"
#include "strutils.h"
#include "xalloc.h"
@@ -39,6 +39,13 @@
/* this is the default upper limit, could be modified by --nr */
#define SLICES_MAX 256
+/* basic table settings */
+enum {
+ PARTX_RAW = (1 << 0),
+ PARTX_NOHEADINGS = (1 << 1),
+ PARTX_EXPORT = (1 << 2),
+};
+
/* all the columns (-o option) */
enum {
COL_PARTNO,
@@ -71,22 +78,22 @@ enum {
struct colinfo {
const char *name; /* header */
double whint; /* width hint (N < 1 is in percent of termwidth) */
- int flags; /* TT_FL_* */
+ int flags; /* SCOLS_FL_* */
const char *help;
};
/* columns descriptions */
struct colinfo infos[] = {
- [COL_PARTNO] = { "NR", 0.25, TT_FL_RIGHT, N_("partition number") },
- [COL_START] = { "START", 0.30, TT_FL_RIGHT, N_("start of the partition in sectors") },
- [COL_END] = { "END", 0.30, TT_FL_RIGHT, N_("end of the partition in sectors") },
- [COL_SECTORS] = { "SECTORS", 0.30, TT_FL_RIGHT, N_("number of sectors") },
- [COL_SIZE] = { "SIZE", 0.30, TT_FL_RIGHT, N_("human readable size") },
- [COL_NAME] = { "NAME", 0.30, TT_FL_TRUNC, N_("partition name") },
+ [COL_PARTNO] = { "NR", 0.25, SCOLS_FL_RIGHT, N_("partition number") },
+ [COL_START] = { "START", 0.30, SCOLS_FL_RIGHT, N_("start of the partition in sectors") },
+ [COL_END] = { "END", 0.30, SCOLS_FL_RIGHT, N_("end of the partition in sectors") },
+ [COL_SECTORS] = { "SECTORS", 0.30, SCOLS_FL_RIGHT, N_("number of sectors") },
+ [COL_SIZE] = { "SIZE", 0.30, SCOLS_FL_RIGHT, N_("human readable size") },
+ [COL_NAME] = { "NAME", 0.30, SCOLS_FL_TRUNC, N_("partition name") },
[COL_UUID] = { "UUID", 36, 0, N_("partition UUID")},
- [COL_SCHEME] = { "SCHEME", 0.1, TT_FL_TRUNC, N_("partition table type (dos, gpt, ...)")},
- [COL_FLAGS] = { "FLAGS", 0.1, TT_FL_TRUNC, N_("partition flags")},
- [COL_TYPE] = { "TYPE", 1, TT_FL_RIGHT, N_("partition type (a string, a UUID, or hex)")},
+ [COL_SCHEME] = { "SCHEME", 0.1, SCOLS_FL_TRUNC, N_("partition table type (dos, gpt, ...)")},
+ [COL_FLAGS] = { "FLAGS", 0.1, SCOLS_FL_TRUNC, N_("partition flags")},
+ [COL_TYPE] = { "TYPE", 1, SCOLS_FL_RIGHT, N_("partition type (a string, a UUID, or hex)")},
};
#define NCOLS ARRAY_SIZE(infos)
@@ -526,15 +533,15 @@ static int list_parts(blkid_partlist ls, int lower, int upper)
return 0;
}
-static void add_tt_line(struct tt *tt, blkid_partition par)
+static void add_scols_line(struct libscols_table *table, blkid_partition par)
{
- struct tt_line *line;
+ struct libscols_line *line;
int i;
- assert(tt);
+ assert(table);
assert(par);
- line = tt_add_line(tt, NULL);
+ line = scols_table_new_line(table, NULL);
if (!line) {
warn(_("failed to add line to output"));
return;
@@ -594,14 +601,14 @@ static void add_tt_line(struct tt *tt, blkid_partition par)
}
if (str)
- tt_line_set_data(line, i, str);
+ scols_line_set_data(line, i, str);
}
}
-static int show_parts(blkid_partlist ls, int tt_flags, int lower, int upper)
+static int show_parts(blkid_partlist ls, int scols_flags, int lower, int upper)
{
int i, rc = -1;
- struct tt *tt;
+ struct libscols_table *table;
int nparts;
assert(ls);
@@ -610,16 +617,19 @@ static int show_parts(blkid_partlist ls, int tt_flags, int lower, int upper)
if (!nparts)
return 0;
- tt = tt_new_table(tt_flags | TT_FL_FREEDATA);
- if (!tt) {
+ table = scols_new_table(NULL);
+ if (!table) {
warn(_("failed to initialize output table"));
return -1;
}
+ scols_table_set_raw(table, !!(scols_flags & PARTX_RAW));
+ scols_table_set_export(table, !!(scols_flags & PARTX_EXPORT));
+ scols_table_set_no_headings(table, !!(scols_flags & PARTX_NOHEADINGS));
for (i = 0; i < ncolumns; i++) {
struct colinfo *col = get_column_info(i);
- if (!tt_define_column(tt, col->name, col->whint, col->flags)) {
+ if (!scols_table_new_column(table, col->name, col->whint, col->flags)) {
warnx(_("failed to initialize output column"));
goto done;
}
@@ -634,13 +644,13 @@ static int show_parts(blkid_partlist ls, int tt_flags, int lower, int upper)
if (upper && n > upper)
continue;
- add_tt_line(tt, par);
+ add_scols_line(table, par);
}
rc = 0;
- tt_print_table(tt);
+ scols_print_table(table);
done:
- tt_free_table(tt);
+ scols_unref_table(table);
return rc;
}
@@ -722,7 +732,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
int main(int argc, char **argv)
{
int fd, c, what = ACT_NONE, lower = 0, upper = 0, rc = 0;
- int tt_flags = 0;
+ int scols_flags = 0;
char *type = NULL;
char *device = NULL; /* pointer to argv[], ie: /dev/sda1 */
char *wholedisk = NULL; /* allocated, ie: /dev/sda */
@@ -775,7 +785,7 @@ int main(int argc, char **argv)
what = ACT_DELETE;
break;
case 'g':
- tt_flags |= TT_FL_NOHEADINGS;
+ scols_flags |= PARTX_NOHEADINGS;
break;
case 'l':
what = ACT_LIST;
@@ -788,11 +798,11 @@ int main(int argc, char **argv)
outarg = optarg;
break;
case 'P':
- tt_flags |= TT_FL_EXPORT;
+ scols_flags |= PARTX_EXPORT;
what = ACT_SHOW;
break;
case 'r':
- tt_flags |= TT_FL_RAW;
+ scols_flags |= PARTX_RAW;
what = ACT_SHOW;
break;
case 's':
@@ -953,7 +963,7 @@ int main(int argc, char **argv)
switch (what) {
case ACT_SHOW:
- rc = show_parts(ls, tt_flags, lower, upper);
+ rc = show_parts(ls, scols_flags, lower, upper);
break;
case ACT_LIST:
rc = list_parts(ls, lower, upper);