summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorStephen Warren <swarren@nvidia.com>2014-06-11 12:47:26 -0600
committerTom Rini <trini@ti.com>2014-08-09 11:16:57 -0400
commitcf6598193aed5de8855eaf70c1994f2bc437255a (patch)
tree4effb602945b18ad9c639cfd7b5e9f17eb02ffa4 /fs
parente76b933e02e1b38e48754c435e9dba1c0deeb3c6 (diff)
downloadu-boot-imx-cf6598193aed5de8855eaf70c1994f2bc437255a.zip
u-boot-imx-cf6598193aed5de8855eaf70c1994f2bc437255a.tar.gz
u-boot-imx-cf6598193aed5de8855eaf70c1994f2bc437255a.tar.bz2
fs: implement size/fatsize/ext4size
These commands may be used to determine the size of a file without actually reading the whole file content into memory. This may be used to determine if the file will fit into the memory buffer that will contain it. In particular, the DFU code will use it for this purpose in the next commit. Signed-off-by: Stephen Warren <swarren@nvidia.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/ext4/ext4fs.c5
-rw-r--r--fs/fat/fat.c5
-rw-r--r--fs/fs.c43
-rw-r--r--fs/sandbox/sandboxfs.c5
4 files changed, 58 insertions, 0 deletions
diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c
index 417ce7b..cbdc220 100644
--- a/fs/ext4/ext4fs.c
+++ b/fs/ext4/ext4fs.c
@@ -182,6 +182,11 @@ int ext4fs_exists(const char *filename)
return file_len >= 0;
}
+int ext4fs_size(const char *filename)
+{
+ return ext4fs_open(filename);
+}
+
int ext4fs_read(char *buf, unsigned len)
{
if (ext4fs_root == NULL || ext4fs_file == NULL)
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index 54f42ea..561921f 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -1243,6 +1243,11 @@ int fat_exists(const char *filename)
return sz >= 0;
}
+int fat_size(const char *filename)
+{
+ return do_fat_read_at(filename, 0, NULL, 0, LS_NO, 1);
+}
+
long file_fat_read_at(const char *filename, unsigned long pos, void *buffer,
unsigned long maxsize)
{
diff --git a/fs/fs.c b/fs/fs.c
index ea15c5f..dd680f3 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -46,6 +46,11 @@ static inline int fs_exists_unsupported(const char *filename)
return 0;
}
+static inline int fs_size_unsupported(const char *filename)
+{
+ return -1;
+}
+
static inline int fs_read_unsupported(const char *filename, void *buf,
int offset, int len)
{
@@ -77,6 +82,7 @@ struct fstype_info {
disk_partition_t *fs_partition);
int (*ls)(const char *dirname);
int (*exists)(const char *filename);
+ int (*size)(const char *filename);
int (*read)(const char *filename, void *buf, int offset, int len);
int (*write)(const char *filename, void *buf, int offset, int len);
void (*close)(void);
@@ -91,6 +97,7 @@ static struct fstype_info fstypes[] = {
.close = fat_close,
.ls = file_fat_ls,
.exists = fat_exists,
+ .size = fat_size,
.read = fat_read_file,
.write = fs_write_unsupported,
},
@@ -103,6 +110,7 @@ static struct fstype_info fstypes[] = {
.close = ext4fs_close,
.ls = ext4fs_ls,
.exists = ext4fs_exists,
+ .size = ext4fs_size,
.read = ext4_read_file,
.write = fs_write_unsupported,
},
@@ -115,6 +123,7 @@ static struct fstype_info fstypes[] = {
.close = sandbox_fs_close,
.ls = sandbox_fs_ls,
.exists = sandbox_fs_exists,
+ .size = sandbox_fs_size,
.read = fs_read_sandbox,
.write = fs_write_sandbox,
},
@@ -126,6 +135,7 @@ static struct fstype_info fstypes[] = {
.close = fs_close_unsupported,
.ls = fs_ls_unsupported,
.exists = fs_exists_unsupported,
+ .size = fs_size_unsupported,
.read = fs_read_unsupported,
.write = fs_write_unsupported,
},
@@ -223,6 +233,19 @@ int fs_exists(const char *filename)
return ret;
}
+int fs_size(const char *filename)
+{
+ int ret;
+
+ struct fstype_info *info = fs_get_info(fs_type);
+
+ ret = info->size(filename);
+
+ fs_close();
+
+ return ret;
+}
+
int fs_read(const char *filename, ulong addr, int offset, int len)
{
struct fstype_info *info = fs_get_info(fs_type);
@@ -266,6 +289,26 @@ int fs_write(const char *filename, ulong addr, int offset, int len)
return ret;
}
+int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
+ int fstype)
+{
+ int size;
+
+ if (argc != 4)
+ return CMD_RET_USAGE;
+
+ if (fs_set_blk_dev(argv[1], argv[2], fstype))
+ return 1;
+
+ size = fs_size(argv[3]);
+ if (size < 0)
+ return CMD_RET_FAILURE;
+
+ setenv_hex("filesize", size);
+
+ return 0;
+}
+
int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
int fstype)
{
diff --git a/fs/sandbox/sandboxfs.c b/fs/sandbox/sandboxfs.c
index 8507978..ba6402c 100644
--- a/fs/sandbox/sandboxfs.c
+++ b/fs/sandbox/sandboxfs.c
@@ -80,6 +80,11 @@ int sandbox_fs_exists(const char *filename)
return sz >= 0;
}
+int sandbox_fs_size(const char *filename)
+{
+ return os_get_filesize(filename);
+}
+
void sandbox_fs_close(void)
{
}