mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2] uimage: fix: add can_lseek_backward and use in uimage_open
@ 2017-11-08 18:07 Michael Grzeschik
  2017-11-10  7:01 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Grzeschik @ 2017-11-08 18:07 UTC (permalink / raw)
  To: barebox

Since commit ce0cc7fe we support forward seek on tftpfs. This feature
breaks the condition to check rather we open an uimage over tftp. Since
backward seeking is the problem here, we add the function
can_lseek_backward and check for it instead of the simple lseek.

Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
---
v1 -> v2: - added can_lseek_backward
          - also fixed check in uimagefs
          - aligned comments to check

common/uimage.c |  4 ++--
 fs/uimagefs.c   |  4 ++--
 include/fs.h    | 20 ++++++++++++++++++++
 3 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/common/uimage.c b/common/uimage.c
index 28a25bba2d..b6f0f109ca 100644
--- a/common/uimage.c
+++ b/common/uimage.c
@@ -111,9 +111,9 @@ again:
 	/*
 	 * Hack around tftp fs. We need lseek for uImage support, but
 	 * this cannot be implemented in tftp fs, so we detect this
-	 * by doing a test lseek and copy the file to ram if it fails
+	 * and copy the file to ram if it fails
 	 */
-	if (IS_BUILTIN(CONFIG_FS_TFTP) && lseek(fd, 0, SEEK_SET)) {
+	if (IS_BUILTIN(CONFIG_FS_TFTP) && !can_lseek_backward(fd)) {
 		close(fd);
 		ret = copy_file(filename, uimage_tmp, 0);
 		if (ret)
diff --git a/fs/uimagefs.c b/fs/uimagefs.c
index 13c1fbac05..c0c5750c2c 100644
--- a/fs/uimagefs.c
+++ b/fs/uimagefs.c
@@ -374,9 +374,9 @@ again:
 	/*
 	 * Hack around tftp fs. We need lseek for uImage support, but
 	 * this cannot be implemented in tftp fs, so we detect this
-	 * by doing a test lseek and copy the file to ram if it fails
+	 * and copy the file to ram if it fails
 	 */
-	if (IS_BUILTIN(CONFIG_FS_TFTP) && lseek(fd, 0, SEEK_SET)) {
+	if (IS_BUILTIN(CONFIG_FS_TFTP) && !can_lseek_backward(fd)) {
 		close(fd);
 		ret = copy_file(priv->filename, priv->tmp, 0);
 		if (ret)
diff --git a/include/fs.h b/include/fs.h
index d7fa7714b4..f8a3b8bda4 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -100,6 +100,26 @@ struct fs_device_d {
 	char *linux_rootarg;
 };
 
+/*
+ * Some filesystems i.e. tftpfs only support lseek into one direction.
+ * To detect this limited functionality we add this extra function.
+ * Additionaly we also return 0 if we even can not seek forward.
+ */
+static inline int can_lseek_backward(int fd)
+{
+	int ret;
+
+	ret = lseek(fd, 1, SEEK_SET);
+	if (ret < 0)
+		return 0;
+
+	ret = lseek(fd, 0, SEEK_SET);
+	if (ret < 0)
+		return 0;
+
+	return ret;
+}
+
 #define drv_to_fs_driver(d) container_of(d, struct fs_driver_d, drv)
 
 int flush(int fd);
-- 
2.11.0


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

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

* Re: [PATCH v2] uimage: fix: add can_lseek_backward and use in uimage_open
  2017-11-08 18:07 [PATCH v2] uimage: fix: add can_lseek_backward and use in uimage_open Michael Grzeschik
@ 2017-11-10  7:01 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2017-11-10  7:01 UTC (permalink / raw)
  To: Michael Grzeschik; +Cc: barebox

On Wed, Nov 08, 2017 at 07:07:47PM +0100, Michael Grzeschik wrote:
> Since commit ce0cc7fe we support forward seek on tftpfs. This feature
> breaks the condition to check rather we open an uimage over tftp. Since
> backward seeking is the problem here, we add the function
> can_lseek_backward and check for it instead of the simple lseek.
> 
> Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
> ---
> v1 -> v2: - added can_lseek_backward
>           - also fixed check in uimagefs
>           - aligned comments to check
> 
> common/uimage.c |  4 ++--
>  fs/uimagefs.c   |  4 ++--
>  include/fs.h    | 20 ++++++++++++++++++++
>  3 files changed, 24 insertions(+), 4 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/common/uimage.c b/common/uimage.c
> index 28a25bba2d..b6f0f109ca 100644
> --- a/common/uimage.c
> +++ b/common/uimage.c
> @@ -111,9 +111,9 @@ again:
>  	/*
>  	 * Hack around tftp fs. We need lseek for uImage support, but
>  	 * this cannot be implemented in tftp fs, so we detect this
> -	 * by doing a test lseek and copy the file to ram if it fails
> +	 * and copy the file to ram if it fails
>  	 */
> -	if (IS_BUILTIN(CONFIG_FS_TFTP) && lseek(fd, 0, SEEK_SET)) {
> +	if (IS_BUILTIN(CONFIG_FS_TFTP) && !can_lseek_backward(fd)) {
>  		close(fd);
>  		ret = copy_file(filename, uimage_tmp, 0);
>  		if (ret)
> diff --git a/fs/uimagefs.c b/fs/uimagefs.c
> index 13c1fbac05..c0c5750c2c 100644
> --- a/fs/uimagefs.c
> +++ b/fs/uimagefs.c
> @@ -374,9 +374,9 @@ again:
>  	/*
>  	 * Hack around tftp fs. We need lseek for uImage support, but
>  	 * this cannot be implemented in tftp fs, so we detect this
> -	 * by doing a test lseek and copy the file to ram if it fails
> +	 * and copy the file to ram if it fails
>  	 */
> -	if (IS_BUILTIN(CONFIG_FS_TFTP) && lseek(fd, 0, SEEK_SET)) {
> +	if (IS_BUILTIN(CONFIG_FS_TFTP) && !can_lseek_backward(fd)) {
>  		close(fd);
>  		ret = copy_file(priv->filename, priv->tmp, 0);
>  		if (ret)
> diff --git a/include/fs.h b/include/fs.h
> index d7fa7714b4..f8a3b8bda4 100644
> --- a/include/fs.h
> +++ b/include/fs.h
> @@ -100,6 +100,26 @@ struct fs_device_d {
>  	char *linux_rootarg;
>  };
>  
> +/*
> + * Some filesystems i.e. tftpfs only support lseek into one direction.
> + * To detect this limited functionality we add this extra function.
> + * Additionaly we also return 0 if we even can not seek forward.
> + */
> +static inline int can_lseek_backward(int fd)
> +{
> +	int ret;
> +
> +	ret = lseek(fd, 1, SEEK_SET);
> +	if (ret < 0)
> +		return 0;
> +
> +	ret = lseek(fd, 0, SEEK_SET);
> +	if (ret < 0)
> +		return 0;
> +
> +	return ret;
> +}
> +
>  #define drv_to_fs_driver(d) container_of(d, struct fs_driver_d, drv)
>  
>  int flush(int fd);
> -- 
> 2.11.0
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

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

end of thread, other threads:[~2017-11-10  7:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-08 18:07 [PATCH v2] uimage: fix: add can_lseek_backward and use in uimage_open Michael Grzeschik
2017-11-10  7:01 ` Sascha Hauer

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