[i-g-t PATCH 3/4] lib/igt_debugfs: Add helper to return path to device.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Abdiel Janulgue <abdiel.janulgue@xxxxxxxxxxxxxxx>
---
 lib/igt_debugfs.c | 26 ++++++++++++++++++++++++++
 lib/igt_debugfs.h |  1 +
 2 files changed, 27 insertions(+)

diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 7584be5..b019c3b 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -22,6 +22,9 @@
  *
  */
 
+#ifndef ANDROID
+#define _GNU_SOURCE
+#endif
 #include <inttypes.h>
 #include <sys/stat.h>
 #include <sys/mount.h>
@@ -198,6 +201,29 @@ int igt_debugfs_dir(int device)
 	igt_debug("Opening debugfs directory '%s'\n", path);
 	return open(path, O_RDONLY);
 }
+\
+/**
+ * igt_debugfs_path:
+ * @device: fd of the device
+ *
+ * Returns:
+ * The path to the debugfs directory corresponding to device
+ */
+const char *igt_debugfs_path(int device)
+{
+	char *path = 0;
+
+	if (!path) {
+		char *linkname;
+		int debugfs;
+		igt_assert((debugfs = igt_debugfs_dir(device)) != -1);
+		igt_assert(path = calloc(PATH_MAX, sizeof(char)));
+		igt_assert(asprintf(&linkname, "/proc/self/fd/%d", debugfs) != -1);
+		igt_assert(readlink(linkname, path, PATH_MAX * sizeof(char)) != -1);
+	}
+
+	return path;
+}
 
 /**
  * igt_debugfs_open:
diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h
index 7b846a8..76cf409 100644
--- a/lib/igt_debugfs.h
+++ b/lib/igt_debugfs.h
@@ -204,5 +204,6 @@ void igt_enable_prefault(void);
  */
 int igt_get_stable_obj_count(int driver);
 void igt_debugfs_dump(int device, const char *filename);
+const char *igt_debugfs_path(int device);
 
 #endif /* __IGT_DEBUGFS_H__ */
-- 
2.7.4

_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux