diff options
author | Stephen Warren <swarren@nvidia.com> | 2014-02-03 13:20:59 -0700 |
---|---|---|
committer | Tom Rini <trini@ti.com> | 2014-02-19 09:47:33 -0500 |
commit | bd6fb31fab1523ecac1aaf7af574868a26169dc6 (patch) | |
tree | 00a06ba1a3cc5409caf3e45f188528809fe86337 | |
parent | 16f4d9335fe18cf3b57e400baf7687f1c390fd8c (diff) | |
download | u-boot-imx-bd6fb31fab1523ecac1aaf7af574868a26169dc6.zip u-boot-imx-bd6fb31fab1523ecac1aaf7af574868a26169dc6.tar.gz u-boot-imx-bd6fb31fab1523ecac1aaf7af574868a26169dc6.tar.bz2 |
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>
-rw-r--r-- | fs/fs.c | 9 | ||||
-rw-r--r-- | include/fs.h | 10 |
2 files changed, 13 insertions, 6 deletions
@@ -75,6 +75,7 @@ static struct fstype_info fstypes[] = { .close = fat_close, .ls = file_fat_ls, .read = fat_read_file, + .write = fs_write_unsupported, }, #endif #ifdef CONFIG_FS_EXT4 @@ -84,6 +85,7 @@ static struct fstype_info fstypes[] = { .close = ext4fs_close, .ls = ext4fs_ls, .read = ext4_read_file, + .write = fs_write_unsupported, }, #endif #ifdef CONFIG_SANDBOX @@ -212,16 +214,11 @@ int fs_write(const char *filename, ulong addr, int offset, int len) void *buf; int ret; - /* - * We don't actually know how many bytes are being read, since len==0 - * means read the whole file. - */ buf = map_sysmem(addr, len); ret = info->write(filename, buf, offset, len); unmap_sysmem(buf); - /* If we requested a specific number of bytes, check we got it */ - if (ret >= 0 && len && ret != len) { + if (ret >= 0 && ret != len) { printf("** Unable to write file %s **\n", filename); ret = -1; } diff --git a/include/fs.h b/include/fs.h index 7d9403e..97b0094 100644 --- a/include/fs.h +++ b/include/fs.h @@ -55,6 +55,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. */ |