diff options
author | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2017-03-03 09:48:41 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2017-03-03 11:51:38 +0100 |
commit | ce0cc7fee618306624b34d7c14a492c336d7129c (patch) | |
tree | b86bc30bb8177f1952de1c96aecde6b15d869ac0 /fs/tftp.c | |
parent | 74f750fe65587dc0c46100a0f2b94879b2b1f863 (diff) | |
download | barebox-ce0cc7fee618306624b34d7c14a492c336d7129c.tar.gz barebox-ce0cc7fee618306624b34d7c14a492c336d7129c.tar.xz |
tftp: implement forward seeking
Just abuse tftp_read to step forward.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'fs/tftp.c')
-rw-r--r-- | fs/tftp.c | 27 |
1 files changed, 26 insertions, 1 deletions
@@ -589,7 +589,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; } |