[PATCH 07/18] ramfs: add symlink and readlink support

Jean-Christophe PLAGNIOL-VILLARD plagnioj at jcrosoft.com
Wed Aug 29 01:21:29 EDT 2012


On 15:59 Mon 27 Aug     , Sascha Hauer wrote:
> On Fri, Aug 24, 2012 at 06:50:07AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
> > ---
> >  fs/ramfs.c |   53 ++++++++++++++++++++++++++++++++++++++++++++++-------
> >  1 file changed, 46 insertions(+), 7 deletions(-)
> > 
> > diff --git a/fs/ramfs.c b/fs/ramfs.c
> > index 91d06b8..38da593 100644
> > --- a/fs/ramfs.c
> > +++ b/fs/ramfs.c
> > @@ -42,6 +42,7 @@ struct ramfs_inode {
> >  	struct ramfs_inode *parent;
> >  	struct ramfs_inode *next;
> >  	struct ramfs_inode *child;
> > +	char *symlink;
> >  	ulong mode;
> >  
> >  	struct handle_d *handle;
> > @@ -176,6 +177,7 @@ static void ramfs_put_inode(struct ramfs_inode *node)
> >  		data = tmp;
> >  	}
> >  
> > +	free(node->symlink);
free here
> >  	free(node->name);
> >  	free(node);
> >  }
> > @@ -212,18 +214,28 @@ static struct ramfs_inode* node_insert(struct ramfs_inode *parent_node, const ch
> >  
> >  /* ---------------------------------------------------------------*/
> >  
> > -static int ramfs_create(struct device_d *dev, const char *pathname, mode_t mode)
> > +static int __ramfs_create(struct device_d *dev, const char *pathname,
> > +			  mode_t mode, const char *symlink)
> >  {
> >  	struct ramfs_priv *priv = dev->priv;
> >  	struct ramfs_inode *node;
> >  	char *file;
> >  
> >  	node = rlookup_parent(priv, pathname, &file);
> > -	if (node) {
> > -		node_insert(node, file, mode);
> > -		return 0;
> > -	}
> > -	return -ENOENT;
> > +	if (!node)
> > +		return -ENOENT;
> > +
> > +	node = node_insert(node, file, mode);
> > +	if (!node)
> > +		return -ENOMEM;
> > +	node->symlink = strdup(symlink);
> 
> Either check for errors or use xstrdup.
no I do not want to use x... stuff on ramfs
it need to work evenof no memory
> 
> > +
> > +	return 0;
> > +}
> > +
> > +static int ramfs_create(struct device_d *dev, const char *pathname, mode_t mode)
> > +{
> > +	return __ramfs_create(dev, pathname, mode, NULL);
> >  }
> >  
> >  static int ramfs_unlink(struct device_d *dev, const char *pathname)
> > @@ -532,12 +544,37 @@ static int ramfs_stat(struct device_d *dev, const char *filename, struct stat *s
> >  	if (!node)
> >  		return -ENOENT;
> >  
> > -	s->st_size = node->size;
> > +	s->st_size = node->symlink ? strlen(node->symlink) : node->size;
> >  	s->st_mode = node->mode;
> >  
> >  	return 0;
> >  }
> >  
> > +static int ramfs_symlink(struct device_d *dev, const char *pathname,
> > +		       const char *newpath)
> > +{
> > +	mode_t mode = S_IFLNK | S_IRWXU | S_IRWXG | S_IRWXO;
> > +
> > +	return __ramfs_create(dev, newpath, mode, pathname);
> > +}
> > +
> > +static int ramfs_readlink(struct device_d *dev, const char *pathname,
> > +			char *buf, size_t bufsiz)
> > +{
> > +	struct ramfs_priv *priv = dev->priv;
> > +	struct ramfs_inode *node = rlookup(priv, pathname);
> > +	int len;
> > +
> > +	if (!node || !node->symlink)
> > +		return -ENOENT;
> > +
> > +	len = min(bufsiz, strlen(node->symlink));
> > +
> > +	strncat(buf, node->symlink, len);
> 
> You append to buf? What do you expect to be in there? I think memcpy
> would be more appropriate here.
yeap we can use memcpy
> 
> I see no code freeing node->symlink in this patch.
upper

Best Regards,
J.
> 
> 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