fs: fat/ext4/sandbox - Deal with files greater than 2GB
Subsystems (3)
v7 cover fs: fat/ext4/sandbox - Deal with files greater than 2GB
The commands fatls/ext4ls give negative values when dealing with files greater than 2GB.
The commands fatsize/ext4size do not update the variable filesize for these files.
To deal with this, the fs functions have been modified to take an additional parameter of type "* loff_t" which is then populated. The return value of th fs functions are used only for error conditions.
Changes in v7:
* No changes
* Split it so that its bisectable.
* Split it so that its bisectable.
* Split it so that its bisectable.
* Simon - API change in separate patch
* Simon
- take care of fat/vfat in mkfs
- fs/nonfs test code repeats, put it in function
Suriyan Ramasami (6):
sandbox: Use md5sum and fatwrite to enable testing of fs commands
fat: prepare for API change for files greater than 2GB
ext4: prepare for API change for files greater than 2GB
sandbox: prepare for API change for files greater than 2GB
fs: API changes to enable extra parameter to return size of type
loff_t
sandbox: script for testing sandbox/ext4/fat/fs commands
arch/sandbox/cpu/os.c | 13 +- arch/sandbox/cpu/state.c | 8 +- common/board_f.c | 8 +- common/cmd_ext4.c | 61 +---- common/cmd_fat.c | 9 +- common/cmd_fs.c | 17 ++ common/cmd_md5sum.c | 12 +- common/env_fat.c | 4 +- fs/ext4/ext4_common.c | 24 +- fs/ext4/ext4_common.h | 4 +- fs/ext4/ext4_write.c | 32 +++ fs/ext4/ext4fs.c | 37 +-- fs/fat/fat.c | 129 ++++++----- fs/fat/fat_write.c | 61 ++--- fs/fat/file.c | 4 +- fs/fs.c | 77 ++++--- fs/sandbox/sandboxfs.c | 75 ++++--- include/configs/sandbox.h | 2 + include/ext4fs.h | 13 +- include/fat.h | 18 +- include/fs.h | 41 ++-- include/os.h | 5 +- include/sandboxfs.h | 14 +- test/fs/fs-test.sh | 561 ++++++++++++++++++++++++++++++++++++++++++++++ 24 files changed, 945 insertions(+), 284 deletions(-) create mode 100755 test/fs/fs-test.sh
Signature · 1 line
1.9.1
PATCH v7 1/6 sandbox: Use md5sum and fatwrite to enable testing of fs commands
Enable md5sum to check the MD5 of the read and written files to check their contents for validity.
Use map_sysmem() to map buffer in a sandbox environment.
---
Changes in v7:
* No changes
common/cmd_md5sum.c | 12 ++++++++++-- include/configs/sandbox.h | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-)
common/cmd_md5sum.c +10 -2
@@ -11,6 +11,7 @@#include <common.h> #include <command.h> #include <u-boot/md5.h> +#include <asm/io.h> /* * Store the resulting sum to an address or variable
@@ -79,6 +80,7 @@ int do_md5sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])int verify =0 ;int ac;char *const *av; +void *buf;if (argc <3 )return CMD_RET_USAGE ;
@@ -96,7 +98,9 @@ int do_md5sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) addr =simple_strtoul (*av++,NULL ,16 ); len =simple_strtoul (*av++,NULL ,16 ); -md5_wd ((unsigned char *) addr, len, output,CHUNKSZ_MD5 ); + buf =map_sysmem (addr, len); +md5_wd (buf, len, output,CHUNKSZ_MD5 ); +unmap_sysmem (buf);if (!verify) {printf ("md5 for %08lx ... %08lx ==> " , addr, addr + len -1 );
@@ -135,6 +139,7 @@ static int do_md5sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])unsigned long addr, len;unsigned int i;u8 output[16 ]; +void *buf;if (argc <3 )return CMD_RET_USAGE ;
@@ -142,7 +147,10 @@ static int do_md5sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) addr =simple_strtoul (argv[1 ],NULL ,16 ); len =simple_strtoul (argv[2 ],NULL ,16 ); -md5_wd ((unsigned char *) addr, len, output,CHUNKSZ_MD5 ); + buf =map_sysmem (addr, len); +md5_wd (buf, len, output,CHUNKSZ_MD5 ); +unmap_sysmem (buf); +printf ("md5 for %08lx ... %08lx ==> " , addr, addr + len -1 );for (i =0 ; i <16 ; i++)printf ("%02x" , output[i]);
include/configs/sandbox.h +2 -0
@@ -48,6 +48,7 @@#define CONFIG_ANDROID_BOOT_IMAGE #define CONFIG_FS_FAT +#define CONFIG_FAT_WRITE #define CONFIG_FS_EXT4 #define CONFIG_EXT4_WRITE #define CONFIG_CMD_FAT
@@ -57,6 +58,7 @@#define CONFIG_DOS_PARTITION #define CONFIG_HOST_MAX_DEVICES 4#define CONFIG_CMD_FS_GENERIC +#define CONFIG_CMD_MD5SUM #define CONFIG_SYS_VSNPRINTF
Signature · 1 line
1.9.1
PATCH v7 2/6 fat: prepare for API change for files greater than 2GB
In reply to Suriyan RamasamiChange the internal fat functions to use loff_t for offsets.
---
Changes in v7:
* Split it so that its bisectable.
common/cmd_fat.c | 9 ++-- common/env_fat.c | 4 +- fs/fat/fat.c | 133 +++++++++++++++++++++++++++++++---------------------- fs/fat/fat_write.c | 61 +++++++++++++----------- fs/fat/file.c | 4 +- include/fat.h | 13 +++--- 6 files changed, 128 insertions(+), 96 deletions(-)
common/cmd_fat.c +5 -4
@@ -100,7 +100,8 @@ U_BOOT_CMD(static int do_fat_fswrite (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) { -long size; +loff_t size; +int ret;unsigned long addr;unsigned long count;block_dev_desc_t *dev_desc =NULL ;
@@ -127,15 +128,15 @@ static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag, count =simple_strtoul (argv[5 ],NULL ,16 ); buf =map_sysmem (addr, count); - size =file_fat_write (argv[4 ], buf, count); + ret =file_fat_write (argv[4 ], buf,0 , count, &size);unmap_sysmem (buf); -if (size ==-1 ) { +if (ret <0 ) {printf ("\n** Unable to write \"%s\" from %s %d:%d **\n" , argv[4 ], argv[1 ], dev, part);return 1 ; } -printf ("%ld bytes written\n" , size); +printf ("%llu bytes written\n" , size);return 0 ; }
common/env_fat.c +3 -1
@@ -41,6 +41,7 @@ int saveenv(void)disk_partition_t info;int dev, part;int err; +loff_t size; err =env_export (&env_new);if (err)
@@ -59,7 +60,8 @@ int saveenv(void)return 1 ; } - err =file_fat_write (FAT_ENV_FILE , (void *)&env_new,sizeof (env_t)); + err =file_fat_write (FAT_ENV_FILE , (void *)&env_new,sizeof (env_t), + &size);if (err ==-1 ) {printf ("\n** Unable to write \"%s\" from %s%d:%d **\n" ,FAT_ENV_FILE ,FAT_ENV_INTERFACE , dev, part);
fs/fat/fat.c +77 -56
287 lines not on this page · raw message
fs/fat/fat_write.c +34 -27
173 lines not on this page · raw message
fs/fat/file.c +2 -2
@@ -162,8 +162,8 @@ file_ls(const char *dir)return filesystems[current_filesystem].ls (arg); } -long -file_read (const char *filename,void *buffer,unsigned long maxsize) +int +file_read (const char *filename,void *buffer,int maxsize) {char fullpath[1024 ];const char *arg;
include/fat.h +7 -6
@@ -178,8 +178,8 @@ typedef struct {typedef int (file_detectfs_func )(void );typedef int (file_ls_func )(const char *dir); -typedef long (file_read_func )(const char *filename,void *buffer, -unsigned long maxsize); +typedef int (file_read_func )(const char *filename,void *buffer, +int maxsize);struct filesystem {file_detectfs_func *detect;
@@ -199,14 +199,15 @@ int file_fat_detectfs(void);int file_fat_ls (const char *dir);int fat_exists (const char *filename);int fat_size (const char *filename); -long file_fat_read_at (const char *filename,unsigned long pos,void *buffer, -unsigned long maxsize); -long file_fat_read (const char *filename,void *buffer,unsigned long maxsize); +int file_fat_read_at (const char *filename,loff_t pos,void *buffer, +loff_t maxsize,loff_t *actread); +int file_fat_read (const char *filename,void *buffer,int maxsize);const char *file_getfsname (int idx);int fat_set_blk_dev (block_dev_desc_t *rbdd,disk_partition_t *info);int fat_register_device (block_dev_desc_t *dev_desc,int part_no); -int file_fat_write (const char *filename,void *buffer,unsigned long maxsize); +int file_fat_write (const char *filename,void *buf,loff_t offset,loff_t len, +loff_t *actwrite);int fat_read_file (const char *filename,void *buf,int offset,int len);void fat_close (void );#endif /* _FAT_H_ */
Signature · 1 line
1.9.1
PATCH v7 2/6 fat: prepare for API change for files greater than 2GB
Hi,
Quoted 8 lines · Suriyan Ramasami
Change the internal fat functions to use
loff_tfor offsets.Signed-off-by Suriyan Ramasami <[email protected]>---
Changes in v7:
* Split it so that its bisectable.
A few bits below but with these fixed:
Quoted 72 lines
common/cmd_fat.c | 9 ++-- common/env_fat.c | 4 +- fs/fat/fat.c | 133 +++++++++++++++++++++++++++++++---------------------- fs/fat/fat_write.c | 61 +++++++++++++----------- fs/fat/file.c | 4 +- include/fat.h | 13 +++--- 6 files changed, 128 insertions(+), 96 deletions(-)common/cmd_fat.c +5
-4@@ -100,7 +100,8 @@ U_BOOT_CMD(static int do_fat_fswrite (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) { -long size; +loff_t size; +int ret;unsigned long addr;unsigned long count;block_dev_desc_t *dev_desc =NULL ;@@ -127,15 +128,15 @@ static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag, count =simple_strtoul (argv[5 ],NULL ,16 ); buf =map_sysmem (addr, count); - size =file_fat_write (argv[4 ], buf, count); + ret =file_fat_write (argv[4 ], buf,0 , count, &size);unmap_sysmem (buf); -if (size ==-1 ) { +if (ret <0 ) {printf ("\n** Unable to write \"%s\" from %s %d:%d **\n" , argv[4 ], argv[1 ], dev, part);return 1 ; } -printf ("%ld bytes written\n" , size); +printf ("%llu bytes written\n" , size);return 0 ; }common/env_fat.c +3
-1@@ -41,6 +41,7 @@ int saveenv(void)disk_partition_t info;int dev, part;int err; +loff_t size; err =env_export (&env_new);if (err)@@ -59,7 +60,8 @@ int saveenv(void)return 1 ; } - err =file_fat_write (FAT_ENV_FILE , (void *)&env_new,sizeof (env_t)); + err =file_fat_write (FAT_ENV_FILE , (void *)&env_new,sizeof (env_t), + &size);if (err ==-1 ) {printf ("\n** Unable to write \"%s\" from %s%d:%d **\n" ,FAT_ENV_FILE ,FAT_ENV_INTERFACE , dev, part);fs/fat/fat.c +0
-0@@ -317,32 +317,33 @@ get_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long size)/* * Read at most 'maxsize' bytes from 'pos' in the file associated with 'dentptr' * into 'buffer'.
fs/fat/fat.c get_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long size) · line 325
Quoted 10 lines
fs/fat/fat.c +2
-4-* Return the number of bytes read or -1 on fatal errors. +* Update the number of bytes read in *gotsize or return -1 on fatal errors. */ __u8 get_contents_vfatname_block[MAX_CLUSTSIZE ]__aligned(ARCH_DMA_MINALIGN) ; -static long -get_contents (fsdata *mydata,dir_entry *dentptr,unsigned long pos, -__u8 *buffer,unsigned long maxsize) +static int
put this on the same line as the next
Quoted 217 lines
fs/fat/fat.c +43
-38+get_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos, + __u8 *buffer, loff_t maxsize, loff_t *gotsize) { -unsigned long filesize =FAT2CPU32 (dentptr->size), gotsize =0 ; +loff_t filesize =FAT2CPU32 (dentptr->size);unsigned int bytesperclust = mydata->clust_size * mydata->sect_size;__u32 curclust =START (dentptr);__u32 endclust, newclust; -unsigned long actsize; +loff_t actsize; -debug ("Filesize: %ld bytes\n" , filesize); + *gotsize =0 ; +debug ("Filesize: %llu bytes\n" , filesize);if (pos >= filesize) { -debug ("Read position past EOF: %lu\n" , pos); -return gotsize; +debug ("Read position past EOF: %llu\n" , pos); +return 0 ; }if (maxsize >0 && filesize > pos + maxsize) filesize = pos + maxsize; -debug ("%ld bytes\n" , filesize); +debug ("%llu bytes\n" , filesize); actsize = bytesperclust;@@ -352,7 +353,7 @@ get_contents(fsdata *mydata, dir_entry *dentptr, unsigned long pos,if (CHECK_CLUST (curclust, mydata->fatsize)) {debug ("curclust: 0x%x\n" , curclust);debug ("Invalid FAT entry\n" ); -return gotsize; +return 0 ; } actsize += bytesperclust; }@@ -373,16 +374,16 @@ get_contents(fsdata *mydata, dir_entry *dentptr, unsigned long pos, filesize -= actsize; actsize -= pos;memcpy (buffer, get_contents_vfatname_block + pos, actsize); - gotsize += actsize; + *gotsize += actsize;if (!filesize) -return gotsize; +return 0 ; buffer += actsize; curclust =get_fatent (mydata, curclust);if (CHECK_CLUST (curclust, mydata->fatsize)) {debug ("curclust: 0x%x\n" , curclust);debug ("Invalid FAT entry\n" ); -return gotsize; +return 0 ; } }@@ -398,7 +399,7 @@ get_contents(fsdata *mydata, dir_entry *dentptr, unsigned long pos,if (CHECK_CLUST (newclust, mydata->fatsize)) {debug ("curclust: 0x%x\n" , newclust);debug ("Invalid FAT entry\n" ); -return gotsize; +return 0 ; } endclust = newclust; actsize += bytesperclust;@@ -410,14 +411,14 @@ get_contents(fsdata *mydata, dir_entry *dentptr, unsigned long pos,printf ("Error reading cluster\n" );return -1 ; } - gotsize += actsize; -return gotsize; + *gotsize += actsize; +return 0 ; getit:if (get_cluster (mydata, curclust, buffer, (int )actsize) !=0 ) {printf ("Error reading cluster\n" );return -1 ; } - gotsize += (int )actsize; + *gotsize += (int )actsize; filesize -= actsize; buffer += actsize;@@ -425,7 +426,7 @@ getit:if (CHECK_CLUST (curclust, mydata->fatsize)) {debug ("curclust: 0x%x\n" , curclust);printf ("Invalid FAT entry\n" ); -return gotsize; +return 0 ; } actsize = bytesperclust; endclust = curclust;@@ -633,8 +634,8 @@ static dir_entry *get_dentfromdir(fsdata *mydata, int startsect, }if (doit) {if (dirc ==' ' ) { -printf (" %8ld %s%c\n" , - (long )FAT2CPU32 (dentptr->size), +printf (" %8u %s%c\n" , +FAT2CPU32 (dentptr->size), l_name, dirc); }else {@@ -690,8 +691,8 @@ static dir_entry *get_dentfromdir(fsdata *mydata, int startsect,if (doit) {if (dirc ==' ' ) { -printf (" %8ld %s%c\n" , - (long )FAT2CPU32 (dentptr->size), +printf (" %8u %s%c\n" , +FAT2CPU32 (dentptr->size), s_name, dirc); }else { printf(" %s%c\n",@@ -806,9 +807,8 @@ exit:__u8 do_fat_read_at_block[MAX_CLUSTSIZE ]__aligned(ARCH_DMA_MINALIGN) ; -long -do_fat_read_at (const char *filename,unsigned long pos,void *buffer, -unsigned long maxsize,int dols,int dogetsize) +int do_fat_read_at (const char *filename,loff_t pos,void *buffer, +loff_t maxsize,int dols,int dogetsize,loff_t *size) {char fnamecopy[2048 ];boot_sector bs;@@ -821,7 +821,7 @@ do_fat_read_at(const char *filename, unsigned long pos, void *buffer,__u32 cursect;int idx, isdir =0 ;int files =0 , dirs =0 ; -long ret =-1 ; +int ret =-1 ;int firsttime;__u32 root_cluster =0 ;int rootdir_size =0 ;@@ -974,8 +974,8 @@ do_fat_read_at(const char *filename, unsigned long pos, void *buffer, }if (doit) {if (dirc ==' ' ) { -printf (" %8ld %s%c\n" , - (long )FAT2CPU32 (dentptr->size), +printf (" %8u %s%c\n" , +FAT2CPU32 (dentptr->size), l_name, dirc); }else {@@ -1032,8 +1032,8 @@ do_fat_read_at(const char *filename, unsigned long pos, void *buffer, }if (doit) {if (dirc ==' ' ) { -printf (" %8ld %s%c\n" , - (long )FAT2CPU32 (dentptr->size), +printf (" %8u %s%c\n" , +FAT2CPU32 (dentptr->size), s_name, dirc); }else { printf(" %s%c\n",@@ -1102,7 +1102,7 @@ do_fat_read_at(const char *filename, unsigned long pos, void *buffer,if (dols ==LS_ROOT ) {printf ("\n%d file(s), %d dir(s)\n\n" , files, dirs); - ret =0 ; + *size =0 ; } goto exit; }@@ -1141,7 +1141,7 @@ rootdir_done:if (get_dentfromdir (mydata, startsect, subname, dentptr, isdir ?0 : dols) ==NULL ) {if (dols && !isdir) - ret =0 ; + *size =0 ; goto exit; }@@ -1152,21 +1152,23 @@ rootdir_done: subname = nextname; } -if (dogetsize) - ret =FAT2CPU32 (dentptr->size); -else - ret =get_contents (mydata, dentptr, pos, buffer, maxsize); -debug ("Size: %d, got: %ld\n" ,FAT2CPU32 (dentptr->size), ret); +if (dogetsize) { + *size =FAT2CPU32 (dentptr->size); + ret =0 ; + }else { + ret =get_contents (mydata, dentptr, pos, buffer, maxsize, size); + } +debug ("Size: %u, got: %llu\n" ,FAT2CPU32 (dentptr->size), *size); exit:free (mydata->fatbuf);return ret; } -long -do_fat_read (const char *filename,void *buffer,unsigned long maxsize,int dols) +int do_fat_read (const char *filename,void *buffer,loff_t maxsize,int dols, +loff_t *actread) { -return do_fat_read_at (filename,0 , buffer, maxsize, dols,0 ); +return do_fat_read_at (filename,0 , buffer, maxsize, dols,0 , actread); }int file_fat_detectfs (void )@@ -1233,44 +1235,63 @@ int file_fat_detectfs(void)int file_fat_ls (const char *dir) { -return do_fat_read (dir,NULL ,0 ,LS_YES ); +loff_t size; +
fs/fat/fat.c int file_fat_detectfs(void) · line 1246
Quoted 10 lines
fs/fat/fat.c +3
-3+return do_fat_read (dir,NULL ,0 ,LS_YES , &size); }int fat_exists (const char *filename) { -int sz; - sz =do_fat_read_at (filename,0 ,NULL ,0 ,LS_NO ,1 ); -return sz >=0 ; +int ret; +loff_t size;
blank line here
fs/fat/fat.c int file_fat_detectfs(void) · line 1254
Quoted 9 lines
fs/fat/fat.c +4
-1+ ret =do_fat_read_at (filename,0 ,NULL ,0 ,LS_NO ,1 , &size); +return ret ==0 ; }int fat_size (const char *filename) { -return do_fat_read_at (filename,0 ,NULL ,0 ,LS_NO ,1 ); +loff_t size; +int ret;
indent those two lines
Quoted 15 lines
fs/fat/fat.c +8
-3+ + ret =do_fat_read_at (filename,0 ,NULL ,0 ,LS_NO ,1 , &size); +if (ret) +return ret; +else +return size; } -long file_fat_read_at (const char *filename,unsigned long pos,void *buffer, -unsigned long maxsize) +int file_fat_read_at (const char *filename,loff_t pos,void *buffer, +loff_t maxsize,loff_t *actread) {printf ("reading %s\n" , filename); -return do_fat_read_at (filename, pos, buffer, maxsize,LS_NO ,0 );
fs/fat/fat.c int file_fat_detectfs(void) · line 1274
Quoted 10 lines
fs/fat/fat.c +5
-2+return do_fat_read_at (filename, pos, buffer, maxsize,LS_NO ,0 , + actread); } -long file_fat_read (const char *filename,void *buffer,unsigned long maxsize) +int file_fat_read (const char *filename,void *buffer,int maxsize) { -return file_fat_read_at (filename,0 , buffer, maxsize); +loff_t actread; +int ret;
indent those two lines
Quoted 223 lines
fs/fat/fat.c +12
-5+ + ret =file_fat_read_at (filename,0 , buffer, maxsize, &actread); +if (ret) +return ret; +else +return actread; }int fat_read_file (const char *filename,void *buf,int offset,int len) { -int len_read; +int ret; +loff_t actread; - len_read =file_fat_read_at (filename, offset, buf, len); -if (len_read ==-1 ) { + ret =file_fat_read_at (filename, offset, buf, len, &actread); +if (ret) {printf ("** Unable to read file %s **\n" , filename); -return -1 ; +return ret; } -return len_read; +return actread; }void fat_close (void )fs/fat/fat_write.c +34
-27@@ -660,24 +660,26 @@ static int clear_fatent(fsdata *mydata, __u32 entry)/* * Write at most 'maxsize' bytes from 'buffer' into * the file associated with 'dentptr' -* Return the number of bytes read or -1 on fatal errors. +* Update the number of bytes written in *gotsize and return 0 +* or return -1 on fatal errors. */ static int set_contents (fsdata *mydata,dir_entry *dentptr,__u8 *buffer, -unsigned long maxsize) +loff_t maxsize,loff_t *gotsize) { -unsigned long filesize =FAT2CPU32 (dentptr->size), gotsize =0 ; +loff_t filesize =FAT2CPU32 (dentptr->size);unsigned int bytesperclust = mydata->clust_size * mydata->sect_size;__u32 curclust =START (dentptr);__u32 endclust =0 , newclust =0 ; -unsigned long actsize; +loff_t actsize; -debug ("Filesize: %ld bytes\n" , filesize); + *gotsize =0 ; +debug ("Filesize: %llu bytes\n" , filesize);if (maxsize >0 && filesize > maxsize) filesize = maxsize; -debug ("%ld bytes\n" , filesize); +debug ("%llu bytes\n" , filesize); actsize = bytesperclust; endclust = curclust;@@ -692,7 +694,7 @@ set_contents(fsdata *mydata, dir_entry *dentptr, __u8 *buffer,if (CHECK_CLUST (newclust, mydata->fatsize)) {debug ("curclust: 0x%x\n" , newclust);debug ("Invalid FAT entry\n" ); -return gotsize; +return 0 ; } endclust = newclust; actsize += bytesperclust;@@ -706,7 +708,7 @@ set_contents(fsdata *mydata, dir_entry *dentptr, __u8 *buffer, }/* set remaining bytes */ - gotsize += (int )actsize; + *gotsize += actsize; filesize -= actsize; buffer += actsize; actsize = filesize;@@ -715,7 +717,7 @@ set_contents(fsdata *mydata, dir_entry *dentptr, __u8 *buffer,debug ("error: writing cluster\n" );return -1 ; } - gotsize += actsize; + *gotsize += actsize;/* Mark end of file in FAT */ if (mydata->fatsize ==16 )@@ -724,20 +726,20 @@ set_contents(fsdata *mydata, dir_entry *dentptr, __u8 *buffer, newclust =0xfffffff ;set_fatent_value (mydata, endclust, newclust); -return gotsize; +return 0 ; getit:if (set_cluster (mydata, curclust, buffer, (int )actsize) !=0 ) {debug ("error: writing cluster\n" );return -1 ; } - gotsize += (int )actsize; + *gotsize += actsize; filesize -= actsize; buffer += actsize;if (CHECK_CLUST (curclust, mydata->fatsize)) {debug ("curclust: 0x%x\n" , curclust);debug ("Invalid FAT entry\n" ); -return gotsize; +return 0 ; } actsize = bytesperclust; curclust = endclust = newclust;@@ -766,7 +768,7 @@ static void fill_dentry(fsdata *mydata, dir_entry *dentptr,* exceed the size of the block device * Return -1 when overflow occurs, otherwise return 0 */ -static int check_overflow (fsdata *mydata,__u32 clustnum,unsigned long size) +static int check_overflow (fsdata *mydata,__u32 clustnum,loff_t size) {__u32 startsect, sect_num;@@ -923,8 +925,8 @@ static dir_entry *find_directory_entry(fsdata *mydata, int startsect,return NULL ; } -static int do_fat_write (const char *filename,void *buffer, -unsigned long size) +static int do_fat_write (const char *filename,void *buffer,loff_t size, +loff_t *actwrite) {dir_entry *dentptr, *retdent;__u32 startsect;@@ -936,8 +938,8 @@ static int do_fat_write(const char *filename, void *buffer,int cursect;int ret =-1 , name_len;char l_filename[VFAT_MAXLEN_BYTES ]; -int write_size = size; + *actwrite = size; dir_curclust =0 ;if (read_bootsectandvi (&bs, &volinfo, &mydata->fatsize)) {@@ -1015,7 +1017,7 @@ static int do_fat_write(const char *filename, void *buffer, ret =check_overflow (mydata, start_cluster, size);if (ret) { -printf ("Error: %ld overflow\n" , size); +printf ("Error: %llu overflow\n" , size); goto exit; }@@ -1025,13 +1027,12 @@ static int do_fat_write(const char *filename, void *buffer, goto exit; } - ret =set_contents (mydata, retdent, buffer, size); + ret =set_contents (mydata, retdent, buffer, size, actwrite);if (ret <0 ) {printf ("Error: writing contents\n" ); goto exit; } - write_size = ret; -debug ("attempt to write 0x%x bytes\n" , write_size); +debug ("attempt to write 0x%llx bytes\n" , *actwrite);/* Flush fat buffer */ ret =flush_fat_buffer (mydata);@@ -1061,7 +1062,7 @@ static int do_fat_write(const char *filename, void *buffer, ret =check_overflow (mydata, start_cluster, size);if (ret) { -printf ("Error: %ld overflow\n" , size); +printf ("Error: %llu overflow\n" , size); goto exit; }@@ -1069,13 +1070,13 @@ static int do_fat_write(const char *filename, void *buffer,fill_dentry (mydata, empty_dentptr, filename, start_cluster, size,0x20 ); - ret =set_contents (mydata, empty_dentptr, buffer, size); + ret =set_contents (mydata, empty_dentptr, buffer, size, + actwrite);if (ret <0 ) {printf ("Error: writing contents\n" ); goto exit; } - write_size = ret; -debug ("attempt to write 0x%x bytes\n" , write_size); +debug ("attempt to write 0x%llx bytes\n" , *actwrite);/* Flush fat buffer */ ret =flush_fat_buffer (mydata);@@ -1096,11 +1097,17 @@ static int do_fat_write(const char *filename, void *buffer, exit:free (mydata->fatbuf); -return ret <0 ? ret : write_size; +return ret; } -int file_fat_write (const char *filename,void *buffer,unsigned long maxsize) +int file_fat_write (const char *filename,void *buffer,loff_t offset, +loff_t maxsize,loff_t *actwrite) { +if (offset !=0 ) { +printf ("Error: non zero offset is currently not suported.\n" ); +return -1 ; + } +printf ("writing %s\n" , filename); -return do_fat_write (filename, buffer, maxsize); +return do_fat_write (filename, buffer, maxsize, actwrite); }fs/fat/file.c +0
-0
fs/fat/file.c file_ls(const char *dir) · line 165
Quoted 6 lines
fs/fat/file.c +1
-2@@ -162,8 +162,8 @@ file_ls(const char *dir)return filesystems[current_filesystem].ls (arg); } -long -file_read (const char *filename,void *buffer,unsigned long maxsize) +int
put on next line
Quoted 40 lines
fs/fat/file.c +1
-0+file_read(const char *filename, void *buffer, int maxsize) { char fullpath[1024];const char *arg;include/fat.h +7
-7@@ -178,8 +178,8 @@ typedef struct {typedef int (file_detectfs_func )(void );typedef int (file_ls_func )(const char *dir); -typedef long (file_read_func )(const char *filename,void *buffer, -unsigned long maxsize); +typedef int (file_read_func )(const char *filename,void *buffer, +int maxsize);struct filesystem {file_detectfs_func *detect;@@ -199,14 +199,15 @@ int file_fat_detectfs(void);int file_fat_ls (const char *dir);int fat_exists (const char *filename);int fat_size (const char *filename); -long file_fat_read_at (const char *filename,unsigned long pos,void *buffer, -unsigned long maxsize); -long file_fat_read (const char *filename,void *buffer,unsigned long maxsize); +int file_fat_read_at (const char *filename,loff_t pos,void *buffer, +loff_t maxsize,loff_t *actread); +int file_fat_read (const char *filename,void *buffer,int maxsize);const char *file_getfsname (int idx);int fat_set_blk_dev (block_dev_desc_t *rbdd,disk_partition_t *info);int fat_register_device (block_dev_desc_t *dev_desc,int part_no); -int file_fat_write (const char *filename,void *buffer,unsigned long maxsize); +int file_fat_write (const char *filename,void *buf,loff_t offset,loff_t len, +loff_t *actwrite);int fat_read_file (const char *filename,void *buf,int offset,int len);void fat_close (void );#endif /* _FAT_H_ */ --
Quoted 2 lines
1.9.1
Regards,
Simon
PATCH v7 2/6 fat: prepare for API change for files greater than 2GB
Hello Simon,
Quoted 94 lines · Simon Glass
Hi,
Quoted 8 lines · Suriyan Ramasami
Change the internal fat functions to use
loff_tfor offsets.Signed-off-by Suriyan Ramasami <[email protected]>---
Changes in v7:
* Split it so that its bisectable.A few bits below but with these fixed:
Acked-by Simon Glass <[email protected]>Quoted 78 lines
common/cmd_fat.c | 9 ++-- common/env_fat.c | 4 +- fs/fat/fat.c | 133 +++++++++++++++++++++++++++++++---------------------- fs/fat/fat_write.c | 61 +++++++++++++----------- fs/fat/file.c | 4 +- include/fat.h | 13 +++--- 6 files changed, 128 insertions(+), 96 deletions(-)common/cmd_fat.c +5
-4@@ -100,7 +100,8 @@ U_BOOT_CMD(static int do_fat_fswrite (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) { -long size; +loff_t size; +int ret;unsigned long addr;unsigned long count;block_dev_desc_t *dev_desc =NULL ;@@ -127,15 +128,15 @@ static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag, count =simple_strtoul (argv[5 ],NULL ,16 ); buf =map_sysmem (addr, count); - size =file_fat_write (argv[4 ], buf, count); + ret =file_fat_write (argv[4 ], buf,0 , count, &size);unmap_sysmem (buf); -if (size ==-1 ) { +if (ret <0 ) {printf ("\n** Unable to write \"%s\" from %s %d:%d **\n" , argv[4 ], argv[1 ], dev, part);return 1 ; } -printf ("%ld bytes written\n" , size); +printf ("%llu bytes written\n" , size);return 0 ; }common/env_fat.c +3
-1@@ -41,6 +41,7 @@ int saveenv(void)disk_partition_t info;int dev, part;int err; +loff_t size; err =env_export (&env_new);if (err)@@ -59,7 +60,8 @@ int saveenv(void)return 1 ; } - err =file_fat_write (FAT_ENV_FILE , (void *)&env_new,sizeof (env_t)); + err =file_fat_write (FAT_ENV_FILE , (void *)&env_new,sizeof (env_t), + &size);if (err ==-1 ) {printf ("\n** Unable to write \"%s\" from %s%d:%d **\n" ,FAT_ENV_FILE ,FAT_ENV_INTERFACE , dev, part);fs/fat/fat.c +1
-1@@ -317,32 +317,33 @@ get_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long size)/* * Read at most 'maxsize' bytes from 'pos' in the file associated with 'dentptr' * into 'buffer'. -* Return the number of bytes read or -1 on fatal errors. +* Update the number of bytes read in *gotsize or return -1 on fatal errors. */ __u8 get_contents_vfatname_block[MAX_CLUSTSIZE ]__aligned(ARCH_DMA_MINALIGN) ;
Quoted 7 lines
fs/fat/fat.c get_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long size) · line 325
Quoted 4 lines
fs/fat/fat.c +1
-3-static long -get_contents (fsdata *mydata,dir_entry *dentptr,unsigned long pos, -__u8 *buffer,unsigned long maxsize) +static intput this on the same line as the next
OK
Quoted 220 lines
Quoted 220 lines
fs/fat/fat.c +44
-38+get_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos, + __u8 *buffer, loff_t maxsize, loff_t *gotsize) { -unsigned long filesize =FAT2CPU32 (dentptr->size), gotsize =0 ; +loff_t filesize =FAT2CPU32 (dentptr->size);unsigned int bytesperclust = mydata->clust_size * mydata->sect_size;__u32 curclust =START (dentptr);__u32 endclust, newclust; -unsigned long actsize; +loff_t actsize; -debug ("Filesize: %ld bytes\n" , filesize); + *gotsize =0 ; +debug ("Filesize: %llu bytes\n" , filesize);if (pos >= filesize) { -debug ("Read position past EOF: %lu\n" , pos); -return gotsize; +debug ("Read position past EOF: %llu\n" , pos); +return 0 ; }if (maxsize >0 && filesize > pos + maxsize) filesize = pos + maxsize; -debug ("%ld bytes\n" , filesize); +debug ("%llu bytes\n" , filesize); actsize = bytesperclust;@@ -352,7 +353,7 @@ get_contents(fsdata *mydata, dir_entry *dentptr, unsigned long pos,if (CHECK_CLUST (curclust, mydata->fatsize)) {debug ("curclust: 0x%x\n" , curclust);debug ("Invalid FAT entry\n" ); -return gotsize; +return 0 ; } actsize += bytesperclust; }@@ -373,16 +374,16 @@ get_contents(fsdata *mydata, dir_entry *dentptr, unsigned long pos, filesize -= actsize; actsize -= pos;memcpy (buffer, get_contents_vfatname_block + pos, actsize); - gotsize += actsize; + *gotsize += actsize;if (!filesize) -return gotsize; +return 0 ; buffer += actsize; curclust =get_fatent (mydata, curclust);if (CHECK_CLUST (curclust, mydata->fatsize)) {debug ("curclust: 0x%x\n" , curclust);debug ("Invalid FAT entry\n" ); -return gotsize; +return 0 ; } }@@ -398,7 +399,7 @@ get_contents(fsdata *mydata, dir_entry *dentptr, unsigned long pos,if (CHECK_CLUST (newclust, mydata->fatsize)) {debug ("curclust: 0x%x\n" , newclust);debug ("Invalid FAT entry\n" ); -return gotsize; +return 0 ; } endclust = newclust; actsize += bytesperclust;@@ -410,14 +411,14 @@ get_contents(fsdata *mydata, dir_entry *dentptr, unsigned long pos,printf ("Error reading cluster\n" );return -1 ; } - gotsize += actsize; -return gotsize; + *gotsize += actsize; +return 0 ; getit:if (get_cluster (mydata, curclust, buffer, (int )actsize) !=0 ) {printf ("Error reading cluster\n" );return -1 ; } - gotsize += (int )actsize; + *gotsize += (int )actsize; filesize -= actsize; buffer += actsize;@@ -425,7 +426,7 @@ getit:if (CHECK_CLUST (curclust, mydata->fatsize)) {debug ("curclust: 0x%x\n" , curclust);printf ("Invalid FAT entry\n" ); -return gotsize; +return 0 ; } actsize = bytesperclust; endclust = curclust;@@ -633,8 +634,8 @@ static dir_entry *get_dentfromdir(fsdata *mydata, int startsect, }if (doit) {if (dirc ==' ' ) { -printf (" %8ld %s%c\n" , - (long )FAT2CPU32 (dentptr->size), +printf (" %8u %s%c\n" , +FAT2CPU32 (dentptr->size), l_name, dirc); }else {@@ -690,8 +691,8 @@ static dir_entry *get_dentfromdir(fsdata *mydata, int startsect,if (doit) {if (dirc ==' ' ) { -printf (" %8ld %s%c\n" , - (long )FAT2CPU32 (dentptr->size), +printf (" %8u %s%c\n" , +FAT2CPU32 (dentptr->size), s_name, dirc); }else { printf(" %s%c\n",@@ -806,9 +807,8 @@ exit:__u8 do_fat_read_at_block[MAX_CLUSTSIZE ]__aligned(ARCH_DMA_MINALIGN) ; -long -do_fat_read_at (const char *filename,unsigned long pos,void *buffer, -unsigned long maxsize,int dols,int dogetsize) +int do_fat_read_at (const char *filename,loff_t pos,void *buffer, +loff_t maxsize,int dols,int dogetsize,loff_t *size) {char fnamecopy[2048 ];boot_sector bs;@@ -821,7 +821,7 @@ do_fat_read_at(const char *filename, unsigned long pos, void *buffer,__u32 cursect;int idx, isdir =0 ;int files =0 , dirs =0 ; -long ret =-1 ; +int ret =-1 ;int firsttime;__u32 root_cluster =0 ;int rootdir_size =0 ;@@ -974,8 +974,8 @@ do_fat_read_at(const char *filename, unsigned long pos, void *buffer, }if (doit) {if (dirc ==' ' ) { -printf (" %8ld %s%c\n" , - (long )FAT2CPU32 (dentptr->size), +printf (" %8u %s%c\n" , +FAT2CPU32 (dentptr->size), l_name, dirc); }else {@@ -1032,8 +1032,8 @@ do_fat_read_at(const char *filename, unsigned long pos, void *buffer, }if (doit) {if (dirc ==' ' ) { -printf (" %8ld %s%c\n" , - (long )FAT2CPU32 (dentptr->size), +printf (" %8u %s%c\n" , +FAT2CPU32 (dentptr->size), s_name, dirc); }else { printf(" %s%c\n",@@ -1102,7 +1102,7 @@ do_fat_read_at(const char *filename, unsigned long pos, void *buffer,if (dols ==LS_ROOT ) {printf ("\n%d file(s), %d dir(s)\n\n" , files, dirs); - ret =0 ; + *size =0 ; } goto exit; }@@ -1141,7 +1141,7 @@ rootdir_done:if (get_dentfromdir (mydata, startsect, subname, dentptr, isdir ?0 : dols) ==NULL ) {if (dols && !isdir) - ret =0 ; + *size =0 ; goto exit; }@@ -1152,21 +1152,23 @@ rootdir_done: subname = nextname; } -if (dogetsize) - ret =FAT2CPU32 (dentptr->size); -else - ret =get_contents (mydata, dentptr, pos, buffer, maxsize); -debug ("Size: %d, got: %ld\n" ,FAT2CPU32 (dentptr->size), ret); +if (dogetsize) { + *size =FAT2CPU32 (dentptr->size); + ret =0 ; + }else { + ret =get_contents (mydata, dentptr, pos, buffer, maxsize, size); + } +debug ("Size: %u, got: %llu\n" ,FAT2CPU32 (dentptr->size), *size); exit:free (mydata->fatbuf);return ret; } -long -do_fat_read (const char *filename,void *buffer,unsigned long maxsize,int dols) +int do_fat_read (const char *filename,void *buffer,loff_t maxsize,int dols, +loff_t *actread) { -return do_fat_read_at (filename,0 , buffer, maxsize, dols,0 ); +return do_fat_read_at (filename,0 , buffer, maxsize, dols,0 , actread); }int file_fat_detectfs (void )@@ -1233,44 +1235,63 @@ int file_fat_detectfs(void)int file_fat_ls (const char *dir) { -return do_fat_read (dir,NULL ,0 ,LS_YES ); +loff_t size; + +return do_fat_read (dir,NULL ,0 ,LS_YES , &size); }
Quoted 10 lines
fs/fat/fat.c int file_fat_detectfs(void) · line 1246
Quoted 7 lines
fs/fat/fat.c +2
-3int fat_exists (const char *filename) { -int sz; - sz =do_fat_read_at (filename,0 ,NULL ,0 ,LS_NO ,1 ); -return sz >=0 ; +int ret; +loff_t size;blank line here
OK
Quoted 4 lines
Quoted 4 lines
fs/fat/fat.c +2
-0+ ret =do_fat_read_at (filename,0 ,NULL ,0 ,LS_NO ,1 , &size); +return ret ==0 ; }
Quoted 8 lines
fs/fat/fat.c int file_fat_detectfs(void) · line 1254
Quoted 5 lines
fs/fat/fat.c +2
-1int fat_size (const char *filename) { -return do_fat_read_at (filename,0 ,NULL ,0 ,LS_NO ,1 ); +loff_t size; +int ret;indent those two lines
OK
Quoted 19 lines
Quoted 19 lines
fs/fat/fat.c +10
-3+ + ret =do_fat_read_at (filename,0 ,NULL ,0 ,LS_NO ,1 , &size); +if (ret) +return ret; +else +return size; } -long file_fat_read_at (const char *filename,unsigned long pos,void *buffer, -unsigned long maxsize) +int file_fat_read_at (const char *filename,loff_t pos,void *buffer, +loff_t maxsize,loff_t *actread) {printf ("reading %s\n" , filename); -return do_fat_read_at (filename, pos, buffer, maxsize,LS_NO ,0 ); +return do_fat_read_at (filename, pos, buffer, maxsize,LS_NO ,0 , + actread); }
Quoted 9 lines
fs/fat/fat.c int file_fat_detectfs(void) · line 1274
Quoted 6 lines
fs/fat/fat.c +3
-2-long file_fat_read (const char *filename,void *buffer,unsigned long maxsize) +int file_fat_read (const char *filename,void *buffer,int maxsize) { -return file_fat_read_at (filename,0 , buffer, maxsize); +loff_t actread; +int ret;indent those two lines
OK
Quoted 265 lines
Quoted 223 lines
fs/fat/fat.c +12
-5+ + ret =file_fat_read_at (filename,0 , buffer, maxsize, &actread); +if (ret) +return ret; +else +return actread; }int fat_read_file (const char *filename,void *buf,int offset,int len) { -int len_read; +int ret; +loff_t actread; - len_read =file_fat_read_at (filename, offset, buf, len); -if (len_read ==-1 ) { + ret =file_fat_read_at (filename, offset, buf, len, &actread); +if (ret) {printf ("** Unable to read file %s **\n" , filename); -return -1 ; +return ret; } -return len_read; +return actread; }void fat_close (void )fs/fat/fat_write.c +34
-27@@ -660,24 +660,26 @@ static int clear_fatent(fsdata *mydata, __u32 entry)/* * Write at most 'maxsize' bytes from 'buffer' into * the file associated with 'dentptr' -* Return the number of bytes read or -1 on fatal errors. +* Update the number of bytes written in *gotsize and return 0 +* or return -1 on fatal errors. */ static int set_contents (fsdata *mydata,dir_entry *dentptr,__u8 *buffer, -unsigned long maxsize) +loff_t maxsize,loff_t *gotsize) { -unsigned long filesize =FAT2CPU32 (dentptr->size), gotsize =0 ; +loff_t filesize =FAT2CPU32 (dentptr->size);unsigned int bytesperclust = mydata->clust_size * mydata->sect_size;__u32 curclust =START (dentptr);__u32 endclust =0 , newclust =0 ; -unsigned long actsize; +loff_t actsize; -debug ("Filesize: %ld bytes\n" , filesize); + *gotsize =0 ; +debug ("Filesize: %llu bytes\n" , filesize);if (maxsize >0 && filesize > maxsize) filesize = maxsize; -debug ("%ld bytes\n" , filesize); +debug ("%llu bytes\n" , filesize); actsize = bytesperclust; endclust = curclust;@@ -692,7 +694,7 @@ set_contents(fsdata *mydata, dir_entry *dentptr, __u8 *buffer,if (CHECK_CLUST (newclust, mydata->fatsize)) {debug ("curclust: 0x%x\n" , newclust);debug ("Invalid FAT entry\n" ); -return gotsize; +return 0 ; } endclust = newclust; actsize += bytesperclust;@@ -706,7 +708,7 @@ set_contents(fsdata *mydata, dir_entry *dentptr, __u8 *buffer, }/* set remaining bytes */ - gotsize += (int )actsize; + *gotsize += actsize; filesize -= actsize; buffer += actsize; actsize = filesize;@@ -715,7 +717,7 @@ set_contents(fsdata *mydata, dir_entry *dentptr, __u8 *buffer,debug ("error: writing cluster\n" );return -1 ; } - gotsize += actsize; + *gotsize += actsize;/* Mark end of file in FAT */ if (mydata->fatsize ==16 )@@ -724,20 +726,20 @@ set_contents(fsdata *mydata, dir_entry *dentptr, __u8 *buffer, newclust =0xfffffff ;set_fatent_value (mydata, endclust, newclust); -return gotsize; +return 0 ; getit:if (set_cluster (mydata, curclust, buffer, (int )actsize) !=0 ) {debug ("error: writing cluster\n" );return -1 ; } - gotsize += (int )actsize; + *gotsize += actsize; filesize -= actsize; buffer += actsize;if (CHECK_CLUST (curclust, mydata->fatsize)) {debug ("curclust: 0x%x\n" , curclust);debug ("Invalid FAT entry\n" ); -return gotsize; +return 0 ; } actsize = bytesperclust; curclust = endclust = newclust;@@ -766,7 +768,7 @@ static void fill_dentry(fsdata *mydata, dir_entry *dentptr,* exceed the size of the block device * Return -1 when overflow occurs, otherwise return 0 */ -static int check_overflow (fsdata *mydata,__u32 clustnum,unsigned long size) +static int check_overflow (fsdata *mydata,__u32 clustnum,loff_t size) {__u32 startsect, sect_num;@@ -923,8 +925,8 @@ static dir_entry *find_directory_entry(fsdata *mydata, int startsect,return NULL ; } -static int do_fat_write (const char *filename,void *buffer, -unsigned long size) +static int do_fat_write (const char *filename,void *buffer,loff_t size, +loff_t *actwrite) {dir_entry *dentptr, *retdent;__u32 startsect;@@ -936,8 +938,8 @@ static int do_fat_write(const char *filename, void *buffer,int cursect;int ret =-1 , name_len;char l_filename[VFAT_MAXLEN_BYTES ]; -int write_size = size; + *actwrite = size; dir_curclust =0 ;if (read_bootsectandvi (&bs, &volinfo, &mydata->fatsize)) {@@ -1015,7 +1017,7 @@ static int do_fat_write(const char *filename, void *buffer, ret =check_overflow (mydata, start_cluster, size);if (ret) { -printf ("Error: %ld overflow\n" , size); +printf ("Error: %llu overflow\n" , size); goto exit; }@@ -1025,13 +1027,12 @@ static int do_fat_write(const char *filename, void *buffer, goto exit; } - ret =set_contents (mydata, retdent, buffer, size); + ret =set_contents (mydata, retdent, buffer, size, actwrite);if (ret <0 ) {printf ("Error: writing contents\n" ); goto exit; } - write_size = ret; -debug ("attempt to write 0x%x bytes\n" , write_size); +debug ("attempt to write 0x%llx bytes\n" , *actwrite);/* Flush fat buffer */ ret =flush_fat_buffer (mydata);@@ -1061,7 +1062,7 @@ static int do_fat_write(const char *filename, void *buffer, ret =check_overflow (mydata, start_cluster, size);if (ret) { -printf ("Error: %ld overflow\n" , size); +printf ("Error: %llu overflow\n" , size); goto exit; }@@ -1069,13 +1070,13 @@ static int do_fat_write(const char *filename, void *buffer,fill_dentry (mydata, empty_dentptr, filename, start_cluster, size,0x20 ); - ret =set_contents (mydata, empty_dentptr, buffer, size); + ret =set_contents (mydata, empty_dentptr, buffer, size, + actwrite);if (ret <0 ) {printf ("Error: writing contents\n" ); goto exit; } - write_size = ret; -debug ("attempt to write 0x%x bytes\n" , write_size); +debug ("attempt to write 0x%llx bytes\n" , *actwrite);/* Flush fat buffer */ ret =flush_fat_buffer (mydata);@@ -1096,11 +1097,17 @@ static int do_fat_write(const char *filename, void *buffer, exit:free (mydata->fatbuf); -return ret <0 ? ret : write_size; +return ret; } -int file_fat_write (const char *filename,void *buffer,unsigned long maxsize) +int file_fat_write (const char *filename,void *buffer,loff_t offset, +loff_t maxsize,loff_t *actwrite) { +if (offset !=0 ) { +printf ("Error: non zero offset is currently not suported.\n" ); +return -1 ; + } +printf ("writing %s\n" , filename); -return do_fat_write (filename, buffer, maxsize); +return do_fat_write (filename, buffer, maxsize, actwrite); }fs/fat/file.c +0
-0fs/fat/file.c file_ls(const char *dir) · line 165
Quoted 6 lines
fs/fat/file.c +1
-2@@ -162,8 +162,8 @@ file_ls(const char *dir)return filesystems[current_filesystem].ls (arg); } -long -file_read (const char *filename,void *buffer,unsigned long maxsize) +int put on next line
Quoted 33 lines
fs/fat/file.c +1
-0+file_read(const char *filename, void *buffer, int maxsize) { char fullpath[1024];const char *arg;include/fat.h +5
-5@@ -178,8 +178,8 @@ typedef struct {typedef int (file_detectfs_func )(void );typedef int (file_ls_func )(const char *dir); -typedef long (file_read_func )(const char *filename,void *buffer, -unsigned long maxsize); +typedef int (file_read_func )(const char *filename,void *buffer, +int maxsize);struct filesystem {file_detectfs_func *detect;@@ -199,14 +199,15 @@ int file_fat_detectfs(void);int file_fat_ls (const char *dir);int fat_exists (const char *filename);int fat_size (const char *filename); -long file_fat_read_at (const char *filename,unsigned long pos,void *buffer, -unsigned long maxsize); -long file_fat_read (const char *filename,void *buffer,unsigned long maxsize); +int file_fat_read_at (const char *filename,loff_t pos,void *buffer, +loff_t maxsize,loff_t *actread); +int file_fat_read (const char *filename,void *buffer,int maxsize);const char *file_getfsname (int idx);int fat_set_blk_dev (block_dev_desc_t *rbdd,disk_partition_t *info);int fat_register_device (block_dev_desc_t *dev_desc,int part_no);
Quoted 12 lines
Quoted 9 lines
include/fat.h +2
-2-int file_fat_write (const char *filename,void *buffer,unsigned long maxsize); +int file_fat_write (const char *filename,void *buf,loff_t offset,loff_t len, +loff_t *actwrite);int fat_read_file (const char *filename,void *buf,int offset,int len);void fat_close (void );#endif /* _FAT_H_ */ --1.9.1
Regards,
Simon
Thanks for the review!
- Suriyan
PATCH v7 3/6 ext4: prepare for API change for files greater than 2GB
In reply to Suriyan RamasamiChange the internal ext4 functions to use loff_t for offsets.
---
Changes in v7:
* Split it so that its bisectable.
common/cmd_ext4.c | 61 +++++++-------------------------------------------- fs/ext4/ext4_common.c | 24 ++++++++++---------- fs/ext4/ext4_common.h | 4 ++-- fs/ext4/ext4_write.c | 32 +++++++++++++++++++++++++++ fs/ext4/ext4fs.c | 43 +++++++++++++++++++++++------------- include/ext4fs.h | 8 ++++--- 6 files changed, 88 insertions(+), 84 deletions(-)
common/cmd_ext4.c +8 -53
@@ -61,61 +61,16 @@ int do_ext4_ls(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])#if defined(CONFIG_CMD_EXT4_WRITE )int do_ext4_write (cmd_tbl_t *cmdtp,int flag,int argc, -char *const argv[]) +char *const argv[]) { -const char *filename ="/" ; -int dev, part; -unsigned long ram_address; -unsigned long file_size; -disk_partition_t info; -block_dev_desc_t *dev_desc; - -if (argc <6 ) -return cmd_usage (cmdtp); - - part =get_device_and_partition (argv[1 ], argv[2 ], &dev_desc, &info,1 ); -if (part <0 ) -return 1 ; - - dev = dev_desc->dev; - -/* get the filename */ - filename = argv[4 ]; - -/* get the address in hexadecimal format (string to int) */ - ram_address =simple_strtoul (argv[3 ],NULL ,16 ); - -/* get the filesize in hexadecimal format */ - file_size =simple_strtoul (argv[5 ],NULL ,16 ); - -/* set the device as block device */ -ext4fs_set_blk_dev (dev_desc, &info); - -/* mount the filesystem */ -if (!ext4fs_mount (info.size)) { -printf ("Bad ext4 partition %s %d:%d\n" , argv[1 ], dev, part); - goto fail; - } - -/* start write */ -if (ext4fs_write (filename, (unsigned char *)ram_address, file_size)) { -printf ("** Error ext4fs_write() **\n" ); - goto fail; - } -ext4fs_close (); - -return 0 ; - -fail: -ext4fs_close (); - -return 1 ; +return do_save (cmdtp, flag, argc, argv,FS_TYPE_EXT ); } -U_BOOT_CMD (ext4write,6 ,1 , do_ext4_write, -"create a file in the root directory" , -"<interface> <dev[:part]> <addr> <absolute filename path> [sizebytes]\n" -" - create a file in / directory" ); +U_BOOT_CMD (ext4write,7 ,1 , do_ext4_write, +"create a file in the root directory" , +"<interface> <dev[:part]> <addr> <absolute filename path>\n" +" [sizebytes] [file offset]\n" +" - create a file in / directory" );#endif
@@ -132,7 +87,7 @@ U_BOOT_CMD(ext4ls, 4, 1, do_ext4_ls,"<interface> <dev[:part]> [directory]\n" " - list files from 'dev' on 'interface' in a 'directory'"); -U_BOOT_CMD (ext4load,6 ,0 , do_ext4_load, +U_BOOT_CMD (ext4load,7 ,0 , do_ext4_load,"load binary file from a Ext4 filesystem" ,"<interface> [<dev[:part]> [addr [filename [bytes [pos]]]]]\n" " - load binary file 'filename' from 'dev' on 'interface'\n"
fs/ext4/ext4_common.c +13 -11
@@ -1891,6 +1891,7 @@ int ext4fs_iterate_dir(struct ext2fs_node *dir, char *name, {unsigned int fpos =0 ;int status; +loff_t actread;struct ext2fs_node *diro = (struct ext2fs_node *) dir;#ifdef DEBUG
@@ -1908,8 +1909,8 @@ int ext4fs_iterate_dir(struct ext2fs_node *dir, char *name, status =ext4fs_read_file (diro, fpos,sizeof (struct ext2_dirent ), - (char *) &dirent); -if (status <1 ) + (char *)&dirent, &actread); +if (status <0 )return 0 ;if (dirent.namelen !=0 ) {
@@ -1920,8 +1921,9 @@ int ext4fs_iterate_dir(struct ext2fs_node *dir, char *name, status =ext4fs_read_file (diro, fpos +sizeof (struct ext2_dirent ), - dirent.namelen, filename); -if (status <1 ) + dirent.namelen, filename, + &actread); +if (status <0 )return 0 ; fdiro =zalloc (sizeof (struct ext2fs_node ));
@@ -2003,8 +2005,8 @@ int ext4fs_iterate_dir(struct ext2fs_node *dir, char *name,printf ("< ? > " );break ; } -printf ("%10d %s\n" , -__le32_to_cpu (fdiro->inode.size), +printf ("%10u %s\n" , +__le32_to_cpu (fdiro->inode.size), filename); }free (fdiro);
@@ -2019,6 +2021,7 @@ static char *ext4fs_read_symlink(struct ext2fs_node *node)char *symlink;struct ext2fs_node *diro = node;int status; +loff_t actread;if (!diro->inode_read) { status =ext4fs_read_inode (diro->data, diro->ino, &diro->inode);
@@ -2035,7 +2038,7 @@ static char *ext4fs_read_symlink(struct ext2fs_node *node) }else { status =ext4fs_read_file (diro,0 ,__le32_to_cpu (diro->inode.size), - symlink); + symlink, &actread);if (status ==0 ) {free (symlink);return 0 ;
@@ -2169,11 +2172,10 @@ int ext4fs_find_file(const char *path, struct ext2fs_node *rootnode,return 1 ; } -int ext4fs_open (const char *filename) +int ext4fs_open (const char *filename,loff_t *len) {struct ext2fs_node *fdiro =NULL ;int status; -int len;if (ext4fs_root ==NULL )return -1 ;
@@ -2190,10 +2192,10 @@ int ext4fs_open(const char *filename)if (status ==0 ) goto fail; } - len =__le32_to_cpu (fdiro->inode.size); + *len =__le32_to_cpu (fdiro->inode.size); ext4fs_file = fdiro; -return len; +return 0 ; fail:ext4fs_free_node (fdiro, &ext4fs_root->diropen);
fs/ext4/ext4_common.h +2 -2
@@ -50,8 +50,8 @@ static inline void *zalloc(size_t size)int ext4fs_read_inode (struct ext2_data *data,int ino,struct ext2_inode *inode); -int ext4fs_read_file (struct ext2fs_node *node,int pos, -unsigned int len,char *buf); +int ext4fs_read_file (struct ext2fs_node *node,loff_t pos,loff_t len, +char *buf,loff_t *actread);int ext4fs_find_file (const char *path,struct ext2fs_node *rootnode,struct ext2fs_node **foundnode,int expecttype); int ext4fs_iterate_dir(struct ext2fs_node *dir, char *name,
fs/ext4/ext4_write.c +32 -0
@@ -975,3 +975,35 @@ fail:return -1 ; } + +int ext4_write_file (const char *filename,void *buf,loff_t offset, +loff_t len,loff_t *actwrite) +{ +int ret; + +if (offset !=0 ) { +printf ("** Cannot support non-zero offset **\n" ); +return -1 ; + } + +/* mount the filesystem */ +if (!ext4fs_mount (0 )) { +printf ("** Error Bad ext4 partition **\n" ); + goto fail; + } + + ret =ext4fs_write (filename, buf, len); + +if (ret) { +printf ("** Error ext4fs_write() **\n" ); + goto fail; + } +ext4fs_close (); + +return 0 ; + +fail: +ext4fs_close (); + +return -1 ; +}
fs/ext4/ext4fs.c +28 -15
89 lines not on this page · raw message
include/ext4fs.h +5 -3
@@ -125,12 +125,14 @@ int ext4fs_init(void);void ext4fs_deinit (void );int ext4fs_filename_check (char *filename);int ext4fs_write (const char *fname,unsigned char *buffer, -unsigned long sizebytes); +unsigned long sizebytes); +int ext4_write_file (const char *filename,void *buf,loff_t offset,loff_t len, +loff_t *actwrite);#endif struct ext_filesystem *get_fs (void ); -int ext4fs_open (const char *filename); -int ext4fs_read (char *buf,unsigned len); +int ext4fs_open (const char *filename,loff_t *len); +int ext4fs_read (char *buf,loff_t len,loff_t *actread);int ext4fs_mount (unsigned part_length);void ext4fs_close (void );void ext4fs_reinit_global (void );
Signature · 1 line
1.9.1
PATCH v7 3/6 ext4: prepare for API change for files greater than 2GB
Quoted 8 lines · Suriyan Ramasami
Change the internal ext4 functions to use
loff_tfor offsets.Signed-off-by Suriyan Ramasami <[email protected]>---
Changes in v7:
* Split it so that its bisectable.
I'll see if I can test this on real hardware :-)
PATCH v7 4/6 sandbox: prepare for API change for files greater than 2GB
In reply to Suriyan RamasamiChange the internal ext4 functions to use loff_t for offsets.
---
Changes in v7:
* Split it so that its bisectable.
arch/sandbox/cpu/os.c | 13 ++++---- arch/sandbox/cpu/state.c | 8 ++--- common/board_f.c | 8 ++--- fs/sandbox/sandboxfs.c | 78 ++++++++++++++++++++++++++++++++++-------------- include/os.h | 5 ++-- include/sandboxfs.h | 6 ++-- 6 files changed, 77 insertions(+), 41 deletions(-)
arch/sandbox/cpu/os.c +7 -6
@@ -385,7 +385,7 @@ const char *os_dirent_get_typename(enum os_dirent_t type)return os_dirent_typename[OS_FILET_UNKNOWN ]; } -ssize_t os_get_filesize (const char *fname) +int os_get_filesize (const char *fname,loff_t *size) {struct stat buf;int ret;
@@ -393,7 +393,8 @@ ssize_t os_get_filesize(const char *fname) ret =stat (fname, &buf);if (ret)return ret; -return buf.st_size; + *size = buf.st_size; +return 0 ; }void os_putc (int ch)
@@ -427,11 +428,11 @@ int os_read_ram_buf(const char *fname) {struct sandbox_state *state =state_get_current ();int fd, ret; -int size; +loff_t size; - size =os_get_filesize (fname); -if (size <0 ) -return -ENOENT ; + ret =os_get_filesize (fname, &size); +if (ret <0 ) +return ret;if (size != state->ram_size)return -ENOSPC ; fd =open (fname,O_RDONLY );
arch/sandbox/cpu/state.c +4 -4
@@ -49,14 +49,14 @@ static int state_ensure_space(int extra_size)static int state_read_file (struct sandbox_state *state,const char *fname) { -int size; +loff_t size;int ret;int fd; - size =os_get_filesize (fname); -if (size <0 ) { + ret =os_get_filesize (fname, &size); +if (ret <0 ) {printf ("Cannot find sandbox state file '%s'\n" , fname); -return -ENOENT ; +return ret; } state->state_fdt =os_malloc (size);if (!state->state_fdt) {
common/board_f.c +4 -4
@@ -291,7 +291,7 @@ static int read_fdt_from_file(void)struct sandbox_state *state =state_get_current ();const char *fname = state->fdt_fname;void *blob; -ssize_t size; +loff_t size;int err;int fd;
@@ -304,10 +304,10 @@ static int read_fdt_from_file(void)return -EINVAL ; } - size =os_get_filesize (fname); -if (size <0 ) { + err =os_get_filesize (fname, &size); +if (err <0 ) {printf ("Failed to file FDT file '%s'\n" , fname); -return -ENOENT ; +return err; } fd =os_open (fname,OS_O_RDONLY );if (fd <0 ) {
fs/sandbox/sandboxfs.c +55 -23
129 lines not on this page · raw message
include/os.h +3 -2
@@ -217,9 +217,10 @@ const char *os_dirent_get_typename(enum os_dirent_t type);* Get the size of a file * * @param fname Filename to check -* @return size of file, or -1 if an error ocurred +* @param size size of file is returned if no error +* @return 0 on success or -1 if an error ocurred */ -ssize_t os_get_filesize (const char *fname); +int os_get_filesize (const char *fname,loff_t *size);/** * Write a character to the controlling OS terminal
include/sandboxfs.h +4 -2
@@ -20,8 +20,10 @@int sandbox_fs_set_blk_dev (block_dev_desc_t *rbdd,disk_partition_t *info); -long sandbox_fs_read_at (const char *filename,unsigned long pos, -void *buffer,unsigned long maxsize); +int sandbox_fs_read_at (const char *filename,loff_t pos,void *buffer, +loff_t maxsize,loff_t *actread); +int sandbox_fs_write_at (const char *filename,loff_t pos,void *buffer, +loff_t maxsize,loff_t *actwrite);void sandbox_fs_close (void );int sandbox_fs_ls (const char *dirname);
Signature · 1 line
1.9.1
PATCH v7 4/6 sandbox: prepare for API change for files greater than 2GB
Quoted 3 lines · Suriyan Ramasami
Change the internal ext4 functions to use
loff_tfor offsets.Signed-off-by Suriyan Ramasami <[email protected]>
(BTW you could be more consistent with size, sz, file_size - choose one!)
PATCH v7 4/6 sandbox: prepare for API change for files greater than 2GB
Quoted 8 lines · Simon Glass
Quoted 3 lines · Suriyan Ramasami
Change the internal ext4 functions to use
loff_tfor offsets.Signed-off-by Suriyan Ramasami <[email protected]>Acked-by Simon Glass <[email protected]>(BTW you could be more consistent with size, sz,
file_size- choose one!)
OK, let me fix that!
PATCH v7 5/6 fs: API changes to enable extra parameter to return size of type loff_t
In reply to Suriyan RamasamiThe sandbox/ext4/fat/generic fs commands do not gracefully deal with file greater than 2GB. Negative values are returned in such cases.
To handle this, the fs functions have been modified to take an additional parameter of type "* loff_t" which is then populated. The return value of the fs fucntions are used only for error conditions.
---
Changes in v7:
* Simon - API change in separate patch
common/cmd_fs.c | 17 +++++++++++ fs/ext4/ext4fs.c | 22 ++++----------- fs/fat/fat.c | 20 ++++--------- fs/fs.c | 77 ++++++++++++++++++++++++++++++-------------------- fs/sandbox/sandboxfs.c | 29 +++++++------------ include/ext4fs.h | 5 ++-- include/fat.h | 5 ++-- include/fs.h | 41 ++++++++++++++++----------- include/sandboxfs.h | 8 ++++-- 9 files changed, 121 insertions(+), 103 deletions(-)
common/cmd_fs.c +17 -0
@@ -51,6 +51,23 @@ U_BOOT_CMD( " If 'pos' is 0 or omitted, the file is read from the start." ) +static int do_save_wrapper (cmd_tbl_t *cmdtp,int flag,int argc, +char *const argv[]) +{ +return do_save (cmdtp, flag, argc, argv,FS_TYPE_ANY ); +} + +U_BOOT_CMD ( + save,7 ,0 , do_save_wrapper, +"save file to a filesystem" , +"<interface> <dev[:part]> <addr> <filename> bytes [pos]\n" +" - Save binary file 'filename' to partition 'part' on device\n" +" type 'interface' instance 'dev' from addr 'addr' in memory.\n" +" 'bytes' gives the size to save in bytes and is mandatory.\n" +" 'pos' gives the file byte position to start writing to.\n" +" If 'pos' is 0 or omitted, the file is written from the start." +) +static int do_ls_wrapper (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) {
fs/ext4/ext4fs.c +6 -16
@@ -184,16 +184,9 @@ int ext4fs_exists(const char *filename)return ret ==0 ; } -int ext4fs_size (const char *filename) +int ext4fs_size (const char *filename,loff_t *size) { -loff_t size; -int ret; - - ret =ext4fs_open (filename, &size); -if (ret) -return ret; -else -return size; +return ext4fs_open (filename, size); }int ext4fs_read (char *buf,loff_t len,loff_t *actread)
@@ -217,10 +210,10 @@ int ext4fs_probe(block_dev_desc_t *fs_dev_desc,return 0 ; } -int ext4_read_file (const char *filename,void *buf,int offset,int len) +int ext4_read_file (const char *filename,void *buf,loff_t offset,loff_t len, +loff_t *len_read) {loff_t file_len; -loff_t len_read;int ret;if (offset !=0 ) {
@@ -237,10 +230,7 @@ int ext4_read_file(const char *filename, void *buf, int offset, int len)if (len ==0 ) len = file_len; - ret =ext4fs_read (buf, len, &len_read); + ret =ext4fs_read (buf, len, len_read); -if (ret) -return ret; -else -return len_read; +return ret; }
fs/fat/fat.c +6 -14
@@ -1248,16 +1248,9 @@ int fat_exists(const char *filename)return ret ==0 ; } -int fat_size (const char *filename) +int fat_size (const char *filename,loff_t *size) { -loff_t size; -int ret; - - ret =do_fat_read_at (filename,0 ,NULL ,0 ,LS_NO ,1 , &size); -if (ret) -return ret; -else -return size; +return do_fat_read_at (filename,0 ,NULL ,0 ,LS_NO ,1 , size); } int file_fat_read_at(const char *filename, loff_t pos, void *buffer,
@@ -1280,18 +1273,17 @@ int ret;return actread; } -int fat_read_file (const char *filename,void *buf,int offset,int len) +int fat_read_file (const char *filename,void *buf,loff_t offset,loff_t len, +loff_t *actread) {int ret; -loff_t actread; - ret =file_fat_read_at (filename, offset, buf, len, &actread); + ret =file_fat_read_at (filename, offset, buf, len, actread);if (ret) {printf ("** Unable to read file %s **\n" , filename); -return ret; } -return actread; +return ret; }void fat_close (void )
fs/fs.c +46 -31
201 lines not on this page · raw message
fs/sandbox/sandboxfs.c +10 -19
@@ -103,46 +103,37 @@ int sandbox_fs_exists(const char *filename)return ret ==0 ; } -int sandbox_fs_size (const char *filename) +int sandbox_fs_size (const char *filename,loff_t *size) { -loff_t size; -int ret; - - ret =os_get_filesize (filename, &size); -if (ret) -return ret; -else -return size; +return os_get_filesize (filename, size); }void sandbox_fs_close (void ) { } -int fs_read_sandbox (const char *filename,void *buf,int offset,int len) +int fs_read_sandbox (const char *filename,void *buf,loff_t offset,loff_t len, +loff_t *actread) {int ret; -loff_t actread; - ret =sandbox_fs_read_at (filename, offset, buf, len, &actread); + ret =sandbox_fs_read_at (filename, offset, buf, len, actread);if (ret) {printf ("** Unable to read file %s **\n" , filename); -return ret; } -return actread; +return ret; } -int fs_write_sandbox (const char *filename,void *buf,int offset,int len) +int fs_write_sandbox (const char *filename,void *buf,loff_t offset, +loff_t len,loff_t *actwrite) {int ret; -loff_t actwrite; - ret =sandbox_fs_write_at (filename, offset, buf, len, &actwrite); + ret =sandbox_fs_write_at (filename, offset, buf, len, actwrite);if (ret) {printf ("** Unable to write file %s **\n" , filename); -return ret; } -return actwrite; +return ret; }
include/ext4fs.h +3 -2
@@ -138,13 +138,14 @@ void ext4fs_close(void);void ext4fs_reinit_global (void );int ext4fs_ls (const char *dirname);int ext4fs_exists (const char *filename); -int ext4fs_size (const char *filename); +int ext4fs_size (const char *filename,loff_t *size);void ext4fs_free_node (struct ext2fs_node *node,struct ext2fs_node *currroot);int ext4fs_devread (lbaint_t sector,int byte_offset,int byte_len,char *buf);void ext4fs_set_blk_dev (block_dev_desc_t *rbdd,disk_partition_t *info);long int read_allocated_block (struct ext2_inode *inode,int fileblock);int ext4fs_probe (block_dev_desc_t *fs_dev_desc,disk_partition_t *fs_partition); -int ext4_read_file (const char *filename,void *buf,int offset,int len); +int ext4_read_file (const char *filename,void *buf,loff_t offset,loff_t len, +loff_t *actread);int ext4_read_superblock (char *buffer);#endif
include/fat.h +3 -2
@@ -198,7 +198,7 @@ int file_cd(const char *path);int file_fat_detectfs (void );int file_fat_ls (const char *dir);int fat_exists (const char *filename); -int fat_size (const char *filename); +int fat_size (const char *filename,loff_t *size);int file_fat_read_at (const char *filename,loff_t pos,void *buffer,loff_t maxsize,loff_t *actread);int file_fat_read (const char *filename,void *buffer,int maxsize);
@@ -208,6 +208,7 @@ int fat_register_device(block_dev_desc_t *dev_desc, int part_no);int file_fat_write (const char *filename,void *buf,loff_t offset,loff_t len,loff_t *actwrite); -int fat_read_file (const char *filename,void *buf,int offset,int len); +int fat_read_file (const char *filename,void *buf,loff_t offset,loff_t len, +loff_t *actread);void fat_close (void );#endif /* _FAT_H_ */
include/fs.h +25 -16
57 lines not on this page · raw message
include/sandboxfs.h +5 -3
@@ -28,8 +28,10 @@ int sandbox_fs_write_at(const char *filename, loff_t pos, void *buffer,void sandbox_fs_close (void );int sandbox_fs_ls (const char *dirname);int sandbox_fs_exists (const char *filename); -int sandbox_fs_size (const char *filename); -int fs_read_sandbox (const char *filename,void *buf,int offset,int len); -int fs_write_sandbox (const char *filename,void *buf,int offset,int len); +int sandbox_fs_size (const char *filename,loff_t *size); +int fs_read_sandbox (const char *filename,void *buf,loff_t offset,loff_t len, +loff_t *actread); +int fs_write_sandbox (const char *filename,void *buf,loff_t offset, +loff_t len,loff_t *actwrite);#endif
Signature · 1 line
1.9.1
PATCH v7 5/6 fs: API changes to enable extra parameter to return size of type loff_t
Quoted 8 lines · Suriyan Ramasami
The sandbox/ext4/fat/generic fs commands do not gracefully deal with file greater than 2GB. Negative values are returned in such cases.
To handle this, the fs functions have been modified to take an additional parameter of type "*
loff_t" which is then populated. The return value of the fs fucntions are used only for error conditions.Signed-off-by Suriyan Ramasami <[email protected]>
A few nits below, but:
Quoted 83 lines
---
Changes in v7:
* Simon - API change in separate patchcommon/cmd_fs.c | 17 +++++++++++ fs/ext4/ext4fs.c | 22 ++++----------- fs/fat/fat.c | 20 ++++--------- fs/fs.c | 77 ++++++++++++++++++++++++++++++-------------------- fs/sandbox/sandboxfs.c | 29 +++++++------------ include/ext4fs.h | 5 ++-- include/fat.h | 5 ++-- include/fs.h | 41 ++++++++++++++++----------- include/sandboxfs.h | 8 ++++-- 9 files changed, 121 insertions(+), 103 deletions(-)common/cmd_fs.c +17
-0@@ -51,6 +51,23 @@ U_BOOT_CMD( " If 'pos' is 0 or omitted, the file is read from the start." ) +static int do_save_wrapper (cmd_tbl_t *cmdtp,int flag,int argc, +char *const argv[]) +{ +return do_save (cmdtp, flag, argc, argv,FS_TYPE_ANY ); +} + +U_BOOT_CMD ( + save,7 ,0 , do_save_wrapper, +"save file to a filesystem" , +"<interface> <dev[:part]> <addr> <filename> bytes [pos]\n" +" - Save binary file 'filename' to partition 'part' on device\n" +" type 'interface' instance 'dev' from addr 'addr' in memory.\n" +" 'bytes' gives the size to save in bytes and is mandatory.\n" +" 'pos' gives the file byte position to start writing to.\n" +" If 'pos' is 0 or omitted, the file is written from the start." +) +static int do_ls_wrapper (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) {fs/ext4/ext4fs.c +4
-11@@ -184,16 +184,9 @@ int ext4fs_exists(const char *filename)return ret ==0 ; } -int ext4fs_size (const char *filename) +int ext4fs_size (const char *filename,loff_t *size) { -loff_t size; -int ret; - - ret =ext4fs_open (filename, &size); -if (ret) -return ret; -else -return size; +return ext4fs_open (filename, size); }int ext4fs_read (char *buf,loff_t len,loff_t *actread)@@ -217,10 +210,10 @@ int ext4fs_probe(block_dev_desc_t *fs_dev_desc,return 0 ; } -int ext4_read_file (const char *filename,void *buf,int offset,int len) +int ext4_read_file (const char *filename,void *buf,loff_t offset,loff_t len, +loff_t *len_read) {loff_t file_len; -loff_t len_read;int ret;if (offset !=0 ) {@@ -237,10 +230,7 @@ int ext4_read_file(const char *filename, void *buf, int offset, int len)if (len ==0 )
fs/ext4/ext4fs.c int ext4_read_file(const char *filename, void *buf, int offset, int len) · line 235
Quoted 10 lines
fs/ext4/ext4fs.c +2
-5len = file_len; - ret =ext4fs_read (buf, len, &len_read); + ret =ext4fs_read (buf, len, len_read); -if (ret) -return ret; -else -return len_read; +return ret;
Probably don't need ret here
Quoted 31 lines
fs/ext4/ext4fs.c +0
-0}fs/fat/fat.c +4
-10@@ -1248,16 +1248,9 @@ int fat_exists(const char *filename)return ret ==0 ; } -int fat_size (const char *filename) +int fat_size (const char *filename,loff_t *size) { -loff_t size; -int ret; - - ret =do_fat_read_at (filename,0 ,NULL ,0 ,LS_NO ,1 , &size); -if (ret) -return ret; -else -return size; +return do_fat_read_at (filename,0 ,NULL ,0 ,LS_NO ,1 , size); } int file_fat_read_at(const char *filename, loff_t pos, void *buffer,@@ -1280,18 +1273,17 @@ int ret;return actread; } -int fat_read_file (const char *filename,void *buf,int offset,int len) +int fat_read_file (const char *filename,void *buf,loff_t offset,loff_t len, +loff_t *actread)
fs/fat/fat.c int ret; · line 1284
Quoted 10 lines
fs/fat/fat.c +1
-3{int ret; -loff_t actread; - ret =file_fat_read_at (filename, offset, buf, len, &actread); + ret =file_fat_read_at (filename, offset, buf, len, actread);if (ret) {printf ("** Unable to read file %s **\n" , filename); -return ret; }
Remove {} around that
Quoted 254 lines
fs/fat/fat.c +1
-1-return actread; +return ret; }void fat_close (void )fs/fs.c +46
-31@@ -46,19 +46,21 @@ static inline int fs_exists_unsupported(const char *filename)return 0 ; } -static inline int fs_size_unsupported (const char *filename) +static inline int fs_size_unsupported (const char *filename,loff_t *size) {return -1 ; }static inline int fs_read_unsupported (const char *filename,void *buf, -int offset,int len) +loff_t offset,loff_t len, +loff_t *actread) {return -1 ; }static inline int fs_write_unsupported (const char *filename,void *buf, -int offset,int len) +loff_t offset,loff_t len, +loff_t *actwrite) {return -1 ; }@@ -82,9 +84,11 @@ struct fstype_info { disk_partition_t *fs_partition);int (*ls)(const char *dirname);int (*exists)(const char *filename); -int (*size)(const char *filename); -int (*read)(const char *filename,void *buf,int offset,int len); -int (*write)(const char *filename,void *buf,int offset,int len); +int (*size)(const char *filename,loff_t *size); +int (*read)(const char *filename,void *buf,loff_t offset, +loff_t len,loff_t *actread); +int (*write)(const char *filename,void *buf,loff_t offset, +loff_t len,loff_t *actwrite);void (*close)(void ); };@@ -99,7 +103,11 @@ static struct fstype_info fstypes[] = { .exists = fat_exists, .size = fat_size, .read = fat_read_file, +#ifdef CONFIG_FAT_WRITE + .write = file_fat_write, +#else .write = fs_write_unsupported, +#endif }, #endif #ifdef CONFIG_FS_EXT4@@ -112,7 +120,11 @@ static struct fstype_info fstypes[] = { .exists = ext4fs_exists, .size = ext4fs_size, .read = ext4_read_file, +#ifdef CONFIG_CMD_EXT4_WRITE + .write = ext4_write_file, +#else .write = fs_write_unsupported, +#endif }, #endif #ifdef CONFIG_SANDBOX@@ -233,20 +245,21 @@ int fs_exists(const char *filename)return ret; } -int fs_size (const char *filename) +int fs_size (const char *filename,loff_t *size) {int ret;struct fstype_info *info =fs_get_info (fs_type); - ret = info->size (filename); + ret = info->size (filename, size);fs_close ();return ret; } -int fs_read (const char *filename,ulong addr,int offset,int len) +int fs_read (const char *filename,ulong addr,loff_t offset,loff_t len, +loff_t *actread) {struct fstype_info *info =fs_get_info (fs_type);void *buf;@@ -257,11 +270,11 @@ int fs_read(const char *filename, ulong addr, int offset, int len)* means read the whole file. */ buf =map_sysmem (addr, len); - ret = info->read (filename, buf, offset, len); + ret = info->read (filename, buf, offset, len, actread);unmap_sysmem (buf);/* If we requested a specific number of bytes, check we got it */ -if (ret >=0 && len && ret != len) { +if (ret ==0 && len && *actread != len) {printf ("** Unable to read file %s **\n" , filename); ret =-1 ; }@@ -270,17 +283,18 @@ int fs_read(const char *filename, ulong addr, int offset, int len)return ret; } -int fs_write (const char *filename,ulong addr,int offset,int len) +int fs_write (const char *filename,ulong addr,loff_t offset,loff_t len, +loff_t *actwrite) {struct fstype_info *info =fs_get_info (fs_type);void *buf;int ret; buf =map_sysmem (addr, len); - ret = info->write (filename, buf, offset, len); + ret = info->write (filename, buf, offset, len, actwrite);unmap_sysmem (buf); -if (ret >=0 && ret != len) { +if (ret <0 && len != *actwrite) {printf ("** Unable to write file %s **\n" , filename); ret =-1 ; }@@ -292,7 +306,7 @@ int fs_write(const char *filename, ulong addr, int offset, int len)int do_size (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[],int fstype) { -int size; +loff_t size;if (argc !=4 )return CMD_RET_USAGE ;@@ -300,8 +314,7 @@ int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],if (fs_set_blk_dev (argv[1 ], argv[2 ], fstype))return 1 ; - size =fs_size (argv[3 ]); -if (size <0 ) +if (fs_size (argv[3 ], &size) <0 )return CMD_RET_FAILURE ;setenv_hex ("filesize" , size);@@ -315,9 +328,10 @@ int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],unsigned long addr;const char *addr_str;const char *filename; -unsigned long bytes; -unsigned long pos; -int len_read; +loff_t bytes; +loff_t pos; +loff_t len_read; +int ret;unsigned long time;char *ep;@@ -359,12 +373,12 @@ int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], pos =0 ; time =get_timer (0 ); - len_read =fs_read (filename, addr, pos, bytes); + ret =fs_read (filename, addr, pos, bytes, &len_read); time =get_timer (time); -if (len_read <=0 ) +if (ret <0 )return 1 ; -printf ("%d bytes read in %lu ms" , len_read, time); +printf ("%llu bytes read in %lu ms" , len_read, time);if (time >0 ) {puts (" (" );print_size (len_read / time *1000 ,"/s" );@@ -408,9 +422,10 @@ int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], {unsigned long addr;const char *filename; -unsigned long bytes; -unsigned long pos; -int len; +loff_t bytes; +loff_t pos; +loff_t len; +int ret;unsigned long time;if (argc <6 || argc >7 )@@ -419,8 +434,8 @@ int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],if (fs_set_blk_dev (argv[1 ], argv[2 ], fstype))return 1 ; - filename = argv[3 ]; - addr =simple_strtoul (argv[4 ],NULL ,16 ); + addr =simple_strtoul (argv[3 ],NULL ,16 ); + filename = argv[4 ]; bytes =simple_strtoul (argv[5 ],NULL ,16 );if (argc >=7 ) pos =simple_strtoul (argv[6 ],NULL ,16 );@@ -428,12 +443,12 @@ int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], pos =0 ; time =get_timer (0 ); - len =fs_write (filename, addr, pos, bytes); + ret =fs_write (filename, addr, pos, bytes, &len); time =get_timer (time); -if (len <=0 ) +if (ret <0 )return 1 ; -printf ("%d bytes written in %lu ms" , len, time); +printf ("%llu bytes written in %lu ms" , len, time);if (time >0 ) {puts (" (" );print_size (len / time *1000 ,"/s" );fs/sandbox/sandboxfs.c +4
-10@@ -103,46 +103,37 @@ int sandbox_fs_exists(const char *filename)return ret ==0 ; } -int sandbox_fs_size (const char *filename) +int sandbox_fs_size (const char *filename,loff_t *size) { -loff_t size; -int ret; - - ret =os_get_filesize (filename, &size); -if (ret) -return ret; -else -return size; +return os_get_filesize (filename, size); }void sandbox_fs_close (void ) { } -int fs_read_sandbox (const char *filename,void *buf,int offset,int len) +int fs_read_sandbox (const char *filename,void *buf,loff_t offset,loff_t len, +loff_t *actread)
fs/sandbox/sandboxfs.c int sandbox_fs_exists(const char *filename) · line 123
Quoted 10 lines
fs/sandbox/sandboxfs.c +1
-3{int ret; -loff_t actread; - ret =sandbox_fs_read_at (filename, offset, buf, len, &actread); + ret =sandbox_fs_read_at (filename, offset, buf, len, actread);if (ret) {printf ("** Unable to read file %s **\n" , filename); -return ret; }
Remove {}
Quoted 8 lines
fs/sandbox/sandboxfs.c +3
-2-return actread; +return ret; } -int fs_write_sandbox (const char *filename,void *buf,int offset,int len) +int fs_write_sandbox (const char *filename,void *buf,loff_t offset, +loff_t len,loff_t *actwrite)
fs/sandbox/sandboxfs.c int sandbox_fs_exists(const char *filename) · line 136
Quoted 10 lines
fs/sandbox/sandboxfs.c +1
-3{int ret; -loff_t actwrite; - ret =sandbox_fs_write_at (filename, offset, buf, len, &actwrite); + ret =sandbox_fs_write_at (filename, offset, buf, len, actwrite);if (ret) {printf ("** Unable to write file %s **\n" , filename); -return ret; }
Remove {}
Quoted 128 lines
fs/sandbox/sandboxfs.c +1
-1-return actwrite; +return ret; }include/ext4fs.h +3
-2@@ -138,13 +138,14 @@ void ext4fs_close(void);void ext4fs_reinit_global (void );int ext4fs_ls (const char *dirname);int ext4fs_exists (const char *filename); -int ext4fs_size (const char *filename); +int ext4fs_size (const char *filename,loff_t *size);void ext4fs_free_node (struct ext2fs_node *node,struct ext2fs_node *currroot);int ext4fs_devread (lbaint_t sector,int byte_offset,int byte_len,char *buf);void ext4fs_set_blk_dev (block_dev_desc_t *rbdd,disk_partition_t *info);long int read_allocated_block (struct ext2_inode *inode,int fileblock);int ext4fs_probe (block_dev_desc_t *fs_dev_desc,disk_partition_t *fs_partition); -int ext4_read_file (const char *filename,void *buf,int offset,int len); +int ext4_read_file (const char *filename,void *buf,loff_t offset,loff_t len, +loff_t *actread);int ext4_read_superblock (char *buffer);#endif include/fat.h +3
-2@@ -198,7 +198,7 @@ int file_cd(const char *path);int file_fat_detectfs (void );int file_fat_ls (const char *dir);int fat_exists (const char *filename); -int fat_size (const char *filename); +int fat_size (const char *filename,loff_t *size);int file_fat_read_at (const char *filename,loff_t pos,void *buffer,loff_t maxsize,loff_t *actread);int file_fat_read (const char *filename,void *buffer,int maxsize);@@ -208,6 +208,7 @@ int fat_register_device(block_dev_desc_t *dev_desc, int part_no);int file_fat_write (const char *filename,void *buf,loff_t offset,loff_t len,loff_t *actwrite); -int fat_read_file (const char *filename,void *buf,int offset,int len); +int fat_read_file (const char *filename,void *buf,loff_t offset,loff_t len, +loff_t *actread);void fat_close (void );#endif /* _FAT_H_ */ include/fs.h +25
-16@@ -51,32 +51,41 @@ int fs_ls(const char *dirname);int fs_exists (const char *filename);/* -* Determine a file's size +* fs_size - Determine a file's size * -* Returns the file's size in bytes, or a negative value if it doesn't exist. +* @filename: Name of the file +* @size: Size of file +* @return 0 if ok with valid *size, negative on error */ -int fs_size (const char *filename); +int fs_size (const char *filename,loff_t *size);/* -* Read file "filename" from the partition previously set by fs_set_blk_dev(), -* to address "addr", starting at byte offset "offset", and reading "len" -* bytes. "offset" may be 0 to read from the start of the file. "len" may be -* 0 to read the entire file. Note that not all filesystem types support -* either/both offset!=0 or len!=0. +* fs_read - Read file from the partition previously set by fs_set_blk_dev() +* Note that not all filesystem types support either/both offset!=0 or len!=0. * -* Returns number of bytes read on success. Returns <= 0 on error. +* @filename: Name of file to read from +* @addr: The address to read into +* @offset: The offset in file to read from +* @len: The number of bytes to read. Maybe 0 to read entire file +* @actread: Returns the actual number of bytes read +* @return 0 if ok with valid *actread, -1 on error conditions */ -int fs_read (const char *filename,ulong addr,int offset,int len); +int fs_read (const char *filename,ulong addr,loff_t offset,loff_t len, +loff_t *actread);/* -* Write file "filename" to the partition previously set by fs_set_blk_dev(), -* from address "addr", starting at byte offset "offset", and writing "len" -* bytes. "offset" may be 0 to write to the start of the file. Note that not -* all filesystem types support offset!=0. +* fs_write - Write file to the partition previously set by fs_set_blk_dev() +* Note that not all filesystem types support offset!=0. * -* Returns number of bytes read on success. Returns <= 0 on error. +* @filename: Name of file to read from +* @addr: The address to read into +* @offset: The offset in file to read from. Maybe 0 to write to start of file +* @len: The number of bytes to write +* @actwrite: Returns the actual number of bytes written +* @return 0 if ok with valid *actwrite, -1 on error conditions */ -int fs_write (const char *filename,ulong addr,int offset,int len); +int fs_write (const char *filename,ulong addr,loff_t offset,loff_t len, +loff_t *actwrite);/* * Common implementation for various filesystem commands, optionally limited include/sandboxfs.h +5
-4@@ -28,8 +28,10 @@ int sandbox_fs_write_at(const char *filename, loff_t pos, void *buffer,void sandbox_fs_close (void );int sandbox_fs_ls (const char *dirname);int sandbox_fs_exists (const char *filename); -int sandbox_fs_size (const char *filename); -int fs_read_sandbox (const char *filename,void *buf,int offset,int len); -int fs_write_sandbox (const char *filename,void *buf,int offset,int len); +int sandbox_fs_size (const char *filename,loff_t *size); +int fs_read_sandbox (const char *filename,void *buf,loff_t offset,loff_t len, +loff_t *actread); +int fs_write_sandbox (const char *filename,void *buf,loff_t offset, +loff_t len,loff_t *actwrite);#endif --
Quoted 2 lines
1.9.1
Regards,
Simon
PATCH v7 5/6 fs: API changes to enable extra parameter to return size of type loff_t
Quoted 102 lines · Simon Glass
Quoted 8 lines · Suriyan Ramasami
The sandbox/ext4/fat/generic fs commands do not gracefully deal with file greater than 2GB. Negative values are returned in such cases.
To handle this, the fs functions have been modified to take an additional parameter of type "*
loff_t" which is then populated. The return value of the fs fucntions are used only for error conditions.Signed-off-by Suriyan Ramasami <[email protected]>A few nits below, but:
Acked-by Simon Glass <[email protected]>Quoted 88 lines
---
Changes in v7:
* Simon - API change in separate patchcommon/cmd_fs.c | 17 +++++++++++ fs/ext4/ext4fs.c | 22 ++++----------- fs/fat/fat.c | 20 ++++--------- fs/fs.c | 77 ++++++++++++++++++++++++++++++-------------------- fs/sandbox/sandboxfs.c | 29 +++++++------------ include/ext4fs.h | 5 ++-- include/fat.h | 5 ++-- include/fs.h | 41 ++++++++++++++++----------- include/sandboxfs.h | 8 ++++-- 9 files changed, 121 insertions(+), 103 deletions(-)common/cmd_fs.c +17
-0@@ -51,6 +51,23 @@ U_BOOT_CMD( " If 'pos' is 0 or omitted, the file is read from the start." ) +static int do_save_wrapper (cmd_tbl_t *cmdtp,int flag,int argc, +char *const argv[]) +{ +return do_save (cmdtp, flag, argc, argv,FS_TYPE_ANY ); +} + +U_BOOT_CMD ( + save,7 ,0 , do_save_wrapper, +"save file to a filesystem" , +"<interface> <dev[:part]> <addr> <filename> bytes [pos]\n" +" - Save binary file 'filename' to partition 'part' on device\n" +" type 'interface' instance 'dev' from addr 'addr' in memory.\n" +" 'bytes' gives the size to save in bytes and is mandatory.\n" +" 'pos' gives the file byte position to start writing to.\n" +" If 'pos' is 0 or omitted, the file is written from the start." +) +static int do_ls_wrapper (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) {fs/ext4/ext4fs.c +5
-12@@ -184,16 +184,9 @@ int ext4fs_exists(const char *filename)return ret ==0 ; } -int ext4fs_size (const char *filename) +int ext4fs_size (const char *filename,loff_t *size) { -loff_t size; -int ret; - - ret =ext4fs_open (filename, &size); -if (ret) -return ret; -else -return size; +return ext4fs_open (filename, size); }int ext4fs_read (char *buf,loff_t len,loff_t *actread)@@ -217,10 +210,10 @@ int ext4fs_probe(block_dev_desc_t *fs_dev_desc,return 0 ; } -int ext4_read_file (const char *filename,void *buf,int offset,int len) +int ext4_read_file (const char *filename,void *buf,loff_t offset,loff_t len, +loff_t *len_read) {loff_t file_len; -loff_t len_read;int ret;if (offset !=0 ) {@@ -237,10 +230,7 @@ int ext4_read_file(const char *filename, void *buf, int offset, int len)if (len ==0 ) len = file_len; - ret =ext4fs_read (buf, len, &len_read); + ret =ext4fs_read (buf, len, len_read);
Quoted 8 lines
fs/ext4/ext4fs.c int ext4_read_file(const char *filename, void *buf, int offset, int len) · line 235
Quoted 5 lines
fs/ext4/ext4fs.c +1
-4-if (ret) -return ret; -else -return len_read; +return ret;Probably don't need ret here
I shall change it to:
return ext4fs_read(buf, len, len_read);
and get rid of ret.
Quoted 35 lines
Quoted 35 lines
fs/ext4/ext4fs.c +0
-0}fs/fat/fat.c +4
-11@@ -1248,16 +1248,9 @@ int fat_exists(const char *filename)return ret ==0 ; } -int fat_size (const char *filename) +int fat_size (const char *filename,loff_t *size) { -loff_t size; -int ret; - - ret =do_fat_read_at (filename,0 ,NULL ,0 ,LS_NO ,1 , &size); -if (ret) -return ret; -else -return size; +return do_fat_read_at (filename,0 ,NULL ,0 ,LS_NO ,1 , size); } int file_fat_read_at(const char *filename, loff_t pos, void *buffer,@@ -1280,18 +1273,17 @@ int ret;return actread; } -int fat_read_file (const char *filename,void *buf,int offset,int len) +int fat_read_file (const char *filename,void *buf,loff_t offset,loff_t len, +loff_t *actread) {int ret; -loff_t actread;
Quoted 9 lines
fs/fat/fat.c int ret; · line 1284
Quoted 6 lines
fs/fat/fat.c +1
-2- ret =file_fat_read_at (filename, offset, buf, len, &actread); + ret =file_fat_read_at (filename, offset, buf, len, actread);if (ret) {printf ("** Unable to read file %s **\n" , filename); -return ret; }Remove {} around that
OK
Quoted 258 lines
Quoted 258 lines
fs/fat/fat.c +1
-1-return actread; +return ret; }void fat_close (void )fs/fs.c +46
-31@@ -46,19 +46,21 @@ static inline int fs_exists_unsupported(const char *filename)return 0 ; } -static inline int fs_size_unsupported (const char *filename) +static inline int fs_size_unsupported (const char *filename,loff_t *size) {return -1 ; }static inline int fs_read_unsupported (const char *filename,void *buf, -int offset,int len) +loff_t offset,loff_t len, +loff_t *actread) {return -1 ; }static inline int fs_write_unsupported (const char *filename,void *buf, -int offset,int len) +loff_t offset,loff_t len, +loff_t *actwrite) {return -1 ; }@@ -82,9 +84,11 @@ struct fstype_info { disk_partition_t *fs_partition);int (*ls)(const char *dirname);int (*exists)(const char *filename); -int (*size)(const char *filename); -int (*read)(const char *filename,void *buf,int offset,int len); -int (*write)(const char *filename,void *buf,int offset,int len); +int (*size)(const char *filename,loff_t *size); +int (*read)(const char *filename,void *buf,loff_t offset, +loff_t len,loff_t *actread); +int (*write)(const char *filename,void *buf,loff_t offset, +loff_t len,loff_t *actwrite);void (*close)(void ); };@@ -99,7 +103,11 @@ static struct fstype_info fstypes[] = { .exists = fat_exists, .size = fat_size, .read = fat_read_file, +#ifdef CONFIG_FAT_WRITE + .write = file_fat_write, +#else .write = fs_write_unsupported, +#endif }, #endif #ifdef CONFIG_FS_EXT4@@ -112,7 +120,11 @@ static struct fstype_info fstypes[] = { .exists = ext4fs_exists, .size = ext4fs_size, .read = ext4_read_file, +#ifdef CONFIG_CMD_EXT4_WRITE + .write = ext4_write_file, +#else .write = fs_write_unsupported, +#endif }, #endif #ifdef CONFIG_SANDBOX@@ -233,20 +245,21 @@ int fs_exists(const char *filename)return ret; } -int fs_size (const char *filename) +int fs_size (const char *filename,loff_t *size) {int ret;struct fstype_info *info =fs_get_info (fs_type); - ret = info->size (filename); + ret = info->size (filename, size);fs_close ();return ret; } -int fs_read (const char *filename,ulong addr,int offset,int len) +int fs_read (const char *filename,ulong addr,loff_t offset,loff_t len, +loff_t *actread) {struct fstype_info *info =fs_get_info (fs_type);void *buf;@@ -257,11 +270,11 @@ int fs_read(const char *filename, ulong addr, int offset, int len)* means read the whole file. */ buf =map_sysmem (addr, len); - ret = info->read (filename, buf, offset, len); + ret = info->read (filename, buf, offset, len, actread);unmap_sysmem (buf);/* If we requested a specific number of bytes, check we got it */ -if (ret >=0 && len && ret != len) { +if (ret ==0 && len && *actread != len) {printf ("** Unable to read file %s **\n" , filename); ret =-1 ; }@@ -270,17 +283,18 @@ int fs_read(const char *filename, ulong addr, int offset, int len)return ret; } -int fs_write (const char *filename,ulong addr,int offset,int len) +int fs_write (const char *filename,ulong addr,loff_t offset,loff_t len, +loff_t *actwrite) {struct fstype_info *info =fs_get_info (fs_type);void *buf;int ret; buf =map_sysmem (addr, len); - ret = info->write (filename, buf, offset, len); + ret = info->write (filename, buf, offset, len, actwrite);unmap_sysmem (buf); -if (ret >=0 && ret != len) { +if (ret <0 && len != *actwrite) {printf ("** Unable to write file %s **\n" , filename); ret =-1 ; }@@ -292,7 +306,7 @@ int fs_write(const char *filename, ulong addr, int offset, int len)int do_size (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[],int fstype) { -int size; +loff_t size;if (argc !=4 )return CMD_RET_USAGE ;@@ -300,8 +314,7 @@ int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],if (fs_set_blk_dev (argv[1 ], argv[2 ], fstype))return 1 ; - size =fs_size (argv[3 ]); -if (size <0 ) +if (fs_size (argv[3 ], &size) <0 )return CMD_RET_FAILURE ;setenv_hex ("filesize" , size);@@ -315,9 +328,10 @@ int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],unsigned long addr;const char *addr_str;const char *filename; -unsigned long bytes; -unsigned long pos; -int len_read; +loff_t bytes; +loff_t pos; +loff_t len_read; +int ret;unsigned long time;char *ep;@@ -359,12 +373,12 @@ int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], pos =0 ; time =get_timer (0 ); - len_read =fs_read (filename, addr, pos, bytes); + ret =fs_read (filename, addr, pos, bytes, &len_read); time =get_timer (time); -if (len_read <=0 ) +if (ret <0 )return 1 ; -printf ("%d bytes read in %lu ms" , len_read, time); +printf ("%llu bytes read in %lu ms" , len_read, time);if (time >0 ) {puts (" (" );print_size (len_read / time *1000 ,"/s" );@@ -408,9 +422,10 @@ int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], {unsigned long addr;const char *filename; -unsigned long bytes; -unsigned long pos; -int len; +loff_t bytes; +loff_t pos; +loff_t len; +int ret;unsigned long time;if (argc <6 || argc >7 )@@ -419,8 +434,8 @@ int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],if (fs_set_blk_dev (argv[1 ], argv[2 ], fstype))return 1 ; - filename = argv[3 ]; - addr =simple_strtoul (argv[4 ],NULL ,16 ); + addr =simple_strtoul (argv[3 ],NULL ,16 ); + filename = argv[4 ]; bytes =simple_strtoul (argv[5 ],NULL ,16 );if (argc >=7 ) pos =simple_strtoul (argv[6 ],NULL ,16 );@@ -428,12 +443,12 @@ int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[], pos =0 ; time =get_timer (0 ); - len =fs_write (filename, addr, pos, bytes); + ret =fs_write (filename, addr, pos, bytes, &len); time =get_timer (time); -if (len <=0 ) +if (ret <0 )return 1 ; -printf ("%d bytes written in %lu ms" , len, time); +printf ("%llu bytes written in %lu ms" , len, time);if (time >0 ) {puts (" (" );print_size (len / time *1000 ,"/s" );fs/sandbox/sandboxfs.c +4
-11@@ -103,46 +103,37 @@ int sandbox_fs_exists(const char *filename)return ret ==0 ; } -int sandbox_fs_size (const char *filename) +int sandbox_fs_size (const char *filename,loff_t *size) { -loff_t size; -int ret; - - ret =os_get_filesize (filename, &size); -if (ret) -return ret; -else -return size; +return os_get_filesize (filename, size); }void sandbox_fs_close (void ) { } -int fs_read_sandbox (const char *filename,void *buf,int offset,int len) +int fs_read_sandbox (const char *filename,void *buf,loff_t offset,loff_t len, +loff_t *actread) {int ret; -loff_t actread;
Quoted 9 lines
fs/sandbox/sandboxfs.c int sandbox_fs_exists(const char *filename) · line 123
Quoted 6 lines
fs/sandbox/sandboxfs.c +1
-2- ret =sandbox_fs_read_at (filename, offset, buf, len, &actread); + ret =sandbox_fs_read_at (filename, offset, buf, len, actread);if (ret) {printf ("** Unable to read file %s **\n" , filename); -return ret; }Remove {}
OK
Quoted 12 lines
Quoted 12 lines
fs/sandbox/sandboxfs.c +3
-3-return actread; +return ret; } -int fs_write_sandbox (const char *filename,void *buf,int offset,int len) +int fs_write_sandbox (const char *filename,void *buf,loff_t offset, +loff_t len,loff_t *actwrite) {int ret; -loff_t actwrite;
Quoted 9 lines
fs/sandbox/sandboxfs.c int sandbox_fs_exists(const char *filename) · line 136
Quoted 6 lines
fs/sandbox/sandboxfs.c +1
-2- ret =sandbox_fs_write_at (filename, offset, buf, len, &actwrite); + ret =sandbox_fs_write_at (filename, offset, buf, len, actwrite);if (ret) {printf ("** Unable to write file %s **\n" , filename); -return ret; }Remove {}
OK
Quoted 126 lines
Quoted 126 lines
fs/sandbox/sandboxfs.c +1
-1-return actwrite; +return ret; }include/ext4fs.h +3
-2@@ -138,13 +138,14 @@ void ext4fs_close(void);void ext4fs_reinit_global (void );int ext4fs_ls (const char *dirname);int ext4fs_exists (const char *filename); -int ext4fs_size (const char *filename); +int ext4fs_size (const char *filename,loff_t *size);void ext4fs_free_node (struct ext2fs_node *node,struct ext2fs_node *currroot);int ext4fs_devread (lbaint_t sector,int byte_offset,int byte_len,char *buf);void ext4fs_set_blk_dev (block_dev_desc_t *rbdd,disk_partition_t *info);long int read_allocated_block (struct ext2_inode *inode,int fileblock);int ext4fs_probe (block_dev_desc_t *fs_dev_desc,disk_partition_t *fs_partition); -int ext4_read_file (const char *filename,void *buf,int offset,int len); +int ext4_read_file (const char *filename,void *buf,loff_t offset,loff_t len, +loff_t *actread);int ext4_read_superblock (char *buffer);#endif include/fat.h +3
-2@@ -198,7 +198,7 @@ int file_cd(const char *path);int file_fat_detectfs (void );int file_fat_ls (const char *dir);int fat_exists (const char *filename); -int fat_size (const char *filename); +int fat_size (const char *filename,loff_t *size);int file_fat_read_at (const char *filename,loff_t pos,void *buffer,loff_t maxsize,loff_t *actread);int file_fat_read (const char *filename,void *buffer,int maxsize);@@ -208,6 +208,7 @@ int fat_register_device(block_dev_desc_t *dev_desc, int part_no);int file_fat_write (const char *filename,void *buf,loff_t offset,loff_t len,loff_t *actwrite); -int fat_read_file (const char *filename,void *buf,int offset,int len); +int fat_read_file (const char *filename,void *buf,loff_t offset,loff_t len, +loff_t *actread);void fat_close (void );#endif /* _FAT_H_ */ include/fs.h +25
-16@@ -51,32 +51,41 @@ int fs_ls(const char *dirname);int fs_exists (const char *filename);/* -* Determine a file's size +* fs_size - Determine a file's size * -* Returns the file's size in bytes, or a negative value if it doesn't exist. +* @filename: Name of the file +* @size: Size of file +* @return 0 if ok with valid *size, negative on error */ -int fs_size (const char *filename); +int fs_size (const char *filename,loff_t *size);/* -* Read file "filename" from the partition previously set by fs_set_blk_dev(), -* to address "addr", starting at byte offset "offset", and reading "len" -* bytes. "offset" may be 0 to read from the start of the file. "len" may be -* 0 to read the entire file. Note that not all filesystem types support -* either/both offset!=0 or len!=0. +* fs_read - Read file from the partition previously set by fs_set_blk_dev() +* Note that not all filesystem types support either/both offset!=0 or len!=0. * -* Returns number of bytes read on success. Returns <= 0 on error. +* @filename: Name of file to read from +* @addr: The address to read into +* @offset: The offset in file to read from +* @len: The number of bytes to read. Maybe 0 to read entire file +* @actread: Returns the actual number of bytes read +* @return 0 if ok with valid *actread, -1 on error conditions */ -int fs_read (const char *filename,ulong addr,int offset,int len); +int fs_read (const char *filename,ulong addr,loff_t offset,loff_t len, +loff_t *actread);/* -* Write file "filename" to the partition previously set by fs_set_blk_dev(), -* from address "addr", starting at byte offset "offset", and writing "len" -* bytes. "offset" may be 0 to write to the start of the file. Note that not -* all filesystem types support offset!=0. +* fs_write - Write file to the partition previously set by fs_set_blk_dev() +* Note that not all filesystem types support offset!=0. * -* Returns number of bytes read on success. Returns <= 0 on error. +* @filename: Name of file to read from +* @addr: The address to read into +* @offset: The offset in file to read from. Maybe 0 to write to start of file +* @len: The number of bytes to write +* @actwrite: Returns the actual number of bytes written +* @return 0 if ok with valid *actwrite, -1 on error conditions */ -int fs_write (const char *filename,ulong addr,int offset,int len); +int fs_write (const char *filename,ulong addr,loff_t offset,loff_t len, +loff_t *actwrite);/* * Common implementation for various filesystem commands, optionally limited include/sandboxfs.h +5
-3@@ -28,8 +28,10 @@ int sandbox_fs_write_at(const char *filename, loff_t pos, void *buffer,void sandbox_fs_close (void );int sandbox_fs_ls (const char *dirname);int sandbox_fs_exists (const char *filename); -int sandbox_fs_size (const char *filename); -int fs_read_sandbox (const char *filename,void *buf,int offset,int len); -int fs_write_sandbox (const char *filename,void *buf,int offset,int len); +int sandbox_fs_size (const char *filename,loff_t *size); +int fs_read_sandbox (const char *filename,void *buf,loff_t offset,loff_t len, +loff_t *actread); +int fs_write_sandbox (const char *filename,void *buf,loff_t offset, +loff_t len,loff_t *actwrite);
Quoted 7 lines
Quoted 4 lines
include/sandboxfs.h +0
-1#endif --1.9.1
Regards,
Simon
Thanks for the review!
- Suriyan
PATCH v7 6/6 sandbox: script for testing sandbox/ext4/fat/fs commands
In reply to Suriyan RamasamiTest size/read/write commands in a sandbox environment.
---
Changes in v7:
* Simon
- take care of fat/vfat in mkfs
- fs/nonfs test code repeats, put it in function
test/fs/fs-test.sh | 561 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 561 insertions(+) create mode 100755 test/fs/fs-test.sh
test/fs/fs-test.sh new file +561 -0
@@ -0,0 +1,561 @@ +#!/bin/bash +# +# (C) Copyright 2014 Suriyan Ramasami +# +# SPDX-License-Identifier: GPL-2.0+ +# + +# Invoke this test script from U-Boot base directory as ./test/fs/fs-test.sh +# It currently tests the fs/sb and native commands for ext4 and fat partitions +# Expected results are as follows: +# EXT4 tests: +# fs-test.sb.ext4.out: Summary: PASS: 17 FAIL: 2 +# fs-test.ext4.out: Summary: PASS: 11 FAIL: 8 +# fs-test.fs.ext4.out: Summary: PASS: 11 FAIL: 8 +# FAT tests: +# fs-test.sb.fat.out: Summary: PASS: 17 FAIL: 2 +# fs-test.fat.out: Summary: PASS: 19 FAIL: 0 +# fs-test.fs.fat.out: Summary: PASS: 19 FAIL: 0 +# Total Summary: TOTAL PASS: 94 TOTAL FAIL: 20 + +# pre-requisite binaries list. +PREREQ_BINS="md5sum mkfs mount umount dd fallocate mkdir" + +# All generated output files from this test will be in $OUT_DIR +# Hence everything is sandboxed. +OUT_DIR="sandbox/test/fs" + +# Location of generated sandbox u-boot +UBOOT="./sandbox/u-boot" + +# Our mount directory will be in the sandbox +MOUNT_DIR="${OUT_DIR}/mnt" + +# The file system image we create will have the $IMG prefix. +IMG="${OUT_DIR}/3GB" + +# $SMALL_FILE is the name of the 1MB file in the file system image +SMALL_FILE="1MB.file" + +# $BIG_FILE is the name of the 2.5GB file in the file system image +BIG_FILE="2.5GB.file" + +# $MD5_FILE will have the expected md5s when we do the test +# They shall have a suffix which represents their file system (ext4/fat) +MD5_FILE="${OUT_DIR}/md5s.list" + +# $OUT shall be the prefix of the test output. Their suffix will be .out +OUT="${OUT_DIR}/fs-test" + +# Full Path of the 1 MB file that shall be created in the fs image. +MB1="${MOUNT_DIR}/${SMALL_FILE}" +GB2p5="${MOUNT_DIR}/${BIG_FILE}" + +# ************************ +# * Functions start here * +# ************************ + +# Check if the prereq binaries exist, or exit +function check_prereq() { + for prereq in $PREREQ_BINS; do + if [ ! -x `which $prereq` ]; then + echo "Missing $prereq binary. Exiting!" + exit + fi + done + + # We use /dev/urandom to create files. Check if it exists. + if [ ! -c /dev/urandom ]; then + echo "Missing character special /dev/urandom. Exiting!" + exit + fi +} + +# If 1st param is "clean", then clean out the generated files and exit +function check_clean() { + if [ "$1" = "clean" ]; then + rm -rf "$OUT_DIR" + echo "Cleaned up generated files. Exiting" + exit + fi +} + +# Generate sandbox U-Boot - gleaned from /test/dm/test-dm.sh +function compile_sandbox() { + unset CROSS_COMPILE + NUM_CPUS=$(cat /proc/cpuinfo |grep -c processor) + make O=sandbox sandbox_config + make O=sandbox -s -j${NUM_CPUS} + + # Check if U-Boot exists + if [ ! -x "$UBOOT" ]; then + echo "$UBOOT does not exist or is not executable" + echo "Build error?" + echo "Please run this script as ./test/fs/`basename $0`" + exit + fi +} + +# Clean out all generated files other than the file system images +# We save time by not deleting and recreating the file system images +function prepare_env() { + rm -f ${MD5_FILE}.* ${OUT}.* + mkdir ${OUT_DIR} +} + +# 1st parameter is the name of the image file to be created +# 2nd parameter is the filesystem - fat ext4 etc +# -F cant be used with fat as it means something else. +function create_image() { + # Create image if not already present - saves time, while debugging + if [ "$2" = "ext4" ]; then + MKFS_OPTION="-F" + else + MKFS_OPTION="" + fi + if [ ! -f "$1" ]; then + fallocate -l 3G "$1" &> /dev/null + mkfs -t "$2" $MKFS_OPTION "$1" &> /dev/null + if [ $? -ne 0 -a "$2" = "fat" ]; then + # If we fail and we did fat, try vfat. + mkfs -t vfat $MKFS_OPTION "$1" &> /dev/null + fi + fi +} + +# 1st parameter is the FS type: fat/ext4 +# 2nd parameter is the name of small file +# Returns filename which can be used for fat or ext4 for writing +function fname_for_write() { + case $1 in + ext4) + # ext4 needs absolute path name of file + echo /${2}.w + ;; + + *) + echo ${2}.w + ;; + esac +} + +# 1st parameter is image file +# 2nd parameter is file system type - fat/ext4 +# 3rd parameter is name of small file +# 4th parameter is name of big file +# 5th parameter is fs/nonfs/sb - to dictate generic fs commands or +# otherwise or sb hostfs +# 6th parameter is the directory path for the files. Its "" for generic +# fs and ext4/fat and full patch for sb hostfs +# UBOOT is set in env +function test_image() { + addr="0x01000008" + length="0x00100000" + + case "$2" in + fat) + PREFIX="fat" + WRITE="write" + ;; + + ext4) + PREFIX="ext4" + WRITE="write" + ;; + + *) + echo "Unhandled filesystem $2. Exiting!" + exit + ;; + esac + + case "$5" in + fs) + PREFIX="" + WRITE="save" + SUFFIX=" 0:0" + ;; + + nonfs) + SUFFIX=" 0:0" + ;; + + sb) + PREFIX="sb " + WRITE="save" + SUFFIX="fs -" + ;; + + *) + echo "Unhandled mode $5. Exiting!" + exit + ;; + + esac + + if [ -z "$6" ]; then + FILE_WRITE=`fname_for_write $2 $3` + FILE_SMALL=$3 + FILE_BIG=$4 + else + FILE_WRITE=$6/`fname_for_write $2 $3` + FILE_SMALL=$6/$3 + FILE_BIG=$6/$4 + fi + + # In u-boot commands, <interface> stands for host or hostfs + # hostfs maps to the host fs. + # host maps to the "sb bind" that we do + + $UBOOT << EOF +sb=$5 +setenv bind 'if test "\$sb" != sb; then sb bind 0 "$1"; fi' +run bind +# Test Case 1 - ls +${PREFIX}ls host${SUFFIX} $6 +# +# We want ${PREFIX}size host 0:0 $3 for host commands and +# sb size hostfs - $3 for hostfs commands. +# 1MB is 0x0010 0000 +# Test Case 2 - size of small file +${PREFIX}size host${SUFFIX} $FILE_SMALL +printenv filesize +setenv filesize + +# 2.5GB (1024*1024*2500) is 0x9C40 0000 +# Test Case 3 - size of big file +${PREFIX}size host${SUFFIX} $FILE_BIG +printenv filesize +setenv filesize + +# Notes about load operation +# If I use 0x01000000 I get DMA misaligned error message +# Last two parameters are size and offset. + +# Test Case 4a - Read full 1MB of small file +${PREFIX}load host${SUFFIX} $addr $FILE_SMALL +printenv filesize +# Test Case 4b - Read full 1MB of small file +md5sum $addr \$filesize +setenv filesize + +# Test Case 5a - First 1MB of big file +${PREFIX}load host${SUFFIX} $addr $FILE_BIG $length 0x0 +printenv filesize +# Test Case 5b - First 1MB of big file +md5sum $addr \$filesize +setenv filesize + +# fails for ext as no offset support +# Test Case 6a - Last 1MB of big file +${PREFIX}load host${SUFFIX} $addr $FILE_BIG $length 0x9C300000 +printenv filesize +# Test Case 6b - Last 1MB of big file +md5sum $addr \$filesize +setenv filesize + +# fails for ext as no offset support +# Test Case 7a - One from the last 1MB chunk of 2GB +${PREFIX}load host${SUFFIX} $addr $FILE_BIG $length 0x7FF00000 +printenv filesize +# Test Case 7b - One from the last 1MB chunk of 2GB +md5sum $addr \$filesize +setenv filesize + +# fails for ext as no offset support +# Test Case 8a - One from the start 1MB chunk from 2GB +${PREFIX}load host${SUFFIX} $addr $FILE_BIG $length 0x80000000 +printenv filesize +# Test Case 8b - One from the start 1MB chunk from 2GB +md5sum $addr \$filesize +setenv filesize + +# fails for ext as no offset support +# Test Case 9a - One 1MB chunk crossing the 2GB boundary +${PREFIX}load host${SUFFIX} $addr $FILE_BIG $length 0x7FF80000 +printenv filesize +# Test Case 9b - One 1MB chunk crossing the 2GB boundary +md5sum $addr \$filesize +setenv filesize + +# Generic failure case +# Test Case 10 - 2MB chunk from the last 1MB of big file +${PREFIX}load host${SUFFIX} $addr $FILE_BIG 0x00200000 0x9C300000 +printenv filesize +# + +# Read 1MB from small file +${PREFIX}load host${SUFFIX} $addr $FILE_SMALL +# Write it back to test the writes +# Test Case 11a - Check that the write succeeded +${PREFIX}${WRITE} host${SUFFIX} $addr $FILE_WRITE \$filesize +mw.b $addr 00 100 +${PREFIX}load host${SUFFIX} $addr $FILE_WRITE +# Test Case 11b - Check md5 of written to is same as the one read from +md5sum $addr \$filesize +setenv filesize +# +reset + +EOF +} + +# 1st argument is the name of the image file. +# 2nd argument is the file where we generate the md5s of the files +# generated with the appropriate start and length that we use to test. +# It creates the necessary files in the image to test. +# $GB2p5 is the path of the big file (2.5 GB) +# $MB1 is the path of the small file (1 MB) +# $MOUNT_DIR is the path we can use to mount the image file. +function create_files() { + # Mount the image so we can populate it. + mkdir -p "$MOUNT_DIR" + sudo mount -o loop,rw "$1" "$MOUNT_DIR" + + # Create big file in this image. + # Note that we work only on the start 1MB, couple MBs in the 2GB range + # and the last 1 MB of the huge 2.5GB file. + # So, just put random values only in those areas. + if [ ! -f "${GB2p5}" ]; then + sudo dd if=/dev/urandom of="${GB2p5}" bs=1M count=1 \ + &> /dev/null + sudo dd if=/dev/urandom of="${GB2p5}" bs=1M count=2 seek=2047 \ + &> /dev/null + sudo dd if=/dev/urandom of="${GB2p5}" bs=1M count=1 seek=2499 \ + &> /dev/null + fi + + # Create a small file in this image. + if [ ! -f "${MB1}" ]; then + sudo dd if=/dev/urandom of="${MB1}" bs=1M count=1 \ + &> /dev/null + fi + + # Delete the small file which possibly is written as part of a + # previous test. + sudo rm -f "${MB1}.w" + + # Generate the md5sums of reads that we will test against small file + dd if="${MB1}" bs=1M skip=0 count=1 2> /dev/null | md5sum > "$2" + + # Generate the md5sums of reads that we will test against big file + # One from beginning of file. + dd if="${GB2p5}" bs=1M skip=0 count=1 \ + 2> /dev/null | md5sum >> "$2" + + # One from end of file. + dd if="${GB2p5}" bs=1M skip=2499 count=1 \ + 2> /dev/null | md5sum >> "$2" + + # One from the last 1MB chunk of 2GB + dd if="${GB2p5}" bs=1M skip=2047 count=1 \ + 2> /dev/null | md5sum >> "$2" + + # One from the start 1MB chunk from 2GB + dd if="${GB2p5}" bs=1M skip=2048 count=1 \ + 2> /dev/null | md5sum >> "$2" + + # One 1MB chunk crossing the 2GB boundary + dd if="${GB2p5}" bs=512K skip=4095 count=2 \ + 2> /dev/null | md5sum >> "$2" + + sync + sudo umount "$MOUNT_DIR" + rmdir "$MOUNT_DIR" +} + +# 1st parameter is the text to print +# if $? is 0 its a pass, else a fail +# As a side effect it shall update env variable PASS and FAIL +function pass_fail() { + if [ $? -eq 0 ]; then + echo pass - "$1" + PASS=$((PASS + 1)) + else + echo FAIL - "$1" + FAIL=$((FAIL + 1)) + fi +} + +# 1st parameter is the string which leads to an md5 generation +# 2nd parameter is the file we grep, for that string +# 3rd parameter is the name of the file which has md5s in it +# 4th parameter is the line # in the md5 file that we match it against +# This function checks if the md5 of the file in the sandbox matches +# that calculated while generating the file +# 5th parameter is the string to print with the result +check_md5() { + # md5sum in u-boot has output of form: + # md5 for 01000008 ... 01100007 ==> <md5> + # the 7th field is the actual md5 + md5_src=`grep -A3 "$1" "$2" | grep "md5 for"` + md5_src=($md5_src) + md5_src=${md5_src[6]} + + # The md5 list, each line is of the form: + # - <md5> + # the 2nd field is the actual md5 + md5_dst=`sed -n $4p $3` + md5_dst=($md5_dst) + md5_dst=${md5_dst[0]} + + # For a pass they should match. + [ "$md5_src" = "$md5_dst" ] + pass_fail "$5" +} + +# 1st parameter is the name of the output file to check +# 2nd parameter is the name of the file containing the md5 expected +# 3rd parameter is the name of the small file +# 4th parameter is the name of the big file +# 5th paramter is the name of the written file +# This function checks the output file for correct results. +function check_results() { + echo "** Start $1" + + PASS=0 + FAIL=0 + + # Check if the ls is showing correct results for 2.5 gb file + grep -A6 "Test Case 1 " "$1" | egrep -iq "2621440000 *$4" + pass_fail "TC1: ls of $4" + + # Check if the ls is showing correct results for 1 mb file + grep -A6 "Test Case 1 " "$1" | egrep -iq "1048576 *$3" + pass_fail "TC1: ls of $3" + + # Check size command on 1MB.file + egrep -A3 "Test Case 2 " "$1" | grep -q "filesize=100000" + pass_fail "TC2: size of $3" + + # Check size command on 2.5GB.file + egrep -A3 "Test Case 3 " "$1" | grep -q "filesize=9c400000" + pass_fail "TC3: size of $4" + + # Check read full mb of 1MB.file + grep -A6 "Test Case 4a " "$1" | grep -q "filesize=100000" + pass_fail "TC4: load of $3 size" + check_md5 "Test Case 4b " "$1" "$2" 1 "TC4: load from $3" + + # Check first mb of 2.5GB.file + grep -A6 "Test Case 5a " "$1" | grep -q "filesize=100000" + pass_fail "TC5: load of 1st MB from $4 size" + check_md5 "Test Case 5b " "$1" "$2" 2 "TC5: load of 1st MB from $4" + + # Check last mb of 2.5GB.file + grep -A6 "Test Case 6a " "$1" | grep -q "filesize=100000" + pass_fail "TC6: load of last MB from $4 size" + check_md5 "Test Case 6b " "$1" "$2" 3 "TC6: load of last MB from $4" + + # Check last 1mb chunk of 2gb from 2.5GB file + grep -A6 "Test Case 7a " "$1" | grep -q "filesize=100000" + pass_fail "TC7: load of last 1mb chunk of 2GB from $4 size" + check_md5 "Test Case 7b " "$1" "$2" 4 \ + "TC7: load of last 1mb chunk of 2GB from $4" + + # Check first 1mb chunk after 2gb from 2.5GB file + grep -A6 "Test Case 8a " "$1" | grep -q "filesize=100000" + pass_fail "TC8: load 1st MB chunk after 2GB from $4 size" + check_md5 "Test Case 8b " "$1" "$2" 5 \ + "TC8: load 1st MB chunk after 2GB from $4" + + # Check 1mb chunk crossing the 2gb boundary from 2.5GB file + grep -A6 "Test Case 9a " "$1" | grep -q "filesize=100000" + pass_fail "TC9: load 1MB chunk crossing 2GB boundary from $4 size" + check_md5 "Test Case 9b " "$1" "$2" 6 \ + "TC9: load 1MB chunk crossing 2GB boundary from $4" + + # Check 2mb chunk from the last 1MB of 2.5GB file - generic failure case + grep -A6 "Test Case 10 " "$1" | grep -q 'Error: "filesize" not defined' + pass_fail "TC10: load 2MB from the last 1MB of $4 - generic fail case" + + # Check 1mb chunk write + grep -A3 "Test Case 11a " "$1" | \ + egrep -q '1048576 bytes written|update journal' + pass_fail "TC11: 1MB write to $5 - write succeeded" + check_md5 "Test Case 11b " "$1" "$2" 1 \ + "TC11: 1MB write to $5 - content verified" + echo "** End $1" +} + +# Takes in one parameter which is "fs" or "nonfs", which then dictates +# if a fs test (size/load/save) or a nonfs test (fatread/extread) needs to +# be performed. +function test_fs_nonfs() { + echo "Creating files in $fs image if not already present." + create_files $IMAGE $MD5_FILE_FS + + OUT_FILE="${OUT}.fs.${fs}.out" + test_image $IMAGE $fs $SMALL_FILE $BIG_FILE $1 "" \ + > ${OUT_FILE} + check_results $OUT_FILE $MD5_FILE_FS $SMALL_FILE $BIG_FILE \ + $WRITE_FILE + TOTAL_FAIL=$((TOTAL_FAIL + FAIL)) + TOTAL_PASS=$((TOTAL_PASS + PASS)) + echo "Summary: PASS: $PASS FAIL: $FAIL" + echo "--------------------------------------------" +} + +# ******************** +# * End of functions * +# ******************** + +check_clean "$1" +check_prereq +compile_sandbox +prepare_env + +# Track TOTAL_FAIL and TOTAL_PASS +TOTAL_FAIL=0 +TOTAL_PASS=0 + +# In each loop, for a given file system image, we test both the +# fs command, like load/size/write, the file system specific command +# like: ext4load/ext4size/ext4write and the sb load/ls/save commands. +for fs in ext4 fat; do + + echo "Creating $fs image if not already present." + IMAGE=${IMG}.${fs}.img + MD5_FILE_FS="${MD5_FILE}.${fs}" + create_image $IMAGE $fs + + # sb commands test + echo "Creating files in $fs image if not already present." + create_files $IMAGE $MD5_FILE_FS + + # Lets mount the image and test sb hostfs commands + mkdir -p "$MOUNT_DIR" + if [ "$fs" = "fat" ]; then + uid="uid=`id -u`" + else + uid="" + fi + sudo mount -o loop,rw,$uid "$IMAGE" "$MOUNT_DIR" + sudo chmod 777 "$MOUNT_DIR" + + OUT_FILE="${OUT}.sb.${fs}.out" + test_image $IMAGE $fs $SMALL_FILE $BIG_FILE sb `pwd`/$MOUNT_DIR \ + > ${OUT_FILE} + sudo umount "$MOUNT_DIR" + rmdir "$MOUNT_DIR" + + check_results $OUT_FILE $MD5_FILE_FS $SMALL_FILE $BIG_FILE \ + $WRITE_FILE + TOTAL_FAIL=$((TOTAL_FAIL + FAIL)) + TOTAL_PASS=$((TOTAL_PASS + PASS)) + echo "Summary: PASS: $PASS FAIL: $FAIL" + echo "--------------------------------------------" + + test_fs_nonfs nonfs + test_fs_nonfs fs +done + +echo "Total Summary: TOTAL PASS: $TOTAL_PASS TOTAL FAIL: $TOTAL_FAIL" +echo "--------------------------------------------" +if [ $TOTAL_FAIL -eq 0 ]; then + echo "PASSED" + exit 0 +else + echo "FAILED" + exit 1 +fi
Signature · 1 line
1.9.1
PATCH v7 6/6 sandbox: script for testing sandbox/ext4/fat/fs commands
Quoted 11 lines · Suriyan Ramasami
Test size/read/write commands in a sandbox environment.
Signed-off-by Suriyan Ramasami <[email protected]>---
Changes in v7:
* Simon
- take care of fat/vfat in mkfs
- fs/nonfs test code repeats, put it in function
Looks good.
You should keep the complete change history with each patch. 'patman' will do this for you.
Regards,
Simon
PATCH v7 6/6 sandbox: script for testing sandbox/ext4/fat/fs commands
Quoted 13 lines · Simon Glass
Quoted 11 lines · Suriyan Ramasami
Test size/read/write commands in a sandbox environment.
Signed-off-by Suriyan Ramasami <[email protected]>---
Changes in v7:
* Simon
- take care of fat/vfat in mkfs
- fs/nonfs test code repeats, put it in function
Quoted 7 lines
Looks good.
Acked-by Simon Glass <[email protected]>You should keep the complete change history with each patch. 'patman' will do this for you.
In my next patch, with the changes that you have mentioned, I shall try to grab all the change history which got lost between versions.
Quoted 2 lines
Regards,
Simon
Thanks!
- Suriyan