summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2019-01-28 22:55:37 -0800
committerSascha Hauer <s.hauer@pengutronix.de>2019-01-29 09:27:03 +0100
commitc44997e621cfe190fe44523e6cbcb03fea21eb8c (patch)
treebfd907f6c2fcd6ee6073f1d48864df6644aa559a /fs
parent6811cc0dbc04c71cdc1ff12efe0edc8660200563 (diff)
downloadbarebox-c44997e621cfe190fe44523e6cbcb03fea21eb8c.tar.gz
barebox-c44997e621cfe190fe44523e6cbcb03fea21eb8c.tar.xz
fs: Update FILE position in lseek()
Instead on relying on driver callbacks to update 'pos' in FILE, do it as a part of lseek() code. This allows us to drop a bit of repeating code as well as making lseek() implementation consistent with write() and read(). Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'fs')
-rw-r--r--fs/cramfs/cramfs.c3
-rw-r--r--fs/devfs.c2
-rw-r--r--fs/efi.c4
-rw-r--r--fs/efivarfs.c4
-rw-r--r--fs/ext4/ext_barebox.c4
-rw-r--r--fs/fat/fat.c1
-rw-r--r--fs/fs.c2
-rw-r--r--fs/nfs.c3
-rw-r--r--fs/omap4_usbbootfs.c1
-rw-r--r--fs/ramfs.c3
-rw-r--r--fs/ratpfs.c3
-rw-r--r--fs/smhfs.c8
-rw-r--r--fs/squashfs/squashfs.c2
-rw-r--r--fs/tftp.c17
-rw-r--r--fs/ubifs/ubifs.c2
15 files changed, 25 insertions, 34 deletions
diff --git a/fs/cramfs/cramfs.c b/fs/cramfs/cramfs.c
index a3ce354c92..0b86485769 100644
--- a/fs/cramfs/cramfs.c
+++ b/fs/cramfs/cramfs.c
@@ -168,8 +168,7 @@ static int cramfs_read(struct device_d *_dev, FILE *f, void *buf, size_t size)
static loff_t cramfs_lseek(struct device_d *dev, FILE *f, loff_t pos)
{
- f->pos = pos;
- return f->pos;
+ return pos;
}
#if 0
diff --git a/fs/devfs.c b/fs/devfs.c
index ae5e6475b1..6acbbd7adb 100644
--- a/fs/devfs.c
+++ b/fs/devfs.c
@@ -70,8 +70,6 @@ static loff_t devfs_lseek(struct device_d *_dev, FILE *f, loff_t pos)
return -ENOSYS;
}
- f->pos = pos;
-
return pos;
}
diff --git a/fs/efi.c b/fs/efi.c
index 692556b260..074ef6b533 100644
--- a/fs/efi.c
+++ b/fs/efi.c
@@ -297,14 +297,12 @@ static loff_t efifs_lseek(struct device_d *dev, FILE *f, loff_t pos)
struct efifs_file *ufile = f->priv;
efi_status_t efiret;
- f->pos = pos;
-
efiret = ufile->entry->set_position(ufile->entry, pos);
if (EFI_ERROR(efiret)) {
return -efi_errno(efiret);
}
- return f->pos;
+ return pos;
}
static int efifs_truncate(struct device_d *dev, FILE *f, unsigned long size)
diff --git a/fs/efivarfs.c b/fs/efivarfs.c
index bf7351e6db..34a2619353 100644
--- a/fs/efivarfs.c
+++ b/fs/efivarfs.c
@@ -309,9 +309,7 @@ static int efivarfs_truncate(struct device_d *dev, FILE *f, ulong size)
static loff_t efivarfs_lseek(struct device_d *dev, FILE *f, loff_t pos)
{
- f->pos = pos;
-
- return f->pos;
+ return pos;
}
static DIR *efivarfs_opendir(struct device_d *dev, const char *pathname)
diff --git a/fs/ext4/ext_barebox.c b/fs/ext4/ext_barebox.c
index 1e7da2a4b4..6e41b8345e 100644
--- a/fs/ext4/ext_barebox.c
+++ b/fs/ext4/ext_barebox.c
@@ -61,9 +61,7 @@ static int ext_read(struct device_d *_dev, FILE *f, void *buf, size_t insize)
static loff_t ext_lseek(struct device_d *dev, FILE *f, loff_t pos)
{
- f->pos = pos;
-
- return f->pos;
+ return pos;
}
static struct inode *ext_alloc_inode(struct super_block *sb)
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index 49cd78ff92..ee7751e943 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -277,7 +277,6 @@ static loff_t fat_lseek(struct device_d *dev, FILE *f, loff_t pos)
if (ret)
return ret;
- f->pos = pos;
return pos;
}
diff --git a/fs/fs.c b/fs/fs.c
index 625ed10b70..bfed252a4b 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -448,6 +448,8 @@ loff_t lseek(int fildes, loff_t offset, int whence)
return -1;
}
+ f->pos = pos;
+
return pos;
out:
diff --git a/fs/nfs.c b/fs/nfs.c
index d7f156687f..cc8795c2c0 100644
--- a/fs/nfs.c
+++ b/fs/nfs.c
@@ -1064,10 +1064,9 @@ static loff_t nfs_lseek(struct device_d *dev, FILE *file, loff_t pos)
{
struct file_priv *priv = file->priv;
- file->pos = pos;
kfifo_reset(priv->fifo);
- return file->pos;
+ return pos;
}
static int nfs_iterate(struct file *file, struct dir_context *ctx)
diff --git a/fs/omap4_usbbootfs.c b/fs/omap4_usbbootfs.c
index b35f411cbb..51038c705d 100644
--- a/fs/omap4_usbbootfs.c
+++ b/fs/omap4_usbbootfs.c
@@ -151,7 +151,6 @@ static int omap4_usbbootfs_read(
static loff_t omap4_usbbootfs_lseek(struct device_d *dev, FILE *f, loff_t pos)
{
- f->pos = pos;
return pos;
}
diff --git a/fs/ramfs.c b/fs/ramfs.c
index 84ecfa0ddb..f571cd5ca8 100644
--- a/fs/ramfs.c
+++ b/fs/ramfs.c
@@ -349,8 +349,7 @@ static int ramfs_write(struct device_d *_dev, FILE *f, const void *buf, size_t i
static loff_t ramfs_lseek(struct device_d *dev, FILE *f, loff_t pos)
{
- f->pos = pos;
- return f->pos;
+ return pos;
}
static int ramfs_truncate(struct device_d *dev, FILE *f, ulong size)
diff --git a/fs/ratpfs.c b/fs/ratpfs.c
index 902289bab1..e316289d72 100644
--- a/fs/ratpfs.c
+++ b/fs/ratpfs.c
@@ -288,8 +288,7 @@ static loff_t ratpfs_lseek(struct device_d __always_unused *dev,
FILE *f, loff_t pos)
{
pr_debug("%s\n", __func__);
- f->pos = pos;
- return f->pos;
+ return pos;
}
static DIR* ratpfs_opendir(struct device_d __always_unused *dev,
diff --git a/fs/smhfs.c b/fs/smhfs.c
index f1b6d6bb1b..18eaa9dfcf 100644
--- a/fs/smhfs.c
+++ b/fs/smhfs.c
@@ -112,12 +112,10 @@ static int smhfs_read(struct device_d __always_unused *dev,
static loff_t smhfs_lseek(struct device_d __always_unused *dev,
FILE *f, loff_t pos)
{
- if (semihosting_seek(file_to_fd(f), pos)) {
+ if (semihosting_seek(file_to_fd(f), pos))
return -semihosting_errno();
- } else {
- f->pos = pos;
- return f->pos;
- }
+
+ return pos;
}
static DIR* smhfs_opendir(struct device_d __always_unused *dev,
diff --git a/fs/squashfs/squashfs.c b/fs/squashfs/squashfs.c
index d9049b7523..87b182a789 100644
--- a/fs/squashfs/squashfs.c
+++ b/fs/squashfs/squashfs.c
@@ -233,8 +233,6 @@ static int squashfs_read(struct device_d *_dev, FILE *f, void *buf,
static loff_t squashfs_lseek(struct device_d *dev, FILE *f, loff_t pos)
{
- f->pos = pos;
-
return pos;
}
diff --git a/fs/tftp.c b/fs/tftp.c
index 1b50ba84f9..f9e204db59 100644
--- a/fs/tftp.c
+++ b/fs/tftp.c
@@ -576,12 +576,14 @@ 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)
{
/* We cannot seek backwards without reloading or caching the file */
- if (pos >= f->pos) {
+ loff_t f_pos = f->pos;
+
+ 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);
+ while (pos > f_pos) {
+ size_t len = min_t(size_t, 1024, pos - f_pos);
ret = tftp_read(dev, f, buf, len);
@@ -591,13 +593,20 @@ static loff_t tftp_lseek(struct device_d *dev, FILE *f, loff_t pos)
if (ret < 0)
goto out_free;
- f->pos += ret;
+ f_pos += ret;
}
ret = pos;
out_free:
free(buf);
+ if (ret < 0) {
+ /*
+ * Update f->pos even if the overall request
+ * failed since we can't move backwards
+ */
+ f->pos = f_pos;
+ }
return ret;
}
diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c
index 7545dd4c9b..ec6d00890c 100644
--- a/fs/ubifs/ubifs.c
+++ b/fs/ubifs/ubifs.c
@@ -396,8 +396,6 @@ static int ubifs_read(struct device_d *_dev, FILE *f, void *buf, size_t insize)
static loff_t ubifs_lseek(struct device_d *dev, FILE *f, loff_t pos)
{
- f->pos = pos;
-
return pos;
}