mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/4] fs: fix return type of read
@ 2013-02-14 13:08 Alexander Aring
  2013-02-14 13:08 ` [PATCH 2/4] fs: add pread and pwrite functions Alexander Aring
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Alexander Aring @ 2013-02-14 13:08 UTC (permalink / raw)
  To: barebox

Use ssize_t instead of int. Similar write function
which uses ssize_t as return type, too.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 fs/fs.c      | 2 +-
 include/fs.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index f840516..48d1c89 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -754,7 +754,7 @@ int ioctl(int fd, int request, void *buf)
 	return ret;
 }
 
-int read(int fd, void *buf, size_t count)
+ssize_t read(int fd, void *buf, size_t count)
 {
 	struct device_d *dev;
 	struct fs_driver_d *fsdrv;
diff --git a/include/fs.h b/include/fs.h
index 919daab..d6b22f7 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -113,7 +113,7 @@ int close(int fd);
 int flush(int fd);
 int lstat(const char *filename, struct stat *s);
 int stat(const char *filename, struct stat *s);
-int read(int fd, void *buf, size_t count);
+ssize_t read(int fd, void *buf, size_t count);
 int ioctl(int fd, int request, void *buf);
 ssize_t write(int fd, const void *buf, size_t count);
 
-- 
1.8.1.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/4] fs: add pread and pwrite functions
  2013-02-14 13:08 [PATCH 1/4] fs: fix return type of read Alexander Aring
@ 2013-02-14 13:08 ` Alexander Aring
  2013-02-14 21:13   ` Sascha Hauer
  2013-02-14 13:08 ` [PATCH 3/4] nandtest: use new " Alexander Aring
  2013-02-14 13:08 ` [PATCH 4/4] nandtest: fix length calculation Alexander Aring
  2 siblings, 1 reply; 6+ messages in thread
From: Alexander Aring @ 2013-02-14 13:08 UTC (permalink / raw)
  To: barebox

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@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


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/4] nandtest: use new pread and pwrite functions
  2013-02-14 13:08 [PATCH 1/4] fs: fix return type of read Alexander Aring
  2013-02-14 13:08 ` [PATCH 2/4] fs: add pread and pwrite functions Alexander Aring
@ 2013-02-14 13:08 ` Alexander Aring
  2013-02-14 13:08 ` [PATCH 4/4] nandtest: fix length calculation Alexander Aring
  2 siblings, 0 replies; 6+ messages in thread
From: Alexander Aring @ 2013-02-14 13:08 UTC (permalink / raw)
  To: barebox

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 commands/nandtest.c | 36 ++++++------------------------------
 1 file 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 */
-- 
1.8.1.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 4/4] nandtest: fix length calculation
  2013-02-14 13:08 [PATCH 1/4] fs: fix return type of read Alexander Aring
  2013-02-14 13:08 ` [PATCH 2/4] fs: add pread and pwrite functions Alexander Aring
  2013-02-14 13:08 ` [PATCH 3/4] nandtest: use new " Alexander Aring
@ 2013-02-14 13:08 ` Alexander Aring
  2 siblings, 0 replies; 6+ messages in thread
From: Alexander Aring @ 2013-02-14 13:08 UTC (permalink / raw)
  To: barebox

Fix length calculation when offset isn't zero.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 commands/nandtest.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/commands/nandtest.c b/commands/nandtest.c
index 4e6024b..ba15ecf 100644
--- a/commands/nandtest.c
+++ b/commands/nandtest.c
@@ -112,7 +112,7 @@ static int erase_and_write(loff_t ofs, unsigned char *data,
 					newstats.corrected - oldstats.corrected,
 					ofs + memregion.offset + i);
 			init_progression_bar(length);
-			show_progress(ofs);
+			show_progress(ofs + i);
 			if ((newstats.corrected-oldstats.corrected) >=
 					MAX_ECC_BITS) {
 				/* Increment ECC stats that
@@ -130,7 +130,7 @@ static int erase_and_write(loff_t ofs, unsigned char *data,
 			printf("\nECC failed at page 0x%08llx\n",
 					ofs + memregion.offset + i);
 			init_progression_bar(length);
-			show_progress(ofs);
+			show_progress(ofs + i);
 			oldstats.failed = newstats.failed;
 			ecc_failed_cnt++;
 		}
@@ -292,8 +292,8 @@ static int do_nandtest(int argc, char *argv[])
 
 	for (iter = 0; iter < nr_iterations; iter++) {
 		init_progression_bar(length);
-		for (test_ofs = flash_offset;
-				test_ofs < flash_offset + length;
+		for (test_ofs = 0;
+				test_ofs < length;
 				test_ofs += meminfo.erasesize) {
 			show_progress(test_ofs);
 			srand(seed);
-- 
1.8.1.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/4] fs: add pread and pwrite functions
  2013-02-14 13:08 ` [PATCH 2/4] fs: add pread and pwrite functions Alexander Aring
@ 2013-02-14 21:13   ` Sascha Hauer
  2013-02-14 22:23     ` Alexander Aring
  0 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2013-02-14 21:13 UTC (permalink / raw)
  To: Alexander Aring; +Cc: barebox

On Thu, Feb 14, 2013 at 02:08:29PM +0100, Alexander Aring wrote:
> 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@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;
> +}

The man page says that the file offset is not modified by pread/pwrite.
If we add a standard function with a standard prototype I think it
should have the same behaviour.
Maybe this can be implemented similar to the current read() function
is implemented. read() could then call pread() internally and advances
the file offset afterwards.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/4] fs: add pread and pwrite functions
  2013-02-14 21:13   ` Sascha Hauer
@ 2013-02-14 22:23     ` Alexander Aring
  0 siblings, 0 replies; 6+ messages in thread
From: Alexander Aring @ 2013-02-14 22:23 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

Hi Sascha,

On Thu, Feb 14, 2013 at 10:13:05PM +0100, Sascha Hauer wrote:
> On Thu, Feb 14, 2013 at 02:08:29PM +0100, Alexander Aring wrote:
> > 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@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;
> > +}
> 
> The man page says that the file offset is not modified by pread/pwrite.
> If we add a standard function with a standard prototype I think it
> should have the same behaviour.
> Maybe this can be implemented similar to the current read() function
> is implemented. read() could then call pread() internally and advances
> the file offset afterwards.

Ok I will change this. Thanks.

Regards
Alex

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-02-14 22:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-14 13:08 [PATCH 1/4] fs: fix return type of read Alexander Aring
2013-02-14 13:08 ` [PATCH 2/4] fs: add pread and pwrite functions Alexander Aring
2013-02-14 21:13   ` Sascha Hauer
2013-02-14 22:23     ` Alexander Aring
2013-02-14 13:08 ` [PATCH 3/4] nandtest: use new " Alexander Aring
2013-02-14 13:08 ` [PATCH 4/4] nandtest: fix length calculation Alexander Aring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox