[PATCH 3/4] fs: Implement links to directories

Sascha Hauer s.hauer at pengutronix.de
Thu May 11 12:34:36 PDT 2017


On Thu, May 11, 2017 at 11:11:00AM +0200, Sascha Hauer wrote:
> So far links can only point to files. Implement links to
> directories. With this all kinds of links are supported:
> 
> - relative links
> - absolute links
> - links including ".."
> - link loops (are detected, return -EMLINK)
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
>  commands/readlink.c |   2 +-
>  fs/fs.c             | 272 +++++++++++++++++++++++++++++-----------------------
>  include/fs.h        |   3 +-
>  3 files changed, 157 insertions(+), 120 deletions(-)
> 
> diff --git a/commands/readlink.c b/commands/readlink.c
> index 4ac576f16f..a19c8e0041 100644
> --- a/commands/readlink.c
> +++ b/commands/readlink.c

[...]

  
>  int stat(const char *filename, struct stat *s)
>  {
> -	char *f;
> +	char *path = canonicalize_path(filename);
> +	int ret;
>  
> -	f = realfile(filename, s);
> -	if (IS_ERR(f))
> -		return PTR_ERR(f);
> +	if (IS_ERR(path))
> +		return PTR_ERR(path);
>  
> -	free(f);
> -	return 0;
> +	ret = lstat(path, s);
> +
> +	free(path);
> +
> +	return ret;
>  }

The following is missing in this patch, it slipped into a debug
patch I removed from this series:

int lstat(const char *filename, struct stat *s)
{
	char *f = canonicalize_dir(filename);
	int ret;

	if (IS_ERR(f))
		return PTR_ERR(f);

	ret = __lstat(f, s);

	free(f);

	return ret;
}

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list