]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - fs/fs.c
arc: add empty asm/processor.h to satisfy compilation of USB code
[people/ms/u-boot.git] / fs / fs.c
diff --git a/fs/fs.c b/fs/fs.c
index 3da78606d1281f93ebe3108b9a7bd8f6e5f31edc..b2d6a532330cb2cc14d77a5490971b6bcebd1d0b 100644 (file)
--- a/fs/fs.c
+++ b/fs/fs.c
 #include <config.h>
 #include <errno.h>
 #include <common.h>
+#include <mapmem.h>
 #include <part.h>
 #include <ext4fs.h>
 #include <fat.h>
 #include <fs.h>
 #include <sandboxfs.h>
+#include <ubifs_uboot.h>
 #include <asm/io.h>
+#include <div64.h>
+#include <linux/math64.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -77,6 +81,7 @@ static inline int fs_uuid_unsupported(char *uuid_str)
 
 struct fstype_info {
        int fstype;
+       char *name;
        /*
         * Is it legal to pass NULL as .probe()'s  fs_dev_desc parameter? This
         * should be false in most cases. For "virtual" filesystems which
@@ -103,6 +108,7 @@ static struct fstype_info fstypes[] = {
 #ifdef CONFIG_FS_FAT
        {
                .fstype = FS_TYPE_FAT,
+               .name = "fat",
                .null_dev_desc_ok = false,
                .probe = fat_set_blk_dev,
                .close = fat_close,
@@ -121,6 +127,7 @@ static struct fstype_info fstypes[] = {
 #ifdef CONFIG_FS_EXT4
        {
                .fstype = FS_TYPE_EXT,
+               .name = "ext4",
                .null_dev_desc_ok = false,
                .probe = ext4fs_probe,
                .close = ext4fs_close,
@@ -139,6 +146,7 @@ static struct fstype_info fstypes[] = {
 #ifdef CONFIG_SANDBOX
        {
                .fstype = FS_TYPE_SANDBOX,
+               .name = "sandbox",
                .null_dev_desc_ok = true,
                .probe = sandbox_fs_set_blk_dev,
                .close = sandbox_fs_close,
@@ -149,9 +157,25 @@ static struct fstype_info fstypes[] = {
                .write = fs_write_sandbox,
                .uuid = fs_uuid_unsupported,
        },
+#endif
+#ifdef CONFIG_CMD_UBIFS
+       {
+               .fstype = FS_TYPE_UBIFS,
+               .name = "ubifs",
+               .null_dev_desc_ok = true,
+               .probe = ubifs_set_blk_dev,
+               .close = ubifs_close,
+               .ls = ubifs_ls,
+               .exists = ubifs_exists,
+               .size = ubifs_size,
+               .read = ubifs_read,
+               .write = fs_write_unsupported,
+               .uuid = fs_uuid_unsupported,
+       },
 #endif
        {
                .fstype = FS_TYPE_ANY,
+               .name = "unsupported",
                .null_dev_desc_ok = true,
                .probe = fs_probe_unsupported,
                .close = fs_close_unsupported,
@@ -188,6 +212,7 @@ int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype)
        if (!relocated) {
                for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes);
                                i++, info++) {
+                       info->name += gd->reloc_off;
                        info->probe += gd->reloc_off;
                        info->close += gd->reloc_off;
                        info->ls += gd->reloc_off;
@@ -292,10 +317,8 @@ int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
        unmap_sysmem(buf);
 
        /* If we requested a specific number of bytes, check we got it */
-       if (ret == 0 && len && *actread != len) {
-               printf("** Unable to read file %s **\n", filename);
-               ret = -1;
-       }
+       if (ret == 0 && len && *actread != len)
+               printf("** %s shorter than offset + len **\n", filename);
        fs_close();
 
        return ret;
@@ -399,7 +422,7 @@ int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
        printf("%llu bytes read in %lu ms", len_read, time);
        if (time > 0) {
                puts(" (");
-               print_size(len_read / time * 1000, "/s");
+               print_size(div_u64(len_read, time) * 1000, "/s");
                puts(")");
        }
        puts("\n");
@@ -469,7 +492,7 @@ int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
        printf("%llu bytes written in %lu ms", len, time);
        if (time > 0) {
                puts(" (");
-               print_size(len / time * 1000, "/s");
+               print_size(div_u64(len, time) * 1000, "/s");
                puts(")");
        }
        puts("\n");
@@ -501,3 +524,24 @@ int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
 
        return CMD_RET_SUCCESS;
 }
+
+int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       struct fstype_info *info;
+
+       if (argc < 3 || argc > 4)
+               return CMD_RET_USAGE;
+
+       if (fs_set_blk_dev(argv[1], argv[2], FS_TYPE_ANY))
+               return 1;
+
+       info = fs_get_info(fs_type);
+
+       if (argc == 4)
+               setenv(argv[3], info->name);
+       else
+               printf("%s\n", info->name);
+
+       return CMD_RET_SUCCESS;
+}
+