From: Karel Zak Date: Wed, 12 Jan 2022 15:06:59 +0000 (+0100) Subject: lsblk: add --noempty X-Git-Tag: v2.38-rc1~59 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=554e866b94fc9965fef089cf480abea474dc9e34;p=thirdparty%2Futil-linux.git lsblk: add --noempty Signed-off-by: Karel Zak --- diff --git a/misc-utils/lsblk.8.adoc b/misc-utils/lsblk.8.adoc index 2397066e3e..e8c62bbde4 100644 --- a/misc-utils/lsblk.8.adoc +++ b/misc-utils/lsblk.8.adoc @@ -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. diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c index b4696f5ec5..21ea1af07e 100644 --- a/misc-utils/lsblk.c +++ b/misc-utils/lsblk.c @@ -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[=] 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; diff --git a/misc-utils/lsblk.h b/misc-utils/lsblk.h index 61640e8257..0ffe380088 100644 --- a/misc-utils/lsblk.h +++ b/misc-utils/lsblk.h @@ -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 */