fs: fix generic save command implementation

Fix a few issues with the generic "save" shell command, and fs_write()
function.

1) fstypes[].write wasn't filled in for some file-systems, and isn't
   checked when used, which could cause crashes/... if executing save
   on e.g. fat/ext filesystems.

2) fs_write() requires the length argument to be non-zero, since it needs
   to know exactly how many bytes to write. Adjust the comments and code
   according to this.

3) fs_write() wasn't prototyped in <fs.h> like other generic functions;
   other code should be able to call this directly rather than invoking
   the "save" shell command.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Stephen Warren 2014-02-03 13:20:59 -07:00 committed by Tom Rini
parent 16f4d9335f
commit bd6fb31fab
2 changed files with 13 additions and 6 deletions

View file

@ -54,6 +54,16 @@ int fs_ls(const char *dirname);
*/
int fs_read(const char *filename, ulong addr, int offset, int len);
/*
* 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.
*
* Returns number of bytes read on success. Returns <= 0 on error.
*/
int fs_write(const char *filename, ulong addr, int offset, int len);
/*
* Common implementation for various filesystem commands, optionally limited
* to a specific filesystem type via the fstype parameter.