mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 7/8] fs/uimagefs: Use is_tftp_fs() and cache_file() to ease TFTP workaround
Date: Thu, 25 Jan 2018 08:45:19 +0100	[thread overview]
Message-ID: <20180125074520.10320-8-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20180125074520.10320-1-s.hauer@pengutronix.de>

We have helper functions now to ease file caching when a file
is on TFTP. Use them.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/uimagefs.c      | 37 +++++++++++++------------------------
 include/uimagefs.h |  2 +-
 2 files changed, 14 insertions(+), 25 deletions(-)

diff --git a/fs/uimagefs.c b/fs/uimagefs.c
index c0c5750c2c..c120944a46 100644
--- a/fs/uimagefs.c
+++ b/fs/uimagefs.c
@@ -196,7 +196,6 @@ static void uimagefs_remove(struct device_d *dev)
 {
 	struct uimagefs_handle *priv = dev->priv;
 	struct uimagefs_handle_data *d, *tmp;
-	struct stat s;
 
 	list_for_each_entry_safe(d, tmp, &priv->list, list) {
 		free(d->name);
@@ -204,10 +203,11 @@ static void uimagefs_remove(struct device_d *dev)
 		free(d);
 	}
 
-	if (IS_BUILTIN(CONFIG_FS_TFTP) && !stat(priv->tmp, &s))
-		unlink(priv->tmp);
+	if (priv->copy) {
+		unlink(priv->copy);
+		free(priv->copy);
+	}
 
-	free(priv->tmp);
 	free(priv);
 }
 
@@ -363,28 +363,21 @@ static int __uimage_open(struct uimagefs_handle *priv)
 	int ret;
 	size_t offset = 0;
 	size_t data_offset = 0;
+	const char *filename = priv->filename;
+
+	if (is_tftp_fs(filename)) {
+		ret = cache_file(filename, &priv->copy);
+		if (ret)
+			return ret;
+		filename = priv->copy;
+	}
 
-again:
-	fd = open(priv->filename, O_RDONLY);
+	fd = open(filename, O_RDONLY);
 	if (fd < 0) {
 		printf("could not open: %s\n", errno_str());
 		return fd;
 	}
 
-	/*
-	 * Hack around tftp fs. We need lseek for uImage support, but
-	 * this cannot be implemented in tftp fs, so we detect this
-	 * and copy the file to ram if it fails
-	 */
-	if (IS_BUILTIN(CONFIG_FS_TFTP) && !can_lseek_backward(fd)) {
-		close(fd);
-		ret = copy_file(priv->filename, priv->tmp, 0);
-		if (ret)
-			return ret;
-		priv->filename = priv->tmp;
-		goto again;
-	}
-
 	header = &priv->header;
 
 	ret = read(fd, header, sizeof(*header));
@@ -514,10 +507,6 @@ static int uimagefs_probe(struct device_d *dev)
 	priv->filename = fsdev->backingstore;
 	dev_dbg(dev, "mount: %s\n", fsdev->backingstore);
 
-	if (IS_BUILTIN(CONFIG_FS_TFTP))
-		priv->tmp = basprintf("/.uImage_tmp_%08x",
-					crc32(0, fsdev->path, strlen(fsdev->path)));
-
 	ret = __uimage_open(priv);
 	if (ret)
 		goto err;
diff --git a/include/uimagefs.h b/include/uimagefs.h
index 81b32310ad..3f58589b73 100644
--- a/include/uimagefs.h
+++ b/include/uimagefs.h
@@ -45,7 +45,7 @@ struct uimagefs_handle {
 	struct image_header header;
 	int nb_data_entries;
 	char *filename;
-	char *tmp;
+	char *copy;
 
 	struct list_head list;
 };
-- 
2.15.1


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

  parent reply	other threads:[~2018-01-25  7:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-25  7:45 [PATCH v2 0/8] Make TFTP detection more convenient Sascha Hauer
2018-01-25  7:45 ` [PATCH 1/8] startup: create /tmp Sascha Hauer
2018-01-25  7:45 ` [PATCH 2/8] fs: implement is_tftp_fs() Sascha Hauer
2018-01-25  7:45 ` [PATCH 3/8] libfile: implement make_temp Sascha Hauer
2018-01-25  7:45 ` [PATCH 4/8] libfile: implement a function to cache a file Sascha Hauer
2018-01-25  7:45 ` [PATCH 5/8] uimage: fix memory leak in error path Sascha Hauer
2018-01-25  7:45 ` [PATCH 6/8] uimage: Use is_tftp_fs() and cache_file() to ease TFTP workaround Sascha Hauer
2018-01-25  7:45 ` Sascha Hauer [this message]
2018-01-25  7:45 ` [PATCH 8/8] fs: remove now unused function can_lseek_backward() Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180125074520.10320-8-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox