fs: fix return type of read
PATCH 1/4 fs: fix return type of read
Use ssize_t instead of int. Similar write function which uses ssize_t as return type, too.
--- fs/fs.c | 2 +- include/fs.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
fs/fs.c +1 -1
@@ -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;
include/fs.h +1 -1
@@ -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);
Signature · 7 lines
1.8.1.3 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 2/4 fs: add pread and pwrite functions
Add pread and pwrite functions.
These functions setting file pointer to a given offset with lseek and call read or write afterwards.
--- fs/fs.c | 28 ++++++++++++++++++++++++++++ include/fs.h | 2 ++ 2 files changed, 30 insertions(+)
fs/fs.c +28 -0
@@ -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;
include/fs.h +2 -0
@@ -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
Signature · 7 lines
1.8.1.3 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 2/4] fs: add pread and pwrite functions
Quoted 21 lines · Alexander Aring
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 <[email protected]>--- fs/fs.c | 28 ++++++++++++++++++++++++++++ include/fs.h | 2 ++ 2 files changed, 30 insertions(+)fs/fs.c +2
-0@@ -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) +{
fs/fs.c ssize_t read(int fd, void *buf, size_t count) · line 799
Quoted 10 lines
fs/fs.c +10
-0+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
Signature · 9 lines
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 [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 2/4] fs: add pread and pwrite functions
Hi Sascha,
Quoted 31 lines · Sascha Hauer
Quoted 30 lines · Alexander Aring
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 <[email protected]>--- fs/fs.c | 28 ++++++++++++++++++++++++++++ include/fs.h | 2 ++ 2 files changed, 30 insertions(+)fs/fs.c +11
-0@@ -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;
Quoted 8 lines
fs/fs.c ssize_t read(int fd, void *buf, size_t count) · line 799
Quoted 1 line
fs/fs.c +1
-0+}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 currentread()function is implemented.read()could then callpread()internally and advances the file offset afterwards.
Ok I will change this. Thanks.
Regards
Alex
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH 3/4 nandtest: use new pread and pwrite functions
In reply to Alexander Aring--- commands/nandtest.c | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-)
commands/nandtest.c +6 -30
@@ -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 */
Signature · 7 lines
1.8.1.3 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 4/4 nandtest: fix length calculation
In reply to Alexander AringFix length calculation when offset isn't zero.
--- commands/nandtest.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
commands/nandtest.c +4 -4
@@ -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);
Signature · 7 lines
1.8.1.3 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox