]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - fs/fs.c
karo: tx6: fix out of range CORE_VDD
[karo-tx-uboot.git] / fs / fs.c
diff --git a/fs/fs.c b/fs/fs.c
index ddd751c9cccc1d4c30ed6d29bf1d55581e208ab7..0299c4b138760abc027139083fb1048f8aac28c9 100644 (file)
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -17,6 +17,7 @@
 #include <config.h>
 #include <errno.h>
 #include <common.h>
+#include <mapmem.h>
 #include <part.h>
 #include <ext4fs.h>
 #include <fat.h>
@@ -79,6 +80,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
@@ -105,6 +107,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,
@@ -123,6 +126,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,
@@ -141,6 +145,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,
@@ -154,6 +159,7 @@ static struct fstype_info fstypes[] = {
 #endif
        {
                .fstype = FS_TYPE_ANY,
+               .name = "unsupported",
                .null_dev_desc_ok = true,
                .probe = fs_probe_unsupported,
                .close = fs_close_unsupported,
@@ -190,6 +196,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;
@@ -278,26 +285,30 @@ int fs_size(const char *filename, loff_t *size)
        return ret;
 }
 
-int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
+int fs_read(const char *filename, ulong addr, loff_t offset, loff_t maxlen,
            loff_t *actread)
 {
        struct fstype_info *info = fs_get_info(fs_type);
        void *buf;
        int ret;
+       loff_t len;
 
-       /*
-        * We don't actually know how many bytes are being read, since len==0
-        * means read the whole file.
-        */
+       ret = info->size(filename, &len);
+       if (ret) {
+               printf("Failed to determine size of file %s: %d\n",
+                       filename, ret);
+               goto err;
+       }
+       if (maxlen == 0)
+               maxlen = len;
+       else if (len > maxlen)
+               printf("** File %s larger than buffer size; truncating to %llu of %llu bytes\n",
+                       filename, maxlen, len);
+       len = min(len, maxlen);
        buf = map_sysmem(addr, len);
        ret = info->read(filename, buf, offset, len, actread);
+err:
        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;
-       }
        fs_close();
 
        return ret;
@@ -503,3 +514,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;
+}
+