]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsblk: add --noempty
authorKarel Zak <kzak@redhat.com>
Wed, 12 Jan 2022 15:06:59 +0000 (16:06 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 12 Jan 2022 15:06:59 +0000 (16:06 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/lsblk.8.adoc
misc-utils/lsblk.c
misc-utils/lsblk.h

index 2397066e3e3fb4b4547a670de6a967c751fbf64f..e8c62bbde4869c7ec8d019c86fd8c8664d77559a 100644 (file)
@@ -28,6 +28,9 @@ The relationship between block devices and filesystems is not always one-to-one.
 
 == OPTIONS
 
+*-A*, *--noempty*::
+Don't print empty devices.
+
 *-a*, *--all*::
 Disable all built-in filters and list all empty devices and RAM disk devices too.
 
index b4696f5ec5c9d681760ae195071b432330090de3..21ea1af07eee7bee5877b747749c312272edccc7 100644 (file)
@@ -1244,6 +1244,9 @@ static int ignore_empty(struct lsblk_device *dev)
        if (dev->size)
                return 0;
 
+       if (lsblk->noempty && dev->size == 0)
+               return 1;
+
        /* ignore empty loop devices without backing file */
        if (dev->maj == LOOPDEV_MAJOR &&
            !loopdev_has_backing_file(dev->filename))
@@ -1903,6 +1906,7 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_(" -P, --pairs          use key=\"value\" output format\n"), out);
        fputs(_(" -S, --scsi           output info about SCSI devices\n"), out);
        fputs(_(" -T, --tree[=<column>] use tree format output\n"), out);
+       fputs(_(" -A, --noempty        don't print empty devices\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);
@@ -1965,6 +1969,7 @@ int main(int argc, char *argv[])
                { "all",        no_argument,       NULL, 'a' },
                { "bytes",      no_argument,       NULL, 'b' },
                { "nodeps",     no_argument,       NULL, 'd' },
+               { "noempty",    no_argument,       NULL, 'A' },
                { "discard",    no_argument,       NULL, 'D' },
                { "dedup",      required_argument, NULL, 'E' },
                { "zoned",      no_argument,       NULL, 'z' },
@@ -2018,11 +2023,15 @@ int main(int argc, char *argv[])
        lsblk_init_debug();
 
        while((c = getopt_long(argc, argv,
-                              "abdDzE:e:fhJlnMmo:OpPiI:rstVST::w:x:", longopts, NULL)) != -1) {
+                               "AabdDzE:e:fhJlnMmo:OpPiI:rstVST::w:x:",
+                               longopts, NULL)) != -1) {
 
                err_exclusive_options(c, longopts, excl, excl_st);
 
                switch(c) {
+               case 'A':
+                       lsblk->noempty = 1;
+                       break;
                case 'a':
                        lsblk->all_devices = 1;
                        break;
index 61640e825774f1a86d0bfb3c647afc5def3a869d..0ffe380088810bf02dcc706b87a640f128ca11a2 100644 (file)
@@ -55,6 +55,7 @@ struct lsblk {
        unsigned int sort_hidden:1;     /* sort column not between output columns */
        unsigned int dedup_hidden :1;   /* deduplication column not between output columns */
        unsigned int force_tree_order:1;/* sort lines by parent->tree relation */
+       unsigned int noempty:1;         /* hide empty devices */
 };
 
 extern struct lsblk *lsblk;     /* global handler */