summaryrefslogtreecommitdiffstats
path: root/commands/nandtest.c
diff options
context:
space:
mode:
authorAlexander Aring <alex.aring@gmail.com>2013-02-17 22:05:01 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2013-02-20 08:22:42 +0100
commit9d8a20592fdc55be56add1639606b65e3cc523d1 (patch)
treeb00eca00c6930954f213443fb990631dd2dd1110 /commands/nandtest.c
parente48b1440715f7f25d664faf98f5afe0a787f7c68 (diff)
downloadbarebox-9d8a20592fdc55be56add1639606b65e3cc523d1.tar.gz
fs: add pread and pwrite functions
Add pread and pwrite functions. Split read and write functions to save some space. The functions pread and pwrite saves and sets the file position to a given offset and restore them afterwards. This also makes the nandtest command use these function which is necessary to not break compilation for the nandtest command. Signed-off-by: Alexander Aring <alex.aring@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/nandtest.c')
-rw-r--r--commands/nandtest.c36
1 files changed, 6 insertions, 30 deletions
diff --git a/commands/nandtest.c b/commands/nandtest.c
index f08f8eb..4e6024b 100644
--- a/commands/nandtest.c
+++ b/commands/nandtest.c
@@ -43,41 +43,17 @@ static unsigned int ecc_stats_over;
static unsigned int ecc_failed_cnt;
/*
- * Implementation of pread with lseek and read.
- */
-static ssize_t pread(int fd, void *buf, size_t count, loff_t offset)
-{
- int ret;
-
- /* Seek to offset */
- ret = lseek(fd, offset, SEEK_SET);
- if (ret < 0)
- perror("lseek");
-
- /* Read from flash and put it into buf */
- ret = read(fd, buf, count);
- if (ret < 0)
- perror("read");
-
- return 0;
-}
-
-/*
* Implementation of pwrite with lseek and write.
*/
-static ssize_t pwrite(int fd, const void *buf,
+static ssize_t __pwrite(int fd, const void *buf,
size_t count, loff_t offset, loff_t length)
{
- int ret;
-
- ret = lseek(fd, offset, SEEK_SET);
- if (ret < 0)
- perror("lseek");
+ ssize_t ret;
/* Write buf to flash */
- ret = write(fd, buf, count);
+ ret = pwrite(fd, buf, count, offset);
if (ret < 0) {
- perror("write");
+ perror("pwrite");
if (markbad) {
printf("\nMark block bad at 0x%08llx\n",
offset + memregion.offset);
@@ -88,7 +64,7 @@ static ssize_t pwrite(int fd, const void *buf,
}
flush(fd);
- return 0;
+ return ret;
}
/*
@@ -119,7 +95,7 @@ static int erase_and_write(loff_t ofs, unsigned char *data,
for (i = 0; i < meminfo.erasesize;
i += meminfo.writesize) {
/* Write data to given offset */
- pwrite(fd, data + i, meminfo.writesize,
+ __pwrite(fd, data + i, meminfo.writesize,
ofs + i, length);
/* Read data from offset */