From: Karel Zak Date: Thu, 16 Dec 2010 11:47:30 +0000 (+0100) Subject: lsblk: add --nodeps X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f31505fe0396a880dad297d14c29c2415cc94272;p=util-linux lsblk: add --nodeps Signed-off-by: Karel Zak --- diff --git a/misc-utils/lsblk.8 b/misc-utils/lsblk.8 index 50362c62..2f9c17f7 100644 --- a/misc-utils/lsblk.8 +++ b/misc-utils/lsblk.8 @@ -26,6 +26,9 @@ to get list of all available columns. List all block devices. .IP "\fB\-b, \-\-bytes\fP" Print the SIZE column in bytes rather than in human readable format. +.IP "\fB\-d, \-\-nodeps\fP" +Don't print device holders or slaves. For example "lsblk --nodeps /dev/sda" prints +information about the sda device only. .IP "\fB\-e, \-\-exclude \fIlist\fP Exclude devices by comma delimited list of major device numbers. Note that RAM disks (major=1) are excluded by default. diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c index cdfce42f..c07e30a7 100644 --- a/misc-utils/lsblk.c +++ b/misc-utils/lsblk.c @@ -118,6 +118,7 @@ struct lsblk { struct tt *tt; /* output table */ int all_devices:1; /* print all devices */ int bytes:1; /* print SIZE in bytes */ + int nodeps:1; /* don't print slaves/holders */ }; struct lsblk *lsblk; /* global handler */ @@ -693,6 +694,9 @@ static int list_holders(struct blkdev_cxt *cxt) assert(cxt); assert(cxt->sysfs_fd >= 0); + if (lsblk->nodeps) + return 0; + if (!cxt->nholders) return 0; @@ -853,6 +857,7 @@ static void __attribute__((__noreturn__)) help(FILE *out) "\nOptions:\n" " -a, --all print all devices\n" " -b, --bytes print SIZE in bytes rather than in human readable format\n" + " -d, --nodeps don't print slaves or holders\n" " -e, --exclude exclude devices by major number (default: RAM disks)\n" " -f, --fs output info about filesystems\n" " -h, --help usage information (this)\n" @@ -888,6 +893,8 @@ int main(int argc, char *argv[]) struct option longopts[] = { { "all", 0, 0, 'a' }, + { "bytes", 0, 0, 'b' }, + { "nodeps", 0, 0, 'd' }, { "help", 0, 0, 'h' }, { "output", 1, 0, 'o' }, { "perms", 0, 0, 'm' }, @@ -908,7 +915,7 @@ int main(int argc, char *argv[]) lsblk = &_ls; memset(lsblk, 0, sizeof(*lsblk)); - while((c = getopt_long(argc, argv, "abe:fhlnmo:irt", longopts, NULL)) != -1) { + while((c = getopt_long(argc, argv, "abde:fhlnmo:irt", longopts, NULL)) != -1) { switch(c) { case 'a': lsblk->all_devices = 1; @@ -916,6 +923,9 @@ int main(int argc, char *argv[]) case 'b': lsblk->bytes = 1; break; + case 'd': + lsblk->nodeps = 1; + break; case 'e': parse_excludes(optarg); break;