diff --git a/Documentation/TODO b/Documentation/TODO index defca5a0d..1993422c8 100644 --- a/Documentation/TODO +++ b/Documentation/TODO @@ -26,9 +26,6 @@ lscpu lsblk ----- - - (!) add --tree to force tree output for operations like --sort where the - --list is enabled by default. - - currently it does not show mountpoint for all devices in btrfs RAID. It's because /proc/#/mountinfo contains reference to the one device only. Maybe we can add some btrfs specific code to provide a better output for FS based stacks. Not sure. diff --git a/misc-utils/lsblk.8 b/misc-utils/lsblk.8 index d9fc1c0c2..8485e99d7 100644 --- a/misc-utils/lsblk.8 +++ b/misc-utils/lsblk.8 @@ -129,7 +129,9 @@ This option is equivalent to Display version information and exit. .TP .BR \-x , " \-\-sort " \fIcolumn\fP -Sort output lines by \fIcolumn\fP. This option enables \fB\-\-list\fR output. +Sort output lines by \fIcolumn\fP. This option enables \fB\-\-list\fR output format by default. +It is possible to use the option \fI\-\-tree\fP to force tree-like output and +than the tree branches are sorted by the \fIcolumn\fP. .SH NOTES For partitions, some information (e.g. queue attributes) is inherited from the parent device. diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c index 79077af07..1e8108290 100644 --- a/misc-utils/lsblk.c +++ b/misc-utils/lsblk.c @@ -1644,6 +1644,7 @@ static void __attribute__((__noreturn__)) help(FILE *out) fputs(_(" -I, --include 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(_(" -T, --tree use tree format output\n"), out); fputs(_(" -m, --perms output info about permissions\n"), out); fputs(_(" -n, --noheadings don't print headings\n"), out); fputs(_(" -o, --output output columns\n"), out); @@ -1682,6 +1683,7 @@ int main(int argc, char *argv[]) int c, status = EXIT_FAILURE; char *outarg = NULL; size_t i; + int force_tree = 0; static const struct option longopts[] = { { "all", no_argument, NULL, 'a' }, @@ -1707,6 +1709,7 @@ int main(int argc, char *argv[]) { "pairs", no_argument, NULL, 'P' }, { "scsi", no_argument, NULL, 'S' }, { "sort", required_argument, NULL, 'x' }, + { "tree", no_argument, NULL, 'T' }, { "version", no_argument, NULL, 'V' }, { NULL, 0, NULL, 0 }, }; @@ -1719,7 +1722,7 @@ int main(int argc, char *argv[]) { 'O','f' }, { 'O','m' }, { 'O','t' }, - { 'P','l','r' }, + { 'P','T', 'l','r' }, { 0 } }; int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT; @@ -1734,7 +1737,7 @@ int main(int argc, char *argv[]) lsblk_init_debug(); while((c = getopt_long(argc, argv, - "abdDze:fhJlnmo:OpPiI:rstVSx:", longopts, NULL)) != -1) { + "abdDze:fhJlnmo:OpPiI:rstVSTx:", longopts, NULL)) != -1) { err_exclusive_options(c, longopts, excl, excl_st); @@ -1839,6 +1842,9 @@ int main(int argc, char *argv[]) add_uniq_column(COL_REV); add_uniq_column(COL_TRANSPORT); break; + case 'T': + force_tree = 1; + break; case 'V': printf(UTIL_LINUX_VERSION); return EXIT_SUCCESS; @@ -1853,6 +1859,9 @@ int main(int argc, char *argv[]) } } + if (force_tree) + lsblk->flags |= LSBLK_TREE; + check_sysdevblock(); if (!ncolumns) {