diff options
author | Michael Grzeschik <m.grzeschik@pengutronix.de> | 2017-11-08 19:07:47 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2017-11-10 08:01:18 +0100 |
commit | 7c3f8d3663cbee7e406bf949a263ce82f6b34ae8 (patch) | |
tree | 22cc0d8430ddf99d4e76a4ad9678d96813b6e377 /include/fs.h | |
parent | ed5d71ab06bf45e585f9d03049f4730109979aff (diff) | |
download | barebox-7c3f8d3663cbee7e406bf949a263ce82f6b34ae8.tar.gz barebox-7c3f8d3663cbee7e406bf949a263ce82f6b34ae8.tar.xz |
uimage: fix: add can_lseek_backward and use in uimage_open
Since commit ce0cc7fe we support forward seek on tftpfs. This feature
breaks the condition to check rather we open an uimage over tftp. Since
backward seeking is the problem here, we add the function
can_lseek_backward and check for it instead of the simple lseek.
Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include/fs.h')
-rw-r--r-- | include/fs.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/include/fs.h b/include/fs.h index d7fa7714b4..f8a3b8bda4 100644 --- a/include/fs.h +++ b/include/fs.h @@ -100,6 +100,26 @@ struct fs_device_d { char *linux_rootarg; }; +/* + * Some filesystems i.e. tftpfs only support lseek into one direction. + * To detect this limited functionality we add this extra function. + * Additionaly we also return 0 if we even can not seek forward. + */ +static inline int can_lseek_backward(int fd) +{ + int ret; + + ret = lseek(fd, 1, SEEK_SET); + if (ret < 0) + return 0; + + ret = lseek(fd, 0, SEEK_SET); + if (ret < 0) + return 0; + + return ret; +} + #define drv_to_fs_driver(d) container_of(d, struct fs_driver_d, drv) int flush(int fd); |