]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsblk: fix -P regression from v2.34
authorKarel Zak <kzak@redhat.com>
Tue, 25 Feb 2020 14:31:23 +0000 (15:31 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 15 May 2020 09:49:13 +0000 (11:49 +0200)
Since v2.34 --list prints devices only once to make the output
user-readable. Unfortunately, it's regression for scripts/applications
where we need to parse lsblk output. So, let's make --pairs and --raw
backwardly compatible with versions before 2.34 and print all hierarchy.

Addresses: https://github.com/ibm-s390-tools/s390-tools/issues/80
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/lsblk.8
misc-utils/lsblk.c

index 373a80ee220ad3fd5abbe83122410a1c83a920d6..416b282984fe302597993729e5854374fd4934c4 100644 (file)
@@ -96,7 +96,8 @@ also \fB\-\-tree\fR if necessary.
 .BR \-l , " \-\-list"
 Produce output in the form of a list. The output does not provide information
 about relationships between devices and since version 2.34 every device is
-printed only once.
+printed only once if \fB\-\-pairs\fR or \fB\-\-raw\fR not specified (the
+parsable outputs are maintained in backwardly compatible way).
 .TP
 .BR \-M , " \-\-merge"
 Group parents of sub-trees to provide more readable output for RAIDs and
@@ -122,14 +123,15 @@ specified in the format \fI+list\fP (e.g., \fBlsblk \-o +UUID\fP).
 Output all available columns.
 .TP
 .BR \-P , " \-\-pairs"
-Produce output in the form of key="value" pairs.
-All potentially unsafe characters are hex-escaped (\\x<code>).
+Produce output in the form of key="value" pairs.  The output lines are still ordered by
+dependencies.  All potentially unsafe characters are hex-escaped (\\x<code>).
 .TP
 .BR \-p , " \-\-paths"
 Print full device paths.
 .TP
 .BR \-r , " \-\-raw"
-Produce output in raw format.  All potentially unsafe characters are hex-escaped
+Produce output in raw format.  The output lines are still ordered by
+dependencies.  All potentially unsafe characters are hex-escaped
 (\\x<code>) in the NAME, KNAME, LABEL, PARTLABEL and MOUNTPOINT columns.
 .TP
 .BR \-S , " \-\-scsi"
index 441655e24938331ae6a868f6d5f6f8fea8fb98fc..72ac7b483215f69bba784a20b402acd3b4048edd 100644 (file)
@@ -1058,8 +1058,8 @@ static void device_to_scols(
        if (!parent && dev->wholedisk)
                parent = dev->wholedisk;
 
-       /* Do not print device more than one in --list mode */
-       if (!(lsblk->flags & LSBLK_TREE) && dev->is_printed)
+       /* Do not print device more than once on --list if tree order is not requested */
+       if (!(lsblk->flags & LSBLK_TREE) && !lsblk->force_tree_order && dev->is_printed)
                return;
 
        if (lsblk->merge && list_count_entries(&dev->parents) > 1) {
@@ -2044,8 +2044,9 @@ int main(int argc, char *argv[])
                 * /sys is no more sorted */
                lsblk->sort_id = COL_MAJMIN;
 
-       /* For --inverse --list we still follow parent->child relation */
-       if (lsblk->inverse && !(lsblk->flags & LSBLK_TREE))
+       /* For --{inverse,raw,pairs} --list we still follow parent->child relation */
+       if (!(lsblk->flags & LSBLK_TREE)
+           && (lsblk->inverse || lsblk->flags & LSBLK_EXPORT || lsblk->flags & LSBLK_RAW))
                lsblk->force_tree_order = 1;
 
        if (lsblk->sort_id >= 0 && column_id_to_number(lsblk->sort_id) < 0) {