Merge branch 'master' of git://git.denx.de/u-boot-nand-flash
[oweals/u-boot.git] / fs / fs.c
diff --git a/fs/fs.c b/fs/fs.c
index 8fe2403a46aea48e122972d9e4bdf65ba645148b..79d432d58fe094c8eb09e04204114b8bd0d7f172 100644 (file)
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -64,6 +64,15 @@ static inline void fs_close_unsupported(void)
 
 struct fstype_info {
        int fstype;
+       /*
+        * Is it legal to pass NULL as .probe()'s  fs_dev_desc parameter? This
+        * should be false in most cases. For "virtual" filesystems which
+        * aren't based on a U-Boot block device (e.g. sandbox), this can be
+        * set to true. This should also be true for the dumm entry at the end
+        * of fstypes[], since that is essentially a "virtual" (non-existent)
+        * filesystem.
+        */
+       bool null_dev_desc_ok;
        int (*probe)(block_dev_desc_t *fs_dev_desc,
                     disk_partition_t *fs_partition);
        int (*ls)(const char *dirname);
@@ -77,10 +86,11 @@ static struct fstype_info fstypes[] = {
 #ifdef CONFIG_FS_FAT
        {
                .fstype = FS_TYPE_FAT,
+               .null_dev_desc_ok = false,
                .probe = fat_set_blk_dev,
                .close = fat_close,
                .ls = file_fat_ls,
-               .exists = fs_exists_unsupported,
+               .exists = fat_exists,
                .read = fat_read_file,
                .write = fs_write_unsupported,
        },
@@ -88,10 +98,11 @@ static struct fstype_info fstypes[] = {
 #ifdef CONFIG_FS_EXT4
        {
                .fstype = FS_TYPE_EXT,
+               .null_dev_desc_ok = false,
                .probe = ext4fs_probe,
                .close = ext4fs_close,
                .ls = ext4fs_ls,
-               .exists = fs_exists_unsupported,
+               .exists = ext4fs_exists,
                .read = ext4_read_file,
                .write = fs_write_unsupported,
        },
@@ -99,16 +110,18 @@ static struct fstype_info fstypes[] = {
 #ifdef CONFIG_SANDBOX
        {
                .fstype = FS_TYPE_SANDBOX,
+               .null_dev_desc_ok = true,
                .probe = sandbox_fs_set_blk_dev,
                .close = sandbox_fs_close,
                .ls = sandbox_fs_ls,
-               .exists = fs_exists_unsupported,
+               .exists = sandbox_fs_exists,
                .read = fs_read_sandbox,
                .write = fs_write_sandbox,
        },
 #endif
        {
                .fstype = FS_TYPE_ANY,
+               .null_dev_desc_ok = true,
                .probe = fs_probe_unsupported,
                .close = fs_close_unsupported,
                .ls = fs_ls_unsupported,
@@ -162,6 +175,9 @@ int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype)
                                fstype != info->fstype)
                        continue;
 
+               if (!fs_dev_desc && !info->null_dev_desc_ok)
+                       continue;
+
                if (!info->probe(fs_dev_desc, &fs_partition)) {
                        fs_type = info->fstype;
                        return 0;