fs: don't pass NULL dev_desc to most filesystems
FAT and ext4 expect that the passed in block device descriptor not be
NULL. This causes problems on sandbox, where get_device_and_partition()
succeeds for the "host" device, yet passes back a NULL device descriptor.
Add special handling for this situation, so that the generic filesystem
commands operate as expected on sandbox.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
diff --git a/fs/fs.c b/fs/fs.c
index 8fe2403..aaa6732 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -64,6 +64,15 @@
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,6 +86,7 @@
#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,
@@ -88,6 +98,7 @@
#ifdef CONFIG_FS_EXT4
{
.fstype = FS_TYPE_EXT,
+ .null_dev_desc_ok = false,
.probe = ext4fs_probe,
.close = ext4fs_close,
.ls = ext4fs_ls,
@@ -99,6 +110,7 @@
#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,
@@ -109,6 +121,7 @@
#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 @@
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;