[PATCH 2/2] fs: Don't bother filesystems without link support with additional stat() calls

Sascha Hauer s.hauer at pengutronix.de
Tue Sep 5 01:00:21 PDT 2017


In __canonicalize_path() we only call stat() to know if the path
is a link or not. When the filesystem doesn't support links we
already know that it's not a link, so we do not need to call stat().
This helps the tftp filesystem since the parent directories of
a file to be opened won't be stat()ed anymore, something tftp
does not support.

Fixes: a602bebc fs: Implement links to directories

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 fs/fs.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/fs/fs.c b/fs/fs.c
index a5efdd1423..f61ee091b5 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -145,6 +145,7 @@ char *normalise_path(const char *pathname)
 EXPORT_SYMBOL(normalise_path);
 
 static int __lstat(const char *filename, struct stat *s);
+static struct fs_device_d *get_fsdevice_by_path(const char *path);
 
 static char *__canonicalize_path(const char *_pathname, int level)
 {
@@ -167,6 +168,7 @@ static char *__canonicalize_path(const char *_pathname, int level)
 		char *p = strsep(&path, "/");
 		char *tmp;
 		char link[PATH_MAX] = {};
+		struct fs_device_d *fsdev;
 
 		if (!p)
 			break;
@@ -185,6 +187,14 @@ static char *__canonicalize_path(const char *_pathname, int level)
 		free(outpath);
 		outpath = tmp;
 
+		/*
+		 * Don't bother filesystems without link support
+		 * with an additional stat() call.
+		 */
+		fsdev = get_fsdevice_by_path(outpath);
+		if (!fsdev->driver->readlink)
+			continue;
+
 		ret = __lstat(outpath, &s);
 		if (ret)
 			goto out;
-- 
2.11.0




More information about the barebox mailing list