diff mbox

[U-Boot,V3,03/12] fs: don't pass NULL dev_desc to most filesystems

Message ID 1390855802-17504-3-git-send-email-swarren@wwwdotorg.org
State Superseded
Delegated to: Tom Rini
Headers show

Commit Message

Stephen Warren Jan. 27, 2014, 8:49 p.m. UTC
From: Stephen Warren <swarren@nvidia.com>

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>
---
v3: New patch.
---
 fs/fs.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Simon Glass Jan. 31, 2014, 9:57 p.m. UTC | #1
Hi Stephen,

On 27 January 2014 13:49, Stephen Warren <swarren@wwwdotorg.org> wrote:
> From: Stephen Warren <swarren@nvidia.com>
>
> 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>
> ---
> v3: New patch.
> ---
>  fs/fs.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/fs/fs.c b/fs/fs.c
> index 8fe2403a46ae..653e597c3cc9 100644
> --- a/fs/fs.c
> +++ b/fs/fs.c
> @@ -64,6 +64,7 @@ static inline void fs_close_unsupported(void)
>
>  struct fstype_info {
>         int fstype;
> +       bool null_dev_desc_ok;

I suggest adding a comment for this field.

>         int (*probe)(block_dev_desc_t *fs_dev_desc,
>                      disk_partition_t *fs_partition);
>         int (*ls)(const char *dirname);
> @@ -77,6 +78,7 @@ 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,
> @@ -88,6 +90,7 @@ 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,
> @@ -99,6 +102,7 @@ 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,
> @@ -109,6 +113,7 @@ static struct fstype_info fstypes[] = {
>  #endif
>         {
>                 .fstype = FS_TYPE_ANY,
> +               .null_dev_desc_ok = true,
>                 .probe = fs_probe_unsupported,
>                 .close = fs_close_unsupported,
>                 .ls = fs_ls_unsupported,
> @@ -162,6 +167,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;
> --
> 1.8.1.5
>

Regards,
Simon
diff mbox

Patch

diff --git a/fs/fs.c b/fs/fs.c
index 8fe2403a46ae..653e597c3cc9 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -64,6 +64,7 @@  static inline void fs_close_unsupported(void)
 
 struct fstype_info {
 	int fstype;
+	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 +78,7 @@  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,
@@ -88,6 +90,7 @@  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,
@@ -99,6 +102,7 @@  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,
@@ -109,6 +113,7 @@  static struct fstype_info fstypes[] = {
 #endif
 	{
 		.fstype = FS_TYPE_ANY,
+		.null_dev_desc_ok = true,
 		.probe = fs_probe_unsupported,
 		.close = fs_close_unsupported,
 		.ls = fs_ls_unsupported,
@@ -162,6 +167,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;