mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* Fix tftpd-hpa support
@ 2017-09-05  8:00 Sascha Hauer
  2017-09-05  8:00 ` [PATCH 1/2] fs: avoid pathes with '//' in __canonicalize_path() Sascha Hauer
  2017-09-05  8:00 ` [PATCH 2/2] fs: Don't bother filesystems without link support with additional stat() calls Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Sascha Hauer @ 2017-09-05  8:00 UTC (permalink / raw)
  To: Barebox List; +Cc: Dennis Menschel

Downloading files from a tftpd-hpa server is broken when the files
are in subdirectories since the introduction of links to directories
in a602bebc ('fs: Implement links to directories'). This series fixes
this.

Sascha

----------------------------------------------------------------
Sascha Hauer (2):
      fs: avoid pathes with '//' in __canonicalize_path()
      fs: Don't bother filesystems without link support with additional stat() calls

 fs/fs.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] fs: avoid pathes with '//' in __canonicalize_path()
  2017-09-05  8:00 Fix tftpd-hpa support Sascha Hauer
@ 2017-09-05  8:00 ` Sascha Hauer
  2017-09-05  8:00 ` [PATCH 2/2] fs: Don't bother filesystems without link support with additional stat() calls Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2017-09-05  8:00 UTC (permalink / raw)
  To: Barebox List; +Cc: Dennis Menschel

In __canonicalize_path pathes beginning with '//' can occur. This
is normally not a problem since normalize_path() will clean this
up, but it means we cannot call get_fsdevice_by_path() on these
pathes in this function, as needed in the next patch.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/fs.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index c9226f9ba6..a5efdd1423 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -158,8 +158,8 @@ static char *__canonicalize_path(const char *_pathname, int level)
 
 	path = freep = xstrdup(_pathname);
 
-	if (*path == '/')
-		outpath = xstrdup("/");
+	if (*path == '/' || !strcmp(cwd, "/"))
+		outpath = xstrdup("");
 	else
 		outpath = __canonicalize_path(cwd, level + 1);
 
@@ -212,6 +212,11 @@ static char *__canonicalize_path(const char *_pathname, int level)
 out:
 	free(freep);
 
+	if (!*outpath) {
+		free(outpath);
+		outpath = xstrdup("/");
+	}
+
 	return outpath;
 }
 
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] fs: Don't bother filesystems without link support with additional stat() calls
  2017-09-05  8:00 Fix tftpd-hpa support Sascha Hauer
  2017-09-05  8:00 ` [PATCH 1/2] fs: avoid pathes with '//' in __canonicalize_path() Sascha Hauer
@ 2017-09-05  8:00 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2017-09-05  8:00 UTC (permalink / raw)
  To: Barebox List; +Cc: Dennis Menschel

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@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


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-09-05  8:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-05  8:00 Fix tftpd-hpa support Sascha Hauer
2017-09-05  8:00 ` [PATCH 1/2] fs: avoid pathes with '//' in __canonicalize_path() Sascha Hauer
2017-09-05  8:00 ` [PATCH 2/2] fs: Don't bother filesystems without link support with additional stat() calls Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox