fs: fat/ext4/sandbox: Deal with files > 2GB
Subsystems (3)
PATCH v3 1/1 fs: fat/ext4/sandbox: Deal with files > 2GB
The commands fatls/ext4ls give -ve values when dealing with files > 2GB. The commands fatsize/ext4size do not update the variable filesize for these files.
To deal with this, the functions have been modified to take an additional parameter of type "* loff_t" which is then populated. The return value of the functions are solely used for error contitions.
---
v3:
* Added testcase to test writes
* Correct function set_contents() in fs/fat/fat_write.c
v2:
* Added test case for fat/ext4 in test/fs/testfs.sh
* md5sum: call map_sysmem() for buffer that md5_wd will work on
v1:
* First try.
--- arch/sandbox/cpu/os.c | 11 +- arch/sandbox/cpu/state.c | 6 +- common/board_f.c | 6 +- common/cmd_fat.c | 9 +- common/cmd_md5sum.c | 7 +- common/env_fat.c | 4 +- fs/ext4/ext4_common.c | 24 ++-- fs/ext4/ext4_common.h | 4 +- fs/ext4/ext4fs.c | 37 ++--- fs/fat/fat.c | 124 +++++++++-------- fs/fat/fat_write.c | 54 ++++---- fs/fat/file.c | 7 +- fs/fs.c | 63 +++++---- fs/sandbox/sandboxfs.c | 25 ++-- include/configs/sandbox.h | 2 + include/ext4fs.h | 11 +- include/fat.h | 19 +-- include/fs.h | 8 +- include/os.h | 2 +- include/sandboxfs.h | 8 +- test/fs/testfs.sh | 339 ++++++++++++++++++++++++++++++++++++++++++++++ 21 files changed, 581 insertions(+), 189 deletions(-) create mode 100644 test/fs/testfs.sh
arch/sandbox/cpu/os.c +6 -5
@@ -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,10 +428,10 @@ 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 ) + ret =os_get_filesize (fname, &size); +if (ret <0 )return -ENOENT ;if (size != state->ram_size)return -ENOSPC ;
arch/sandbox/cpu/state.c +3 -3
@@ -49,12 +49,12 @@ 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 ; }
common/board_f.c +3 -3
@@ -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,8 +304,8 @@ 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 ; }
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, count, &size);unmap_sysmem (buf); -if (size ==-1 ) { +if (ret ==-1 ) {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/cmd_md5sum.c +6 -1
@@ -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
@@ -135,6 +136,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 +144,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]);
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/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/ext4fs.c +20 -17
@@ -45,8 +45,8 @@ void ext4fs_free_node(struct ext2fs_node *node, struct ext2fs_node *currroot)* Optimized read file API : collects and defers contiguous sector * reads into one potentially more efficient larger sequential read action */ -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) {struct ext_filesystem *fs =get_fs ();int i;
@@ -150,7 +150,8 @@ int ext4fs_read_file(struct ext2fs_node *node, int pos, previous_block_number =-1 ; } -return len; + *actread = len; +return 0 ; }int ext4fs_ls (const char *dirname)
@@ -176,23 +177,24 @@ int ext4fs_ls(const char *dirname)int ext4fs_exists (const char *filename) { -int file_len; +loff_t file_len; +int ret; - file_len =ext4fs_open (filename); -return file_len >=0 ; + ret =ext4fs_open (filename, &file_len); +return ret ==0 ; } -int ext4fs_size (const char *filename) +int ext4fs_size (const char *filename,loff_t *size) { -return ext4fs_open (filename); +return ext4fs_open (filename, size); } -int ext4fs_read (char *buf,unsigned len) +int ext4fs_read (char *buf,loff_t len,loff_t *actread) {if (ext4fs_root ==NULL || ext4fs_file ==NULL )return 0 ; -return ext4fs_read_file (ext4fs_file,0 , len, buf); +return ext4fs_read_file (ext4fs_file,0 , len, buf, actread); } int ext4fs_probe(block_dev_desc_t *fs_dev_desc,
@@ -208,18 +210,19 @@ 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) { -int file_len; -int len_read; +loff_t file_len; +int ret;if (offset !=0 ) {printf ("** Cannot support non-zero offset **\n" );return -1 ; } - file_len =ext4fs_open (filename); -if (file_len <0 ) { + ret =ext4fs_open (filename, &file_len); +if (ret <0 ) {printf ("** File not found %s **\n" , filename);return -1 ; }
@@ -227,7 +230,7 @@ int ext4_read_file(const char *filename, void *buf, int offset, int len)if (len ==0 ) len = file_len; - len_read =ext4fs_read (buf, len); + ret =ext4fs_read (buf, len, len_read); -return len_read; +return ret; }
fs/fat/fat.c +67 -57
277 lines not on this page · raw message
fs/fat/fat_write.c +28 -26
166 lines not on this page · raw message
fs/fat/file.c +4 -3
@@ -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,loff_t maxsize,loff_t *actread) {char fullpath[1024 ];const char *arg;
@@ -180,5 +180,6 @@ file_read(const char *filename, void *buffer, unsigned long maxsize) arg = fullpath; } -return filesystems[current_filesystem].read (arg, buffer, maxsize); +return filesystems[current_filesystem].read (arg, buffer, maxsize, + actread); }
fs/fs.c +35 -28
165 lines not on this page · raw message
fs/sandbox/sandboxfs.c +17 -8
@@ -16,7 +16,7 @@ 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) { -ssize_t size; +loff_t size;int fd, ret; fd =os_open (filename,OS_O_RDONLY );
@@ -27,8 +27,16 @@ long sandbox_fs_read_at(const char *filename, unsigned long pos,os_close (fd);return ret; } -if (!maxsize) - maxsize =os_get_filesize (filename); +if (!maxsize) { + ret =os_get_filesize (filename, &size); +if (ret) { +os_close (fd); +return ret; + } + + maxsize = size; + } + size =os_read (fd, buffer, maxsize);os_close (fd);
@@ -74,15 +82,16 @@ int sandbox_fs_ls(const char *dirname)int sandbox_fs_exists (const char *filename) { -ssize_t sz; +loff_t sz; +int ret; - sz =os_get_filesize (filename); -return sz >=0 ; + ret =os_get_filesize (filename, &sz); +return ret ==0 ; } -int sandbox_fs_size (const char *filename) +int sandbox_fs_size (const char *filename,loff_t *size) { -return os_get_filesize (filename); +return os_get_filesize (filename, size); }void sandbox_fs_close (void )
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
include/ext4fs.h +6 -5
@@ -125,24 +125,25 @@ 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);#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 );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 +11 -8
@@ -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, +loff_t maxsize,loff_t *actread);struct filesystem {file_detectfs_func *detect;
@@ -198,15 +198,18 @@ 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); -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 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,loff_t maxsize, +loff_t *actread);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 fat_read_file (const char *filename,void *buf,int offset,int len); +int file_fat_write (const char *filename,void *buffer,loff_t maxsize, +loff_t *actwrite); +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 +5 -3
@@ -55,7 +55,7 @@ int fs_exists(const char *filename);* * Returns the file's size in bytes, or a negative value if it doesn't exist. */ -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(),
@@ -66,7 +66,8 @@ int fs_size(const char *filename);* * Returns number of bytes read on success. Returns <= 0 on error. */ -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(),
@@ -76,7 +77,8 @@ int fs_read(const char *filename, ulong addr, int offset, int len);* * Returns number of bytes read on success. Returns <= 0 on error. */ -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/os.h +1 -1
@@ -219,7 +219,7 @@ const char *os_dirent_get_typename(enum os_dirent_t type);* @param fname Filename to check * @return size of file, 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 +5 -3
@@ -26,8 +26,10 @@ long sandbox_fs_read_at(const char *filename, unsigned long pos,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 *size); +int fs_write_sandbox (const char *filename,void *buf,loff_t offset, +loff_t len,loff_t *actwrite);#endif
test/fs/testfs.sh new file +339 -0
339 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v3 1/1 fs: fat/ext4/sandbox: Deal with files > 2GB
Hello Suriyan,
Quoted 1 line · Suriyan Ramasami
Subject: [PATCH v3 1/1] fs: fat/ext4/sandbox: Deal with files > 2GB
Could you repost using the full 'negative' word instead of an abbreviation? Otherwise people looking for issues by keywords might miss this one.
Amicalement,
Signature · 1 line
Albert.
PATCH v3 1/1 fs: fat/ext4/sandbox: Deal with files > 2GB
Hello Albert,
Quoted 11 lines · Albert ARIBAUD
Hello Suriyan,
Quoted 1 line · Suriyan Ramasami
Subject: [PATCH v3 1/1] fs: fat/ext4/sandbox: Deal with files > 2GB
Could you repost using the full 'negative' word instead of an abbreviation? Otherwise people looking for issues by keywords might miss this one.
I shall do so in version 4.
Thanks!
- Suriyan
Quoted 3 lines
Amicalement,
--
Albert.