LSBLK_NOHEADINGS = (1 << 2),
LSBLK_EXPORT = (1 << 3),
LSBLK_TREE = (1 << 4),
+ LSBLK_JSON = (1 << 5),
};
enum {
#define is_parsable(_l) (scols_table_is_raw((_l)->table) || \
- scols_table_is_export((_l)->table))
+ scols_table_is_export((_l)->table) || \
+ scols_table_is_json((_l)->table))
static char *mk_name(const char *name)
{
fputs(_(" -f, --fs output info about filesystems\n"), out);
fputs(_(" -i, --ascii use ascii characters only\n"), out);
fputs(_(" -I, --include <list> show only devices with specified major numbers\n"), out);
+ fputs(_(" -J, --json use JSON output format\n"), out);
fputs(_(" -l, --list use list format output\n"), out);
fputs(_(" -m, --perms output info about permissions\n"), out);
fputs(_(" -n, --noheadings don't print headings\n"), out);
{ "nodeps", 0, 0, 'd' },
{ "discard", 0, 0, 'D' },
{ "help", 0, 0, 'h' },
+ { "json", 0, 0, 'J' },
{ "output", 1, 0, 'o' },
{ "output-all", 0, 0, 'O' },
{ "perms", 0, 0, 'm' },
static const ul_excl_t excl[] = { /* rows and cols in in ASCII order */
{ 'D','O' },
{ 'I','e' },
+ { 'J', 'P', 'r' },
{ 'O','S' },
{ 'O','f' },
{ 'O','m' },
lsblk_init_debug();
while((c = getopt_long(argc, argv,
- "abdDe:fhlnmo:OpPiI:rstVSx:", longopts, NULL)) != -1) {
+ "abdDe:fhJlnmo:OpPiI:rstVSx:", longopts, NULL)) != -1) {
err_exclusive_options(c, longopts, excl, excl_st);
case 'h':
help(stdout);
break;
+ case 'J':
+ scols_flags |= LSBLK_JSON;
+ break;
case 'l':
scols_flags &= ~LSBLK_TREE; /* disable the default */
break;
scols_table_enable_raw(lsblk->table, !!(scols_flags & LSBLK_RAW));
scols_table_enable_export(lsblk->table, !!(scols_flags & LSBLK_EXPORT));
scols_table_enable_ascii(lsblk->table, !!(scols_flags & LSBLK_ASCII));
+ scols_table_enable_json(lsblk->table, !!(scols_flags & LSBLK_JSON));
scols_table_enable_noheadings(lsblk->table, !!(scols_flags & LSBLK_NOHEADINGS));
+ if (scols_flags & LSBLK_JSON)
+ scols_table_set_name(lsblk->table, "blockdevices");
+
for (i = 0; i < ncolumns; i++) {
struct colinfo *ci = get_column_info(i);
struct libscols_column *cl;