[igt-dev] [PATCH i-g-t 1/2] lib/igt_debugfs: Add function to check if file exists in debugfs

Piotr Piórkowski piotr.piorkowski at intel.com
Tue Apr 10 13:52:26 UTC 2018


We doesn't have simple to use function to check if file exists
in debugfs.
Let's add function which takes as arguments the file descriptor of the
device and file name in the debugfs of this device, and return true if
file exists, otherwise false.

Signed-off-by: Piotr Piórkowski <piotr.piorkowski at intel.com>
Cc: Sagar Arun Kamble <sagar.a.kamble at intel.com>
Cc: Lukasz Fiedorowicz <lukasz.fiedorowicz at intel.com>
Cc: Michal Wajdeczko <michal.wajdeczko at intel.com>
Cc: Michał Winiarski <michal.winiarski at intel.com>
---
 lib/igt_debugfs.c | 28 ++++++++++++++++++++++++++++
 lib/igt_debugfs.h |  1 +
 2 files changed, 29 insertions(+)

diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 8adc02e9..a0aa357a 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -214,6 +214,34 @@ char *igt_debugfs_path(int device, char *path, int pathlen)
 	return path;
 }
 
+/**
+ * igt_debugfs_is_file_exists:
+ * @device: fd of the device
+ * @filename: name of the debugfs node to open
+ *
+ * This checks if the file exists in debugfs. The filename should be
+ * relative to the drm device's root, i.e. without "drm/$minor".
+ *
+ * Returns:
+ * The true if the file exists, otherwise false.
+ */
+bool igt_debugfs_is_file_exists(int device, const char *filename)
+{
+	struct stat buffer;
+	char path[256];
+	bool exists = false;
+
+	if (!igt_debugfs_path(device, path, sizeof(path)))
+		return false;
+
+	sprintf(path, "%s/%s", path, filename);
+
+	exists = stat(path, &buffer) == 0;
+	igt_debug("File %s %s exists\n", path, exists ? "is" : "is not");
+
+	return exists;
+}
+
 /**
  * igt_debugfs_dir:
  * @device: fd of the device
diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h
index 8d25abfe..ec91800e 100644
--- a/lib/igt_debugfs.h
+++ b/lib/igt_debugfs.h
@@ -33,6 +33,7 @@ enum pipe;
 
 const char *igt_debugfs_mount(void);
 char *igt_debugfs_path(int device, char *path, int pathlen);
+bool igt_debugfs_is_file_exists(int device, const char *filename);
 
 int igt_debugfs_dir(int device);
 
-- 
2.14.3



More information about the igt-dev mailing list