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

Chris Wilson chris at chris-wilson.co.uk
Tue Apr 24 08:27:34 UTC 2018


Quoting Piotr Piorkowski (2018-04-24 08:50:03)
> 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");

Nah, such a message will quickly get tedious. The function is a
predicate is a predicate for the caller to decide what action to take;
that is where the interesting information will be, not this.
-Chris


More information about the igt-dev mailing list