[PATCH 08/18] nfs: add readlink support

Sascha Hauer s.hauer at pengutronix.de
Mon Aug 27 10:04:13 EDT 2012


On Fri, Aug 24, 2012 at 06:50:08AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
> ---
>  fs/nfs.c |   93 +++++++++++++++++++++++++++++++++++++++++++-------------------
>  1 file changed, 65 insertions(+), 28 deletions(-)
> 
> diff --git a/fs/nfs.c b/fs/nfs.c
> index 79e667f..a4e1f91 100644
> --- a/fs/nfs.c
> +++ b/fs/nfs.c
> @@ -605,34 +605,6 @@ static int nfs_read_req(struct file_priv *priv, int offset, int readlen)
>  	return 0;
>  }
>  
> @@ -742,6 +714,70 @@ static struct file_priv *nfs_do_stat(struct device_d *dev, const char *filename,
>  	return priv;
>  }
>  
> +static int nfs_readlink_req(struct file_priv *priv, char* buf, size_t size)
> +{
> +	uint32_t data[1024];
> +	uint32_t *p;
> +	int len;
> +	int ret;
> +	char *path;
> +	uint32_t *filedata;
> +
> +	p = &(data[0]);
> +	p = rpc_add_credentials(p);
> +
> +	memcpy(p, priv->filefh, NFS_FHSIZE);
> +	p += (NFS_FHSIZE / 4);
> +
> +	len = p - &(data[0]);
> +
> +	ret = rpc_req(priv->npriv, PROG_NFS, NFS_READLINK, data, len);
> +	if (ret)
> +		return ret;
> +
> +	filedata = nfs_packet + sizeof(struct rpc_reply);
> +	filedata++;
> +
> +	len = ntohl(net_read_uint32(filedata)); /* new path length */
> +	filedata++;
> +
> +	path = (char *)filedata;
> +
> +	if (len > size)
> +		len = size;
> +
> +	memcpy(buf, path, len);
> +	buf[len] = 0;

You write past the buffer here.

> +
> +	return 0;
> +}
> +
> +static int nfs_readlink(struct device_d *dev, const char *filename,
> +			char *realname, size_t size)
> +{
> +	struct file_priv *priv;
> +	int ret;
> +	struct stat s;
> +
> +	priv = nfs_do_stat(dev, filename, &s);
> +	if (IS_ERR(priv))
> +		return PTR_ERR(priv);
> +
> +

unnecessary blank line.

> +	if (S_ISDIR(s.st_mode))
> +		strcat(realname, filename);
> +	else
> +		strcat(realname, dirname((char*)filename));

What do you expect to be in realname?

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