summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2012-08-17 00:48:35 +0800
committerJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2012-09-05 03:22:13 +0800
commit2f17f1a22f112bbc1eaa179914f0e5069f2a5ba2 (patch)
treeea01af61b64eab01851e3aeec8138eb0fe41ee1b /fs
parent5b1583d994c0e63b4588a75b631011e2bf41bab8 (diff)
downloadbarebox-2f17f1a22f112bbc1eaa179914f0e5069f2a5ba2.tar.gz
barebox-2f17f1a22f112bbc1eaa179914f0e5069f2a5ba2.tar.xz
fs: add readlink support
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/fs.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/fs/fs.c b/fs/fs.c
index 0b376a544b..6a855130a1 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -890,6 +890,43 @@ int close(int fd)
}
EXPORT_SYMBOL(close);
+int readlink(const char *pathname, char *buf, size_t bufsiz)
+{
+ struct fs_driver_d *fsdrv;
+ struct fs_device_d *fsdev;
+ char *p = normalise_path(pathname);
+ char *freep = p;
+ int ret;
+
+ ret = path_check_prereq(pathname, S_IFLNK);
+ if (ret)
+ goto out;
+
+ fsdev = get_fs_device_and_root_path(&p);
+ if (!fsdev) {
+ ret = -ENODEV;
+ goto out;
+ }
+ fsdrv = fsdev->driver;
+
+ if (fsdrv->readlink)
+ ret = fsdrv->readlink(&fsdev->dev, p, buf, bufsiz);
+ else
+ ret = -ENOSYS;
+
+ if (ret)
+ goto out;
+
+out:
+ free(freep);
+
+ if (ret)
+ errno = -ret;
+
+ return ret;
+}
+EXPORT_SYMBOL(readlink);
+
static int fs_match(struct device_d *dev, struct driver_d *drv)
{
return strcmp(dev->name, drv->name) ? -1 : 0;