diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2018-02-08 09:04:27 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2018-02-08 09:04:27 +0100 |
commit | 0dce5375d799e727bd1aa5ccdb28156d9bcd4d17 (patch) | |
tree | e1c6dd036a69ab954616219dfa0cee8312bb43f8 /fs | |
parent | 6f826bfe45298721a92bbe93d32a6a0eb76d46ee (diff) | |
parent | 74cdc34323ee23b9b195866c56699e268f05841a (diff) | |
download | barebox-0dce5375d799e727bd1aa5ccdb28156d9bcd4d17.tar.gz barebox-0dce5375d799e727bd1aa5ccdb28156d9bcd4d17.tar.xz |
Merge branch 'for-next/tftp-workaround'
Diffstat (limited to 'fs')
-rw-r--r-- | fs/fs.c | 22 | ||||
-rw-r--r-- | fs/uimagefs.c | 37 |
2 files changed, 35 insertions, 24 deletions
@@ -1914,3 +1914,25 @@ char *path_get_linux_rootarg(const char *path) return xstrdup(str); } + +/** + * __is_tftp_fs() - return true when path is mounted on TFTP + * @path: The path + * + * Do not use directly, use is_tftp_fs instead. + * + * Return: true when @path is on TFTP, false otherwise + */ +bool __is_tftp_fs(const char *path) +{ + struct fs_device_d *fsdev; + + fsdev = get_fsdevice_by_path(path); + if (!fsdev) + return false; + + if (strcmp(fsdev->driver->drv.name, "tftp")) + return false; + + return true; +} 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; |