public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH V3 01/12] fs: fix generic save command implementation
@ 2014-01-27 20:49 Stephen Warren
  2014-01-27 20:49 ` [U-Boot] [PATCH V3 02/12] fs: implement infra-structure for an 'exists' function Stephen Warren
                   ` (10 more replies)
  0 siblings, 11 replies; 20+ messages in thread
From: Stephen Warren @ 2014-01-27 20:49 UTC (permalink / raw)
  To: u-boot

From: Stephen Warren <swarren@nvidia.com>

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>
---
v3: No change.
v2: No change.
---
 fs/fs.c      |  9 +++------
 include/fs.h | 10 ++++++++++
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index be1855d1291f..9c2ef6b6597c 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -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 7d9403ed8758..97b0094e954b 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.
  */
-- 
1.8.1.5

^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2014-02-03 20:37 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-27 20:49 [U-Boot] [PATCH V3 01/12] fs: fix generic save command implementation Stephen Warren
2014-01-27 20:49 ` [U-Boot] [PATCH V3 02/12] fs: implement infra-structure for an 'exists' function Stephen Warren
2014-01-31 21:56   ` Simon Glass
2014-01-27 20:49 ` [U-Boot] [PATCH V3 03/12] fs: don't pass NULL dev_desc to most filesystems Stephen Warren
2014-01-31 21:57   ` Simon Glass
2014-01-27 20:49 ` [U-Boot] [PATCH V3 04/12] cmd_test: use table lookup for parsing Stephen Warren
2014-02-01  0:03   ` Simon Glass
2014-02-03 20:19     ` Stephen Warren
2014-02-03 20:37       ` Simon Glass
2014-01-27 20:49 ` [U-Boot] [PATCH V3 05/12] cmd_test: check for binary operators before unary Stephen Warren
2014-01-27 20:49 ` [U-Boot] [PATCH V3 06/12] cmd_test: implement ! on sub-expressions Stephen Warren
2014-01-27 20:49 ` [U-Boot] [PATCH V3 07/12] cmd_test: evaluate to false without any arguments Stephen Warren
2014-01-27 20:49 ` [U-Boot] [PATCH V3 08/12] cmd_test: implement -e test for file existence Stephen Warren
2014-02-01  0:04   ` Simon Glass
2014-01-27 20:49 ` [U-Boot] [PATCH V3 09/12] sandbox: implement exists() function Stephen Warren
2014-01-27 20:50 ` [U-Boot] [PATCH V3 10/12] sandbox: enable CONFIG_CMD_FS_GENERIC Stephen Warren
2014-02-01  0:05   ` Simon Glass
2014-01-27 20:50 ` [U-Boot] [PATCH V3 11/12] ext4: implement exists() for ext4fs Stephen Warren
2014-01-27 20:50 ` [U-Boot] [PATCH V3 12/12] fat: implement exists() for FAT fs Stephen Warren
2014-02-01  0:06   ` Simon Glass

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox