From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: barebox@lists.infradead.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Subject: [PATCH v2 07/19] fs: Update FILE position in lseek()
Date: Mon, 28 Jan 2019 22:55:37 -0800 [thread overview]
Message-ID: <20190129065549.29161-8-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <20190129065549.29161-1-andrew.smirnov@gmail.com>
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>
---
fs/cramfs/cramfs.c | 3 +--
fs/devfs.c | 2 --
fs/efi.c | 4 +---
fs/efivarfs.c | 4 +---
fs/ext4/ext_barebox.c | 4 +---
fs/fat/fat.c | 1 -
fs/fs.c | 2 ++
fs/nfs.c | 3 +--
fs/omap4_usbbootfs.c | 1 -
fs/ramfs.c | 3 +--
fs/ratpfs.c | 3 +--
fs/smhfs.c | 8 +++-----
fs/squashfs/squashfs.c | 2 --
fs/tftp.c | 17 +++++++++++++----
fs/ubifs/ubifs.c | 2 --
15 files changed, 25 insertions(+), 34 deletions(-)
diff --git a/fs/cramfs/cramfs.c b/fs/cramfs/cramfs.c
index 093657f62..1cce04fce 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 ae5e6475b..6acbbd7ad 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 692556b26..074ef6b53 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 bf7351e6d..34a261935 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 1e7da2a4b..6e41b8345 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 49cd78ff9..ee7751e94 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 a304bf186..7729fe8b1 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 07a82ec60..d83f25007 100644
--- a/fs/nfs.c
+++ b/fs/nfs.c
@@ -1092,10 +1092,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 b35f411cb..51038c705 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 84ecfa0dd..f571cd5ca 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 902289bab..e316289d7 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 f1b6d6bb1..18eaa9dfc 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 d9049b752..87b182a78 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 1b50ba84f..f9e204db5 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 7545dd4c9..ec6d00890 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;
}
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2019-01-29 6:56 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-29 6:55 [PATCH v2 00/19] 32-bit lseek and /dev/mem fixes/improvements Andrey Smirnov
2019-01-29 6:55 ` [PATCH v2 01/19] commands: Move mem_parse_options() to lib/misc.c Andrey Smirnov
2019-01-29 6:55 ` [PATCH v2 02/19] commands: Get rid of mem_rw_buf Andrey Smirnov
2019-01-29 6:55 ` [PATCH v2 03/19] commands: Move /dev/mem driver to drivers/misc Andrey Smirnov
2019-01-29 6:55 ` [PATCH v2 04/19] nvmem: Do not use DEVFS_IS_CHARACTER_DEV Andrey Smirnov
2019-01-29 6:55 ` [PATCH v2 05/19] common: firmware: Don't use FILE_SIZE_STREAM directly Andrey Smirnov
2019-01-29 6:55 ` [PATCH v2 06/19] devfs: Fix incorrect error check for cdev->ops->lseek() Andrey Smirnov
2019-01-29 6:55 ` Andrey Smirnov [this message]
2019-01-29 6:55 ` [PATCH v2 08/19] fs: Drop trivial .lseek() implementaitons in FS drivers Andrey Smirnov
2019-01-29 6:55 ` [PATCH v2 09/19] devfs: Drop dev_lseek_default() Andrey Smirnov
2019-01-29 6:55 ` [PATCH v2 10/19] fs: devfs: Change .lseek callbacks to return 'int' Andrey Smirnov
2019-02-04 14:32 ` Sascha Hauer
2019-01-29 6:55 ` [PATCH v2 11/19] fs: Do not use IS_ERR_VALUE() to validate offset in lseek() Andrey Smirnov
2019-01-29 6:55 ` [PATCH v2 12/19] fs: Simplify new position calculation " Andrey Smirnov
2019-01-29 6:55 ` [PATCH v2 13/19] fs: Share code between mem_write()/mem_read() Andrey Smirnov
2019-01-29 6:55 ` [PATCH v2 14/19] fs: Avoid division in mem_copy() Andrey Smirnov
2019-01-29 6:55 ` [PATCH v2 15/19] fs: Report actual data processed by mem_copy() Andrey Smirnov
2019-01-29 6:55 ` [PATCH v2 16/19] fs: Introduce mem_read_nofail() Andrey Smirnov
2019-01-29 6:55 ` [PATCH v2 17/19] commands: md: Do not use memmap() Andrey Smirnov
2019-02-04 13:57 ` Sascha Hauer
2019-02-04 19:35 ` Andrey Smirnov
2019-01-29 6:55 ` [PATCH v2 18/19] drivers: mem: Create file to access second half of 64-bit memory Andrey Smirnov
2019-01-29 8:48 ` Sascha Hauer
2019-01-29 20:40 ` Andrey Smirnov
2019-01-29 21:09 ` Sam Ravnborg
2019-01-31 10:54 ` Peter Mamonov
2019-01-31 12:50 ` Peter Mamonov
2019-02-01 7:47 ` Sascha Hauer
2019-02-01 10:25 ` Peter Mamonov
2019-02-02 1:07 ` Andrey Smirnov
2019-02-02 0:35 ` Andrey Smirnov
2019-02-04 7:40 ` Sascha Hauer
2019-01-31 20:17 ` Andrey Smirnov
2019-02-01 10:14 ` Peter Mamonov
2019-01-29 6:55 ` [PATCH v2 19/19] libfile: Fix incorrect lseek check in open_and_lseek() Andrey Smirnov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190129065549.29161-8-andrew.smirnov@gmail.com \
--to=andrew.smirnov@gmail.com \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox