diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2017-03-13 08:16:44 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2017-03-13 08:16:44 +0100 |
commit | e0093dcf236cdc1d4faef95189c9376ef6610ae7 (patch) | |
tree | ad41b7daf6e194ad32b0b6a7b33e652c45bd9d38 /fs | |
parent | 4e11672653a4ad639ca2d2158b1266b258951f93 (diff) | |
parent | 939d3a7684ed3138f5e2bfff7cd2876c1e050ca8 (diff) | |
download | barebox-e0093dcf236cdc1d4faef95189c9376ef6610ae7.tar.gz barebox-e0093dcf236cdc1d4faef95189c9376ef6610ae7.tar.xz |
Merge branch 'for-next/misc'
Diffstat (limited to 'fs')
-rw-r--r-- | fs/fs.c | 14 | ||||
-rw-r--r-- | fs/tftp.c | 37 |
2 files changed, 41 insertions, 10 deletions
@@ -910,6 +910,8 @@ loff_t lseek(int fildes, loff_t offset, int whence) case SEEK_SET: if (f->size != FILE_SIZE_STREAM && offset > f->size) goto out; + if (offset < 0) + goto out; pos = offset; break; case SEEK_CUR: @@ -918,15 +920,21 @@ loff_t lseek(int fildes, loff_t offset, int whence) pos = f->pos + offset; break; case SEEK_END: - if (offset) + if (offset > 0) goto out; - pos = f->size; + pos = f->size + offset; break; default: goto out; } - return fsdrv->lseek(&f->fsdev->dev, f, pos); + pos = fsdrv->lseek(&f->fsdev->dev, f, pos); + if (pos < 0) { + errno = -pos; + return -1; + } + + return pos; out: if (ret) @@ -568,13 +568,11 @@ static int tftp_read(struct device_d *dev, FILE *f, void *buf, size_t insize) while (insize) { now = kfifo_get(priv->fifo, buf, insize); + outsize += now; + buf += now; + insize -= now; if (priv->state == STATE_DONE) - return outsize + now; - if (now) { - outsize += now; - buf += now; - insize -= now; - } + return outsize; if (TFTP_FIFO_SIZE - kfifo_len(priv->fifo) >= priv->blocksize) tftp_send(priv); @@ -591,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; } |