summaryrefslogtreecommitdiffstats
path: root/misc-utils/lsblk.c
diff options
context:
space:
mode:
authorKarel Zak2018-06-18 13:01:27 +0200
committerKarel Zak2018-06-21 13:19:28 +0200
commitffc2762393b9ccb43899cd22a1d098d895d8b841 (patch)
tree3888f73ce9c02d8035c27b5c972875ecb11fc11d /misc-utils/lsblk.c
parentdocs: add note about lsblk to TODO (diff)
downloadkernel-qcow2-util-linux-ffc2762393b9ccb43899cd22a1d098d895d8b841.tar.gz
kernel-qcow2-util-linux-ffc2762393b9ccb43899cd22a1d098d895d8b841.tar.xz
kernel-qcow2-util-linux-ffc2762393b9ccb43899cd22a1d098d895d8b841.zip
lsblk: add --sysroot
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils/lsblk.c')
-rw-r--r--misc-utils/lsblk.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c
index ed771bc37..2d0c98127 100644
--- a/misc-utils/lsblk.c
+++ b/misc-utils/lsblk.c
@@ -222,6 +222,7 @@ struct lsblk {
struct libscols_column *sort_col;/* sort output by this column */
int sort_id;
+ const char *sysroot;
int flags; /* LSBLK_* */
unsigned int all_devices:1; /* print all devices, including empty */
@@ -1232,7 +1233,7 @@ static int set_cxt(struct blkdev_cxt *cxt,
}
DBG(CXT, ul_debugobj(cxt, "%s: filename=%s", cxt->name, cxt->filename));
- devno = __sysfs_devname_to_devno(NULL, cxt->name, wholedisk ? wholedisk->name : NULL);
+ devno = __sysfs_devname_to_devno(lsblk->sysroot, cxt->name, wholedisk ? wholedisk->name : NULL);
if (!devno) {
DBG(CXT, ul_debugobj(cxt, "%s: unknown device name", cxt->name));
@@ -1240,7 +1241,7 @@ static int set_cxt(struct blkdev_cxt *cxt,
}
if (lsblk->inverse) {
- cxt->sysfs = ul_new_sysfs_path(devno, wholedisk ? wholedisk->sysfs : NULL, NULL);
+ cxt->sysfs = ul_new_sysfs_path(devno, wholedisk ? wholedisk->sysfs : NULL, lsblk->sysroot);
if (!cxt->sysfs) {
DBG(CXT, ul_debugobj(cxt, "%s: failed to initialize sysfs handler", cxt->name));
return -1;
@@ -1248,7 +1249,7 @@ static int set_cxt(struct blkdev_cxt *cxt,
if (parent)
sysfs_blkdev_set_parent(parent->sysfs, cxt->sysfs);
} else {
- cxt->sysfs = ul_new_sysfs_path(devno, parent ? parent->sysfs : NULL, NULL);
+ cxt->sysfs = ul_new_sysfs_path(devno, parent ? parent->sysfs : NULL, lsblk->sysroot);
if (!cxt->sysfs) {
DBG(CXT, ul_debugobj(cxt, "%s: failed to initialize sysfs handler", cxt->name));
return -1;
@@ -1706,6 +1707,10 @@ int main(int argc, char *argv[])
size_t i;
int force_tree = 0;
+ enum {
+ OPT_SYSROOT = CHAR_MAX + 1
+ };
+
static const struct option longopts[] = {
{ "all", no_argument, NULL, 'a' },
{ "bytes", no_argument, NULL, 'b' },
@@ -1730,6 +1735,7 @@ int main(int argc, char *argv[])
{ "pairs", no_argument, NULL, 'P' },
{ "scsi", no_argument, NULL, 'S' },
{ "sort", required_argument, NULL, 'x' },
+ { "sysroot", required_argument, NULL, OPT_SYSROOT },
{ "tree", no_argument, NULL, 'T' },
{ "version", no_argument, NULL, 'V' },
{ NULL, 0, NULL, 0 },
@@ -1866,6 +1872,10 @@ int main(int argc, char *argv[])
case 'T':
force_tree = 1;
break;
+
+ case OPT_SYSROOT:
+ lsblk->sysroot = optarg;
+ break;
case 'V':
printf(UTIL_LINUX_VERSION);
return EXIT_SUCCESS;