[igt-dev] [PATCH v2 1/2] lib/igt_debugfs: Add function to check if file exists in debugfs
Piotr Piorkowski
piotr.piorkowski at intel.com
Tue Apr 24 07:50:03 UTC 2018
From: Piotr Piórkowski <piotr.piorkowski at intel.com>
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.
v2:
- rename function (Chris)
- modify function (Chris)
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>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
---
lib/igt_debugfs.c | 25 +++++++++++++++++++++++++
lib/igt_debugfs.h | 1 +
2 files changed, 26 insertions(+)
diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 8adc02e9..d49a83e3 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -214,6 +214,31 @@ char *igt_debugfs_path(int device, char *path, int pathlen)
return path;
}
+/**
+ * igt_debugfs_has_filename:
+ * @device: fd of the device
+ * @filename: name of the debugfs node to open
+ *
+ * This checks if the debugfs has filename. 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_has_filename(int device, const char *filename)
+{
+ bool exists = false;
+ int dir;
+
+ dir = igt_debugfs_dir(device);
+ exists = faccessat(dir, filename, F_OK, 0) == 0;
+ close(dir);
+
+ igt_debug("File %s %s exists\n", filename, 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..d3b274af 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_has_filename(int device, const char *filename);
int igt_debugfs_dir(int device);
--
2.14.3
More information about the igt-dev
mailing list