summaryrefslogtreecommitdiff
path: root/lib/igt_debugfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/igt_debugfs.c')
-rw-r--r--lib/igt_debugfs.c50
1 files changed, 35 insertions, 15 deletions
diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 63183e57..1e8c8cc3 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -127,38 +127,38 @@ const char *igt_debugfs_mount(void)
}
/**
- * igt_debugfs_dir:
+ * igt_debugfs_path:
* @device: fd of the device
+ * @path: buffer to store path
+ * @pathlen: len of @path buffer.
*
- * This opens the debugfs directory corresponding to device for use
- * with igt_sysfs_get() and related functions.
+ * This finds the debugfs directory corresponding to @device.
*
* Returns:
- * The directory fd, or -1 on failure.
+ * The directory path, or NULL on failure.
*/
-int igt_debugfs_dir(int device)
+char *igt_debugfs_path(int device, char *path, int pathlen)
{
struct stat st;
const char *debugfs_root;
- char path[200];
int idx;
if (fstat(device, &st)) {
igt_debug("Couldn't stat FD for DRM device: %s\n", strerror(errno));
- return -1;
+ return NULL;
}
if (!S_ISCHR(st.st_mode)) {
igt_debug("FD for DRM device not a char device!\n");
- return -1;
+ return NULL;
}
debugfs_root = igt_debugfs_mount();
idx = minor(st.st_rdev);
- snprintf(path, sizeof(path), "%s/dri/%d/name", debugfs_root, idx);
+ snprintf(path, pathlen, "%s/dri/%d/name", debugfs_root, idx);
if (stat(path, &st))
- return -1;
+ return NULL;
if (idx >= 64) {
int file, name_len, cmp_len;
@@ -166,17 +166,17 @@ int igt_debugfs_dir(int device)
file = open(path, O_RDONLY);
if (file < 0)
- return -1;
+ return NULL;
name_len = read(file, name, sizeof(name));
close(file);
for (idx = 0; idx < 16; idx++) {
- snprintf(path, sizeof(path), "%s/dri/%d/name",
+ snprintf(path, pathlen, "%s/dri/%d/name",
debugfs_root, idx);
file = open(path, O_RDONLY);
if (file < 0)
- return -1;
+ return NULL;
cmp_len = read(file, cmp, sizeof(cmp));
close(file);
@@ -186,10 +186,30 @@ int igt_debugfs_dir(int device)
}
if (idx == 16)
- return -1;
+ return NULL;
}
- snprintf(path, sizeof(path), "%s/dri/%d", debugfs_root, idx);
+ snprintf(path, pathlen, "%s/dri/%d", debugfs_root, idx);
+ return path;
+}
+
+/**
+ * igt_debugfs_dir:
+ * @device: fd of the device
+ *
+ * This opens the debugfs directory corresponding to device for use
+ * with igt_sysfs_get() and related functions.
+ *
+ * Returns:
+ * The directory fd, or -1 on failure.
+ */
+int igt_debugfs_dir(int device)
+{
+ char path[200];
+
+ if (!igt_debugfs_path(device, path, sizeof(path)))
+ return -1;
+
igt_debug("Opening debugfs directory '%s'\n", path);
return open(path, O_RDONLY);
}