[U-Boot] [PATCH 3/5] ubifs: return filesize from ubifs load operations

Murali Karicheri m-karicheri2 at ti.com
Mon Jan 20 23:10:08 CET 2014


This patch extends the ubifs load implementation to return the size of
the file loaded from the filesystem.  The ubifs command implementation
has also been modified to set the filesize environment variable
accordingly.

Signed-off-by: Vitaly Andrianov <vitalya at ti.com>
Signed-off-by: Murali Karicheri <m-karicheri2 at ti.com>
---
 common/cmd_ubifs.c |    7 +++++--
 fs/ubifs/ubifs.c   |   14 +++++++-------
 fs/ubifs/ubifs.h   |    2 +-
 3 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/common/cmd_ubifs.c b/common/cmd_ubifs.c
index fdc8bfe..a2926e0 100644
--- a/common/cmd_ubifs.c
+++ b/common/cmd_ubifs.c
@@ -110,6 +110,7 @@ int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	int ret;
 	u32 addr;
 	u32 size = 0;
+	char buf[32];
 
 	if (!ubifs_mounted) {
 		printf("UBIFS not mounted, use ubifs mount to mount volume first!\n");
@@ -132,12 +133,14 @@ int do_ubifs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	}
 	debug("Loading file '%s' to address 0x%08x (size %d)\n", filename, addr, size);
 
-	ret = ubifs_load(filename, addr, size);
+	ret = ubifs_load(filename, addr, &size);
 	if (ret) {
 		printf("** File not found %s **\n", filename);
 		ret = CMD_RET_FAILURE;
+	} else {
+		sprintf(buf, "%X", size);
+		setenv("filesize", buf);
 	}
-
 	return ret;
 }
 
diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c
index 273c0a9..4f1d5c7 100644
--- a/fs/ubifs/ubifs.c
+++ b/fs/ubifs/ubifs.c
@@ -677,7 +677,7 @@ error:
 	return err;
 }
 
-int ubifs_load(char *filename, u32 addr, u32 size)
+int ubifs_load(char *filename, u32 addr, u32 *size)
 {
 	struct ubifs_info *c = ubifs_sb->s_fs_info;
 	unsigned long inum;
@@ -711,12 +711,12 @@ int ubifs_load(char *filename, u32 addr, u32 size)
 	 * If no size was specified or if size bigger than filesize
 	 * set size to filesize
 	 */
-	if ((size == 0) || (size > inode->i_size))
-		size = inode->i_size;
+	if ((*size == 0) || (*size > inode->i_size))
+		*size = inode->i_size;
 
-	count = (size + UBIFS_BLOCK_SIZE - 1) >> UBIFS_BLOCK_SHIFT;
+	count = (*size + UBIFS_BLOCK_SIZE - 1) >> UBIFS_BLOCK_SHIFT;
 	printf("Loading file '%s' to addr 0x%08x with size %d (0x%08x)...\n",
-	       filename, addr, size, size);
+	       filename, addr, *size, *size);
 
 	page.addr = (void *)addr;
 	page.index = 0;
@@ -725,8 +725,8 @@ int ubifs_load(char *filename, u32 addr, u32 size)
 		/*
 		 * Make sure to not read beyond the requested size
 		 */
-		if (((i + 1) == count) && (size < inode->i_size))
-			last_block_size = size - (i * PAGE_SIZE);
+		if (((i + 1) == count) && (*size < inode->i_size))
+			last_block_size = *size - (i * PAGE_SIZE);
 
 		err = do_readpage(c, inode, &page, last_block_size);
 		if (err)
diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h
index 2213201..00485b3 100644
--- a/fs/ubifs/ubifs.h
+++ b/fs/ubifs/ubifs.h
@@ -2142,7 +2142,7 @@ int ubifs_init(void);
 int ubifs_mount(char *vol_name);
 void ubifs_umount(struct ubifs_info *c);
 int ubifs_ls(char *dir_name);
-int ubifs_load(char *filename, u32 addr, u32 size);
+int ubifs_load(char *filename, u32 addr, u32 *size);
 
 #include "debug.h"
 #include "misc.h"
-- 
1.7.9.5



More information about the U-Boot mailing list