summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKarel Zak2012-10-23 10:57:59 +0200
committerKarel Zak2012-10-23 12:15:58 +0200
commitd0f7e5b4a0a1b83e515c9fd894d74ed36d7da5c1 (patch)
tree2d79269c4ab7dd7369e7615e3a28ec73f756a375 /lib
parentlib/tt: don't ignore "extreme" columns if an free space is available (diff)
downloadkernel-qcow2-util-linux-d0f7e5b4a0a1b83e515c9fd894d74ed36d7da5c1.tar.gz
kernel-qcow2-util-linux-d0f7e5b4a0a1b83e515c9fd894d74ed36d7da5c1.tar.xz
kernel-qcow2-util-linux-d0f7e5b4a0a1b83e515c9fd894d74ed36d7da5c1.zip
include/sysfs: add SCSI host:channel:target:lun support
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/sysfs.c42
1 files changed, 39 insertions, 3 deletions
diff --git a/lib/sysfs.c b/lib/sysfs.c
index 1384acda6..4cb6284ca 100644
--- a/lib/sysfs.c
+++ b/lib/sysfs.c
@@ -173,10 +173,9 @@ void sysfs_deinit(struct sysfs_cxt *cxt)
close(cxt->dir_fd);
free(cxt->dir_path);
- cxt->devno = 0;
+ memset(cxt, 0, sizeof(*cxt));
+
cxt->dir_fd = -1;
- cxt->parent = NULL;
- cxt->dir_path = NULL;
}
int sysfs_stat(struct sysfs_cxt *cxt, const char *attr, struct stat *st)
@@ -636,6 +635,43 @@ err:
return -1;
}
+
+int sysfs_scsi_get_hctl(struct sysfs_cxt *cxt, int *h, int *c, int *t, int *l)
+{
+ char buf[PATH_MAX], *hctl;
+ ssize_t len;
+
+ if (!cxt)
+ return -EINVAL;
+ if (cxt->has_hctl)
+ goto done;
+
+ len = sysfs_readlink(cxt, "device", buf, sizeof(buf));
+ if (len < 0)
+ return len;
+
+ buf[len] = '\0';
+ hctl = strrchr(buf, '/') + 1;
+ if (!hctl)
+ return -1;
+
+ if (sscanf(hctl, "%d:%d:%d:%d", &cxt->scsi_host, &cxt->scsi_channel,
+ &cxt->scsi_target, &cxt->scsi_lun) != 4)
+ return -1;
+
+ cxt->has_hctl = 1;
+done:
+ if (h)
+ *h = cxt->scsi_host;
+ if (c)
+ *c = cxt->scsi_channel;
+ if (t)
+ *t = cxt->scsi_target;
+ if (l)
+ *l = cxt->scsi_lun;
+ return 0;
+}
+
#ifdef TEST_PROGRAM_SYSFS
#include <errno.h>
#include <err.h>