[PATCH 03/18] fs: add symlink support
Jean-Christophe PLAGNIOL-VILLARD
plagnioj at jcrosoft.com
Sat Sep 1 06:42:30 EDT 2012
On 15:35 Mon 27 Aug , Sascha Hauer wrote:
> On Fri, Aug 24, 2012 at 06:50:03AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > Limit it's support to existing file only
> >
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
> > ---
> > fs/fs.c | 43 +++++++++++++++++++++++++++++++++++++++++++
> > include/fs.h | 4 ++++
> > 2 files changed, 47 insertions(+)
> >
> > diff --git a/fs/fs.c b/fs/fs.c
> > index c950054..a19e1f4 100644
> > --- a/fs/fs.c
> > +++ b/fs/fs.c
> > @@ -949,6 +949,49 @@ out:
> > }
> > EXPORT_SYMBOL(readlink);
> >
> > +int symlink(const char *pathname, const char *newpath)
> > +{
> > + struct fs_driver_d *fsdrv;
> > + struct fs_device_d *fsdev;
> > + char *p = normalise_path(pathname);
> > + int ret;
> > + struct stat s;
> > +
> > + if (!stat(p, &s) && S_ISDIR(s.st_mode)) {
> > + ret = -ENOSYS;
> > + goto out;
>
> You lose the memory allocated in normalise_path here.
yeap forget to put the free in out
>
> > + }
> > +
> > + free(p);
> > + p = normalise_path(newpath);
>
> p is never freed again.
>
> > +
> > + ret = stat(p, &s);
> > + if (!ret) {
> > + ret = -EEXIST;
> > + goto out;
> > + }
> > +
> > + fsdev = get_fs_device_and_root_path(&p);
> > + if (!fsdev) {
> > + ret = -ENODEV;
> > + goto out;
> > + }
> > + fsdrv = fsdev->driver;
> > +
> > + if (fsdrv->symlink) {
> > + ret = fsdrv->symlink(&fsdev->dev, pathname, p);
> > + } else {
> > + ret = -EROFS;
>
> Better:
>
> EPERM The file system containing newpath does not support the creation of symbolic links.
ok
Best Regards,
J.
More information about the barebox
mailing list