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

Chris Wilson chris at chris-wilson.co.uk
Tue Apr 10 14:02:40 UTC 2018


Quoting Piotr Piórkowski (2018-04-10 14:52:26)
> 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:

is_file_exists?

	igt_debugfs_file_exists
or
	igt_debugfs_has_filename

> + * @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)
> +{
	bool exists;
	int dir;

	dir = igt_debugfs_dir(device);
	exists = faccessat(dir, filename, F_OK, 0) == 0;
	close(dir);

	return exists;
}


More information about the igt-dev mailing list