summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2019-01-28 22:55:40 -0800
committerSascha Hauer <s.hauer@pengutronix.de>2019-02-04 15:30:11 +0100
commit0b80e3dae75c32e5f30bf4d9052d4f390cc0bb6e (patch)
treeab214800c21830022497a60925741850e9bcd1c8
parent5c9408572406c8718a35931ecf74a5cf38632914 (diff)
downloadbarebox-0b80e3dae75c32e5f30bf4d9052d4f390cc0bb6e.tar.gz
barebox-0b80e3dae75c32e5f30bf4d9052d4f390cc0bb6e.tar.xz
fs: devfs: Change .lseek callbacks to return 'int'
Returning requested offset from .lseek() callback doesn't really give us any new information while bringing unnecessary complications. Change all .lseek() types (both in struct struct cdev_operations and in struct fs_driver_d) to return 'int' and adjust the rest of the codebase accordingly. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--drivers/mtd/nand/nand-bb.c7
-rw-r--r--drivers/mtd/ubi/barebox.c4
-rw-r--r--fs/bpkfs.c4
-rw-r--r--fs/devfs.c6
-rw-r--r--fs/efi.c4
-rw-r--r--fs/fat/fat.c4
-rw-r--r--fs/fs.c8
-rw-r--r--fs/nfs.c4
-rw-r--r--fs/pstore/fs.c4
-rw-r--r--fs/smhfs.c4
-rw-r--r--fs/tftp.c10
-rw-r--r--fs/uimagefs.c4
-rw-r--r--include/driver.h2
-rw-r--r--include/fs.h2
14 files changed, 32 insertions, 35 deletions
diff --git a/drivers/mtd/nand/nand-bb.c b/drivers/mtd/nand/nand-bb.c
index 012163ebb2..e578d72a49 100644
--- a/drivers/mtd/nand/nand-bb.c
+++ b/drivers/mtd/nand/nand-bb.c
@@ -236,17 +236,16 @@ static int nand_bb_calc_size(struct nand_bb *bb)
return 0;
}
-static loff_t nand_bb_lseek(struct cdev *cdev, loff_t __offset)
+static int nand_bb_lseek(struct cdev *cdev, loff_t offset)
{
struct nand_bb *bb = cdev->priv;
loff_t raw_pos = 0;
- uint32_t offset = __offset;
/* lseek only in readonly mode */
if (bb->flags & O_ACCMODE)
return -ENOSYS;
while (raw_pos < bb->mtd->size) {
- off_t now = min(offset, bb->mtd->erasesize);
+ off_t now = min_t(loff_t, offset, bb->mtd->erasesize);
if (mtd_block_isbad(bb->mtd, raw_pos)) {
raw_pos += bb->mtd->erasesize;
@@ -257,7 +256,7 @@ static loff_t nand_bb_lseek(struct cdev *cdev, loff_t __offset)
if (!offset) {
bb->offset = raw_pos;
- return __offset;
+ return 0;
}
}
diff --git a/drivers/mtd/ubi/barebox.c b/drivers/mtd/ubi/barebox.c
index 65f5456455..781061d9a7 100644
--- a/drivers/mtd/ubi/barebox.c
+++ b/drivers/mtd/ubi/barebox.c
@@ -151,7 +151,7 @@ static int ubi_volume_cdev_close(struct cdev *cdev)
return 0;
}
-static loff_t ubi_volume_cdev_lseek(struct cdev *cdev, loff_t ofs)
+static int ubi_volume_cdev_lseek(struct cdev *cdev, loff_t ofs)
{
struct ubi_volume_cdev_priv *priv = cdev->priv;
@@ -159,7 +159,7 @@ static loff_t ubi_volume_cdev_lseek(struct cdev *cdev, loff_t ofs)
if (priv->written)
return -EINVAL;
- return ofs;
+ return 0;
}
static int ubi_volume_cdev_truncate(struct cdev *cdev, size_t size)
diff --git a/fs/bpkfs.c b/fs/bpkfs.c
index f1db963d09..655cde09b7 100644
--- a/fs/bpkfs.c
+++ b/fs/bpkfs.c
@@ -192,7 +192,7 @@ static int bpkfs_read(struct device_d *dev, FILE *file, void *buf, size_t insize
}
}
-static loff_t bpkfs_lseek(struct device_d *dev, FILE *file, loff_t pos)
+static int bpkfs_lseek(struct device_d *dev, FILE *file, loff_t pos)
{
struct bpkfs_handle_data *d = file->priv;
@@ -201,7 +201,7 @@ static loff_t bpkfs_lseek(struct device_d *dev, FILE *file, loff_t pos)
d->pos = pos;
- return pos;
+ return 0;
}
struct somfy_readdir {
diff --git a/fs/devfs.c b/fs/devfs.c
index 5599f39e8c..007dea96d8 100644
--- a/fs/devfs.c
+++ b/fs/devfs.c
@@ -57,10 +57,10 @@ static int devfs_write(struct device_d *_dev, FILE *f, const void *buf, size_t s
return cdev_write(cdev, buf, size, f->pos, f->flags);
}
-static loff_t devfs_lseek(struct device_d *_dev, FILE *f, loff_t pos)
+static int devfs_lseek(struct device_d *_dev, FILE *f, loff_t pos)
{
struct cdev *cdev = f->priv;
- loff_t ret;
+ int ret;
if (cdev->ops->lseek) {
ret = cdev->ops->lseek(cdev, pos + cdev->offset);
@@ -68,7 +68,7 @@ static loff_t devfs_lseek(struct device_d *_dev, FILE *f, loff_t pos)
return ret;
}
- return pos;
+ return 0;
}
static int devfs_erase(struct device_d *_dev, FILE *f, loff_t count, loff_t offset)
diff --git a/fs/efi.c b/fs/efi.c
index 074ef6b533..cd4fee79a1 100644
--- a/fs/efi.c
+++ b/fs/efi.c
@@ -292,7 +292,7 @@ static int efifs_write(struct device_d *_dev, FILE *f, const void *buf, size_t i
return bufsize;
}
-static loff_t efifs_lseek(struct device_d *dev, FILE *f, loff_t pos)
+static int efifs_lseek(struct device_d *dev, FILE *f, loff_t pos)
{
struct efifs_file *ufile = f->priv;
efi_status_t efiret;
@@ -302,7 +302,7 @@ static loff_t efifs_lseek(struct device_d *dev, FILE *f, loff_t pos)
return -efi_errno(efiret);
}
- return pos;
+ return 0;
}
static int efifs_truncate(struct device_d *dev, FILE *f, unsigned long size)
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index ee7751e943..1367577723 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -268,7 +268,7 @@ static int fat_read(struct device_d *_dev, FILE *f, void *buf, size_t insize)
return outsize;
}
-static loff_t fat_lseek(struct device_d *dev, FILE *f, loff_t pos)
+static int fat_lseek(struct device_d *dev, FILE *f, loff_t pos)
{
FIL *f_file = f->priv;
int ret;
@@ -277,7 +277,7 @@ static loff_t fat_lseek(struct device_d *dev, FILE *f, loff_t pos)
if (ret)
return ret;
- return pos;
+ return 0;
}
static DIR* fat_opendir(struct device_d *dev, const char *pathname)
diff --git a/fs/fs.c b/fs/fs.c
index 8cd965b1ae..21f15ec09a 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -439,11 +439,9 @@ loff_t lseek(int fildes, loff_t offset, int whence)
}
if (fsdrv->lseek) {
- pos = fsdrv->lseek(&f->fsdev->dev, f, pos);
- if (IS_ERR_VALUE(pos)) {
- errno = -pos;
- return -1;
- }
+ ret = fsdrv->lseek(&f->fsdev->dev, f, pos);
+ if (ret < 0)
+ goto out;
}
f->pos = pos;
diff --git a/fs/nfs.c b/fs/nfs.c
index cc8795c2c0..c58fca78e5 100644
--- a/fs/nfs.c
+++ b/fs/nfs.c
@@ -1060,13 +1060,13 @@ static int nfs_read(struct device_d *dev, FILE *file, void *buf, size_t insize)
return kfifo_get(priv->fifo, buf, insize);
}
-static loff_t nfs_lseek(struct device_d *dev, FILE *file, loff_t pos)
+static int nfs_lseek(struct device_d *dev, FILE *file, loff_t pos)
{
struct file_priv *priv = file->priv;
kfifo_reset(priv->fifo);
- return pos;
+ return 0;
}
static int nfs_iterate(struct file *file, struct dir_context *ctx)
diff --git a/fs/pstore/fs.c b/fs/pstore/fs.c
index a879a68064..9a7e0b5526 100644
--- a/fs/pstore/fs.c
+++ b/fs/pstore/fs.c
@@ -172,13 +172,13 @@ static int pstore_read(struct device_d *dev, FILE *file, void *buf,
return insize;
}
-static loff_t pstore_lseek(struct device_d *dev, FILE *file, loff_t pos)
+static int pstore_lseek(struct device_d *dev, FILE *file, loff_t pos)
{
struct pstore_private *d = file->priv;
d->pos = pos;
- return pos;
+ return 0;
}
static DIR *pstore_opendir(struct device_d *dev, const char *pathname)
diff --git a/fs/smhfs.c b/fs/smhfs.c
index 18eaa9dfcf..7a6933630c 100644
--- a/fs/smhfs.c
+++ b/fs/smhfs.c
@@ -109,13 +109,13 @@ static int smhfs_read(struct device_d __always_unused *dev,
return -semihosting_errno();
}
-static loff_t smhfs_lseek(struct device_d __always_unused *dev,
+static int smhfs_lseek(struct device_d __always_unused *dev,
FILE *f, loff_t pos)
{
if (semihosting_seek(file_to_fd(f), pos))
return -semihosting_errno();
- return pos;
+ return 0;
}
static DIR* smhfs_opendir(struct device_d __always_unused *dev,
diff --git a/fs/tftp.c b/fs/tftp.c
index f9e204db59..41f904f29f 100644
--- a/fs/tftp.c
+++ b/fs/tftp.c
@@ -573,13 +573,13 @@ static int tftp_read(struct device_d *dev, FILE *f, void *buf, size_t insize)
return outsize;
}
-static loff_t tftp_lseek(struct device_d *dev, FILE *f, loff_t pos)
+static int tftp_lseek(struct device_d *dev, FILE *f, loff_t pos)
{
/* We cannot seek backwards without reloading or caching the file */
loff_t f_pos = f->pos;
if (pos >= f_pos) {
- loff_t ret;
+ int ret = 0;
char *buf = xmalloc(1024);
while (pos > f_pos) {
@@ -596,8 +596,6 @@ static loff_t tftp_lseek(struct device_d *dev, FILE *f, loff_t pos)
f_pos += ret;
}
- ret = pos;
-
out_free:
free(buf);
if (ret < 0) {
@@ -606,8 +604,10 @@ out_free:
* failed since we can't move backwards
*/
f->pos = f_pos;
+ return ret;
}
- return ret;
+
+ return 0;
}
return -ENOSYS;
diff --git a/fs/uimagefs.c b/fs/uimagefs.c
index c120944a46..e5ada82da8 100644
--- a/fs/uimagefs.c
+++ b/fs/uimagefs.c
@@ -116,7 +116,7 @@ static int uimagefs_read(struct device_d *dev, FILE *file, void *buf, size_t ins
}
}
-static loff_t uimagefs_lseek(struct device_d *dev, FILE *file, loff_t pos)
+static int uimagefs_lseek(struct device_d *dev, FILE *file, loff_t pos)
{
struct uimagefs_handle_data *d = file->priv;
@@ -125,7 +125,7 @@ static loff_t uimagefs_lseek(struct device_d *dev, FILE *file, loff_t pos)
d->pos = pos;
- return pos;
+ return 0;
}
static DIR *uimagefs_opendir(struct device_d *dev, const char *pathname)
diff --git a/include/driver.h b/include/driver.h
index bcb31afdc2..a8e046ed7f 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -434,7 +434,7 @@ struct cdev_operations {
ssize_t (*write)(struct cdev*, const void* buf, size_t count, loff_t offset, ulong flags);
int (*ioctl)(struct cdev*, int, void *);
- loff_t (*lseek)(struct cdev*, loff_t);
+ int (*lseek)(struct cdev*, loff_t);
int (*open)(struct cdev*, unsigned long flags);
int (*close)(struct cdev*);
int (*flush)(struct cdev*);
diff --git a/include/fs.h b/include/fs.h
index 181318f404..68b6380bc6 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -53,7 +53,7 @@ struct fs_driver_d {
int (*read)(struct device_d *dev, FILE *f, void *buf, size_t size);
int (*write)(struct device_d *dev, FILE *f, const void *buf, size_t size);
int (*flush)(struct device_d *dev, FILE *f);
- loff_t (*lseek)(struct device_d *dev, FILE *f, loff_t pos);
+ int (*lseek)(struct device_d *dev, FILE *f, loff_t pos);
int (*ioctl)(struct device_d *dev, FILE *f, int request, void *buf);
int (*erase)(struct device_d *dev, FILE *f, loff_t count,