Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Aravind Iddamsetty <aravind.iddamsetty@linux.intel.com>
To: Riana Tauro <riana.tauro@intel.com>, igt-dev@lists.freedesktop.org
Cc: anshuman.gupta@intel.com, lucas.demarchi@intel.com,
	rodrigo.vivi@intel.com, kamil.konieczny@linux.intel.com,
	louis.chauvet@bootlin.com,
	"José Expósito" <jose.exposito89@gmail.com>
Subject: Re: [PATCH i-g-t 4/5] lib/igt_fs: Add helper functions to create and remove directories
Date: Mon, 5 May 2025 11:05:44 +0530	[thread overview]
Message-ID: <ed0f7ca6-debe-4299-ac9e-6c9718683287@linux.intel.com> (raw)
In-Reply-To: <20250422095602.55041-5-riana.tauro@intel.com>


On 22-04-2025 15:26, Riana Tauro wrote:
> Add helper function to create directory and return fd of
> the created directory. Also add a function to remove
> directories. This will be used by configfs
>
> Cc: Louis Chauvet <louis.chauvet@bootlin.com>
> Cc: José Expósito <jose.exposito89@gmail.com>
> Signed-off-by: Riana Tauro <riana.tauro@intel.com>
> ---
>  lib/igt_fs.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
>  lib/igt_fs.h |  2 ++
>  2 files changed, 50 insertions(+)
>
> diff --git a/lib/igt_fs.c b/lib/igt_fs.c
> index f6a2530cd..1fa281315 100644
> --- a/lib/igt_fs.c
> +++ b/lib/igt_fs.c
> @@ -21,8 +21,10 @@
>   * IN THE SOFTWARE.
>   *
>   */
> +#include <sys/stat.h>
>  
>  #include <errno.h>
> +#include <fcntl.h>
>  #include <stdlib.h>
>  #include <unistd.h>
>  
> @@ -94,3 +96,49 @@ ssize_t igt_writen(int fd, const char *buf, size_t len)
>  	} while (total != len);
>  	return total ?: ret;
>  }
> +
> +/**
> + * igt_fs_create_dir: creates and opens directory
> + * @fd: file descriptor of parent directory
> + * @name: name of the directory to create
> + * @mode: permissions for the directory
> + *
> + * creates a directory under parent directory and returns
> + * the fd
> + *
> + * Returns: directory fd on success, -errno otherwise
> + */
> +int igt_fs_create_dir(int fd, const char *name, mode_t mode)
> +{
> +	int ret;
> +	int dirfd;
> +
> +	ret = mkdirat(fd, name, mode);
> +	if (ret)
> +		return -errno;
> +
> +	dirfd = openat(fd, name, O_DIRECTORY);
> +	if (dirfd < 0)
> +		return -errno;
> +
> +	return dirfd;
> +}
> +
> +/**
> + * igt_fs_remove_directory: removes directory
> + * @fd: fd of parent directory
> + * @name: name of directory to remove
> + *
> + * removes directory under parent directory
> + *
> + * Returns: 0 on success, -errno otherwise
> + */
> +int igt_fs_remove_dir(int fd, const char *name)
> +{
> +	int ret = unlinkat(fd, name, AT_REMOVEDIR);
> +
> +	if (ret)
> +		return -errno;
> +
> +	return 0;
> +}
> diff --git a/lib/igt_fs.h b/lib/igt_fs.h
> index 84c3fed62..ee3e7593b 100644
> --- a/lib/igt_fs.h
> +++ b/lib/igt_fs.h
> @@ -27,6 +27,8 @@
>  
>  #include <stdio.h>
>  
> +int igt_fs_create_dir(int fd, const char *name, mode_t mode);
> +int igt_fs_remove_dir(int fd, const char *name);
>  ssize_t igt_readn(int fd, char *buf, size_t len);
>  ssize_t igt_writen(int fd, const char *buf, size_t len);

LGTM.

Reviewed-by: Aravind Iddamsetty <aravind.iddamsetty@linux.intel.com>

Thanks,
Aravind.
>  

  reply	other threads:[~2025-05-05  5:35 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-22  9:55 [PATCH i-g-t 0/5] Add test to validate survivability mode Riana Tauro
2025-04-22  9:55 ` [PATCH i-g-t 1/5] lib/igt_aux: Move is_mountpoint() to igt_aux Riana Tauro
2025-04-22  9:55 ` [PATCH i-g-t 2/5] lib/igt_configfs: Add helper to mount configfs Riana Tauro
2025-05-05  5:35   ` Aravind Iddamsetty
2025-05-07 11:05   ` José Expósito
2025-05-07 15:57   ` Kamil Konieczny
2025-04-22  9:55 ` [PATCH i-g-t 3/5] lib/igt_fs: Rename igt_io to igt_fs to add additional helpers Riana Tauro
2025-05-05  5:35   ` Aravind Iddamsetty
2025-05-07 11:08   ` José Expósito
2025-05-07 15:58   ` Kamil Konieczny
2025-04-22  9:56 ` [PATCH i-g-t 4/5] lib/igt_fs: Add helper functions to create and remove directories Riana Tauro
2025-05-05  5:35   ` Aravind Iddamsetty [this message]
2025-05-07 13:31   ` José Expósito
2025-05-07 15:48   ` Kamil Konieczny
2025-04-22  9:56 ` [PATCH i-g-t 5/5] tests/intel/xe_configfs: Add test to validate survivability mode Riana Tauro
2025-04-22 13:57   ` Lucas De Marchi
2025-04-22 19:29     ` Rodrigo Vivi
2025-04-24  4:17       ` Lucas De Marchi
2025-04-24  5:41         ` Riana Tauro
2025-05-12 10:54           ` Riana Tauro
2025-05-12 14:50             ` Lucas De Marchi
2025-04-24 13:00         ` Rodrigo Vivi
2025-05-05  7:08   ` Aravind Iddamsetty
2025-05-13  5:25     ` Riana Tauro
2025-04-22 19:51 ` ✓ i915.CI.BAT: success for Add test to validate survivability mode (rev2) Patchwork
2025-04-23  1:36 ` ✗ Xe.CI.Full: failure " Patchwork
2025-04-23  5:57 ` ✗ i915.CI.Full: " Patchwork
2025-04-23 21:59 ` ✓ Xe.CI.BAT: success " Patchwork
2025-04-24  9:51 ` ✗ Xe.CI.Full: failure " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ed0f7ca6-debe-4299-ac9e-6c9718683287@linux.intel.com \
    --to=aravind.iddamsetty@linux.intel.com \
    --cc=anshuman.gupta@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=jose.exposito89@gmail.com \
    --cc=kamil.konieczny@linux.intel.com \
    --cc=louis.chauvet@bootlin.com \
    --cc=lucas.demarchi@intel.com \
    --cc=riana.tauro@intel.com \
    --cc=rodrigo.vivi@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox