]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
losetup: use scols_column_set_json_type()
authorKarel Zak <kzak@redhat.com>
Wed, 18 Apr 2018 13:25:20 +0000 (15:25 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 18 Apr 2018 13:25:20 +0000 (15:25 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/losetup.c

index 9c479c02d74a74aa985025000da3f5050fb552a1..7c9145a88e154c3e6d9190f85e77cd912c6bcc85 100644 (file)
@@ -64,21 +64,23 @@ struct colinfo {
        double whint;
        int flags;
        const char *help;
+
+       int json_type;  /* default is string */
 };
 
 static struct colinfo infos[] = {
-       [COL_AUTOCLR]     = { "AUTOCLEAR",    1, SCOLS_FL_RIGHT, N_("autoclear flag set")},
+       [COL_AUTOCLR]     = { "AUTOCLEAR",    1, SCOLS_FL_RIGHT, N_("autoclear flag set"), SCOLS_JSON_BOOLEAN},
        [COL_BACK_FILE]   = { "BACK-FILE",  0.3, 0, N_("device backing file")},
-       [COL_BACK_INO]    = { "BACK-INO",     4, SCOLS_FL_RIGHT, N_("backing file inode number")},
+       [COL_BACK_INO]    = { "BACK-INO",     4, SCOLS_FL_RIGHT, N_("backing file inode number"), SCOLS_JSON_NUMBER},
        [COL_BACK_MAJMIN] = { "BACK-MAJ:MIN", 6, 0, N_("backing file major:minor device number")},
        [COL_NAME]        = { "NAME",      0.25, 0, N_("loop device name")},
-       [COL_OFFSET]      = { "OFFSET",       5, SCOLS_FL_RIGHT, N_("offset from the beginning")},
-       [COL_PARTSCAN]    = { "PARTSCAN",     1, SCOLS_FL_RIGHT, N_("partscan flag set")},
-       [COL_RO]          = { "RO",           1, SCOLS_FL_RIGHT, N_("read-only device")},
-       [COL_SIZELIMIT]   = { "SIZELIMIT",    5, SCOLS_FL_RIGHT, N_("size limit of the file in bytes")},
+       [COL_OFFSET]      = { "OFFSET",       5, SCOLS_FL_RIGHT, N_("offset from the beginning"), SCOLS_JSON_NUMBER},
+       [COL_PARTSCAN]    = { "PARTSCAN",     1, SCOLS_FL_RIGHT, N_("partscan flag set"), SCOLS_JSON_BOOLEAN},
+       [COL_RO]          = { "RO",           1, SCOLS_FL_RIGHT, N_("read-only device"), SCOLS_JSON_BOOLEAN},
+       [COL_SIZELIMIT]   = { "SIZELIMIT",    5, SCOLS_FL_RIGHT, N_("size limit of the file in bytes"), SCOLS_JSON_NUMBER},
        [COL_MAJMIN]      = { "MAJ:MIN",      3, 0, N_("loop device major:minor number")},
-       [COL_DIO]         = { "DIO",          1, SCOLS_FL_RIGHT, N_("access backing file with direct-io")},
-       [COL_LOGSEC]      = { "LOG-SEC",      4, SCOLS_FL_RIGHT, N_("logical sector size in bytes")},
+       [COL_DIO]         = { "DIO",          1, SCOLS_FL_RIGHT, N_("access backing file with direct-io"), SCOLS_JSON_BOOLEAN},
+       [COL_LOGSEC]      = { "LOG-SEC",      4, SCOLS_FL_RIGHT, N_("logical sector size in bytes"), SCOLS_JSON_NUMBER},
 };
 
 static int columns[ARRAY_SIZE(infos) * 2] = {-1};
@@ -328,9 +330,13 @@ static int show_table(struct loopdev_cxt *lc,
 
        for (i = 0; i < ncolumns; i++) {
                struct colinfo *ci = get_column_info(i);
+               struct libscols_column *cl;
 
-               if (!scols_table_new_column(tb, ci->name, ci->whint, ci->flags))
+               cl = scols_table_new_column(tb, ci->name, ci->whint, ci->flags);
+               if (!cl)
                        err(EXIT_FAILURE, _("failed to allocate output column"));
+               if (json)
+                       scols_column_set_json_type(cl, ci->json_type);
        }
 
        /* only one loopdev requested (already assigned to loopdev_cxt) */