Re: [PATCH v2] tftp: implement forward seeking

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Mar 03, 2017 at 09:48:41AM +0100, Uwe Kleine-König wrote:
> Just abuse tftp_read to step forward.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@xxxxxxxxxxxxxx>
> ---
> Hello,
> 
> this is v2 which compared to (implicit) v1 uses xmalloc and no debugging
> any more.
> 
> When tftp_lseek is entered with f->pos == pos, the only thing that the
> function does is xmalloc, free, return. Is it worth to optimize that?
> I thought it's not worth the additional (even if trivial) complication,
> but want to at least point that out.

I don' think that's worth optimizing.

Applied, thanks

Sascha

> 
> Best regards
> Uwe
> 
>  fs/tftp.c | 27 ++++++++++++++++++++++++++-
>  1 file changed, 26 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/tftp.c b/fs/tftp.c
> index 56d4365d773a..4bacd2ed7fcf 100644
> --- a/fs/tftp.c
> +++ b/fs/tftp.c
> @@ -591,7 +591,32 @@ static int tftp_read(struct device_d *dev, FILE *f, void *buf, size_t insize)
>  
>  static loff_t tftp_lseek(struct device_d *dev, FILE *f, loff_t pos)
>  {
> -	/* not implemented in tftp protocol */
> +	/* We cannot seek backwards without reloading or caching the file */
> +	if (pos >= f->pos) {
> +		loff_t ret;
> +		char *buf = xmalloc(1024);
> +
> +		while (pos > f->pos) {
> +			size_t len = min_t(size_t, 1024, pos - f->pos);
> +
> +			ret = tftp_read(dev, f, buf, len);
> +
> +			if (!ret)
> +				/* EOF, so the desired pos is invalid. */
> +				ret = -EINVAL;
> +			if (ret < 0)
> +				goto out_free;
> +
> +			f->pos += ret;
> +		}
> +
> +		ret = pos;
> +
> +out_free:
> +		free(buf);
> +		return ret;
> +	}
> +
>  	return -ENOSYS;
>  }
>  
> -- 
> 2.11.0
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@xxxxxxxxxxxxxxxxxxx
> 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@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox




[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux