* document --tree (was missing in the man page)
* add optional argument to --tree to specify tree
For example:
$ lsblk -o KNAME,SIZE,MOUNTPOINT --tree=KNAME /dev/dm-0
KNAME SIZE MOUNTPOINT
dm-0 232.9G
└─dm-1 232.9G
└─dm-2 232.9G
Signed-off-by: Karel Zak <kzak@redhat.com>
outputs in your scripts. Always explicitly define expected columns by using
.B \-\-output
.I columns-list
outputs in your scripts. Always explicitly define expected columns by using
.B \-\-output
.I columns-list
in environments where a stable output is required.
.PP
Note that
in environments where a stable output is required.
.PP
Note that
Print dependencies in inverse order. If the \fB\-\-list\fR output is requested then
the lines are still ordered by dependencies.
.TP
Print dependencies in inverse order. If the \fB\-\-list\fR output is requested then
the lines are still ordered by dependencies.
.TP
+.BR \-T , " \-\-tree" [ =\fIcolumn ]
+Force tree-like output format. If \fIcolumn\fP is specified, then a tree is printed in the column.
+The default is NAME column.
+.TP
.BR \-t , " \-\-topology"
Output info about block-device topology.
This option is equivalent to
.BR \-t , " \-\-topology"
Output info about block-device topology.
This option is equivalent to
/* columns descriptions */
static struct colinfo infos[] = {
/* columns descriptions */
static struct colinfo infos[] = {
- [COL_NAME] = { "NAME", 0.25, SCOLS_FL_TREE | SCOLS_FL_NOEXTREMES, N_("device name") },
+ [COL_NAME] = { "NAME", 0.25, SCOLS_FL_NOEXTREMES, N_("device name") },
[COL_KNAME] = { "KNAME", 0.3, 0, N_("internal kernel device name") },
[COL_PKNAME] = { "PKNAME", 0.3, 0, N_("internal parent kernel device name") },
[COL_PATH] = { "PATH", 0.3, 0, N_("path to the device node") },
[COL_KNAME] = { "KNAME", 0.3, 0, N_("internal kernel device name") },
[COL_PKNAME] = { "PKNAME", 0.3, 0, N_("internal parent kernel device name") },
[COL_PATH] = { "PATH", 0.3, 0, N_("path to the device node") },
fputs(_(" -O, --output-all output all columns\n"), out);
fputs(_(" -P, --pairs use key=\"value\" output format\n"), out);
fputs(_(" -S, --scsi output info about SCSI devices\n"), out);
fputs(_(" -O, --output-all output all columns\n"), out);
fputs(_(" -P, --pairs use key=\"value\" output format\n"), out);
fputs(_(" -S, --scsi output info about SCSI devices\n"), out);
- fputs(_(" -T, --tree use tree format output\n"), out);
+ fputs(_(" -T, --tree[=<column>] use tree format output\n"), out);
fputs(_(" -a, --all print all devices\n"), out);
fputs(_(" -b, --bytes print SIZE in bytes rather than in human readable format\n"), out);
fputs(_(" -d, --nodeps don't print slaves or holders\n"), out);
fputs(_(" -a, --all print all devices\n"), out);
fputs(_(" -b, --bytes print SIZE in bytes rather than in human readable format\n"), out);
fputs(_(" -d, --nodeps don't print slaves or holders\n"), out);
struct lsblk _ls = {
.sort_id = -1,
.dedup_id = -1,
struct lsblk _ls = {
.sort_id = -1,
.dedup_id = -1,
+ .flags = LSBLK_TREE,
+ .tree_id = COL_NAME
};
struct lsblk_devtree *tr = NULL;
int c, status = EXIT_FAILURE;
char *outarg = NULL;
size_t i;
};
struct lsblk_devtree *tr = NULL;
int c, status = EXIT_FAILURE;
char *outarg = NULL;
size_t i;
+ int force_tree = 0, has_tree_col = 0;
enum {
OPT_SYSROOT = CHAR_MAX + 1
enum {
OPT_SYSROOT = CHAR_MAX + 1
{ "scsi", no_argument, NULL, 'S' },
{ "sort", required_argument, NULL, 'x' },
{ "sysroot", required_argument, NULL, OPT_SYSROOT },
{ "scsi", no_argument, NULL, 'S' },
{ "sort", required_argument, NULL, 'x' },
{ "sysroot", required_argument, NULL, OPT_SYSROOT },
- { "tree", no_argument, NULL, 'T' },
+ { "tree", optional_argument, NULL, 'T' },
{ "version", no_argument, NULL, 'V' },
{ NULL, 0, NULL, 0 },
};
{ "version", no_argument, NULL, 'V' },
{ NULL, 0, NULL, 0 },
};
lsblk_init_debug();
while((c = getopt_long(argc, argv,
lsblk_init_debug();
while((c = getopt_long(argc, argv,
- "abdDzE:e:fhJlnMmo:OpPiI:rstVSTx:", longopts, NULL)) != -1) {
+ "abdDzE:e:fhJlnMmo:OpPiI:rstVST:x:", longopts, NULL)) != -1) {
err_exclusive_options(c, longopts, excl, excl_st);
err_exclusive_options(c, longopts, excl, excl_st);
break;
case 'T':
force_tree = 1;
break;
case 'T':
force_tree = 1;
+ if (optarg)
+ lsblk->tree_id = column_name_to_id(optarg, strlen(optarg));
case OPT_SYSROOT:
lsblk->sysroot = optarg;
break;
case OPT_SYSROOT:
lsblk->sysroot = optarg;
break;
struct libscols_column *cl;
int id = get_column_id(i), fl = ci->flags;
struct libscols_column *cl;
int id = get_column_id(i), fl = ci->flags;
- if (!(lsblk->flags & LSBLK_TREE) && id == COL_NAME)
- fl &= ~SCOLS_FL_TREE;
+ if ((lsblk->flags & LSBLK_TREE)
+ && has_tree_col == 0
+ && id == lsblk->tree_id) {
+ fl |= SCOLS_FL_TREE;
+ fl &= ~SCOLS_FL_RIGHT;
+ has_tree_col = 1;
+ }
+
if (lsblk->sort_hidden && lsblk->sort_id == id)
fl |= SCOLS_FL_HIDDEN;
if (lsblk->dedup_hidden && lsblk->dedup_id == id)
if (lsblk->sort_hidden && lsblk->sort_id == id)
fl |= SCOLS_FL_HIDDEN;
if (lsblk->dedup_hidden && lsblk->dedup_id == id)
struct libscols_table *table; /* output table */
struct libscols_column *sort_col;/* sort output by this column */
struct libscols_table *table; /* output table */
struct libscols_column *sort_col;/* sort output by this column */
+
+ int sort_id; /* id of the sort column */
+ int tree_id; /* od of column used for tree */