[PATCH 2/4] fs: add pread and pwrite functions
Alexander Aring
alex.aring at gmail.com
Thu Feb 14 08:08:29 EST 2013
Add pread and pwrite functions.
These functions setting file pointer to a given
offset with lseek and call read or write afterwards.
Signed-off-by: Alexander Aring <alex.aring at gmail.com>
---
fs/fs.c | 28 ++++++++++++++++++++++++++++
include/fs.h | 2 ++
2 files changed, 30 insertions(+)
diff --git a/fs/fs.c b/fs/fs.c
index 48d1c89..fea7e02 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -785,6 +785,20 @@ ssize_t read(int fd, void *buf, size_t count)
}
EXPORT_SYMBOL(read);
+ssize_t pread(int fd, void *buf, size_t count, loff_t offset)
+{
+ int ret;
+
+ ret = lseek(fd, offset, SEEK_SET);
+ if (ret < 0)
+ goto out;
+
+ ret = read(fd, buf, count);
+out:
+ return ret;
+}
+EXPORT_SYMBOL(pread);
+
ssize_t write(int fd, const void *buf, size_t count)
{
struct device_d *dev;
@@ -821,6 +835,20 @@ out:
}
EXPORT_SYMBOL(write);
+ssize_t pwrite(int fd, const void *buf, size_t count, loff_t offset)
+{
+ int ret;
+
+ ret = lseek(fd, offset, SEEK_SET);
+ if (ret < 0)
+ goto out;
+
+ ret = write(fd, buf, count);
+out:
+ return ret;
+}
+EXPORT_SYMBOL(pwrite);
+
int flush(int fd)
{
struct device_d *dev;
diff --git a/include/fs.h b/include/fs.h
index d6b22f7..7c4e461 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -114,8 +114,10 @@ int flush(int fd);
int lstat(const char *filename, struct stat *s);
int stat(const char *filename, struct stat *s);
ssize_t read(int fd, void *buf, size_t count);
+ssize_t pread(int fd, void *buf, size_t count, loff_t offset);
int ioctl(int fd, int request, void *buf);
ssize_t write(int fd, const void *buf, size_t count);
+ssize_t pwrite(int fd, const void *buf, size_t count, loff_t offset);
#define SEEK_SET 1
#define SEEK_CUR 2
--
1.8.1.3
More information about the barebox
mailing list