[v2,3/3] efi_loader: remove block device details from efi file

Message ID 20181115045810.28736-4-takahiro.akashi@linaro.org
State New
Headers show
Series
  • efi_loader: add removable device support
Related show

Commit Message

AKASHI Takahiro Nov. 15, 2018, 4:58 a.m.
Logically, details on u-boot block device used to implement efi file
protocol are mostly unnecessary, as well as being duplicated, in
efi_file structure.
Moreover, a newly introduced flag, _EFI_DISK_FLAG_INVALID, should be
honored in any file operations via efi file protocol.
These observation suggests that those internal details be set behind
efi_disk object.

So rework in this patch addresses all those issues above although
there is little change in its functionality.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 include/efi_loader.h      |  6 +++++-
 lib/efi_loader/efi_disk.c | 38 ++++++++++++++++++++++++++++++++++++--
 lib/efi_loader/efi_file.c | 21 ++++++++-------------
 3 files changed, 49 insertions(+), 16 deletions(-)

Comments

Alexander Graf Jan. 9, 2019, 9:18 a.m. | #1
On 15.11.18 05:58, AKASHI Takahiro wrote:
> Logically, details on u-boot block device used to implement efi file
> protocol are mostly unnecessary, as well as being duplicated, in
> efi_file structure.
> Moreover, a newly introduced flag, _EFI_DISK_FLAG_INVALID, should be
> honored in any file operations via efi file protocol.
> These observation suggests that those internal details be set behind
> efi_disk object.
> 
> So rework in this patch addresses all those issues above although
> there is little change in its functionality.
> 
> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> ---
>  include/efi_loader.h      |  6 +++++-
>  lib/efi_loader/efi_disk.c | 38 ++++++++++++++++++++++++++++++++++++--
>  lib/efi_loader/efi_file.c | 21 ++++++++-------------
>  3 files changed, 49 insertions(+), 16 deletions(-)
> 
> diff --git a/include/efi_loader.h b/include/efi_loader.h
> index 3bae1844befb..108ef3fe52ee 100644
> --- a/include/efi_loader.h
> +++ b/include/efi_loader.h
> @@ -264,6 +264,10 @@ efi_status_t efi_disk_register(void);
>  bool efi_disk_is_valid(efi_handle_t handle);
>  /* Called by bootefi to find and update disk storage information */
>  efi_status_t efi_disk_update(void);
> +/* Called by file protocol to set internal block io device */
> +int efi_disk_set_blk_dev(efi_handle_t disk);
> +/* Called by file protocol to get disk/partition information */
> +int efi_disk_get_info(efi_handle_t disk, disk_partition_t *part);
>  /* Create handles and protocols for the partitions of a block device */
>  int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc,
>  			       const char *if_typename, int diskid,
> @@ -355,7 +359,7 @@ void efi_signal_event(struct efi_event *event, bool check_tpl);
>  
>  /* open file system: */
>  struct efi_simple_file_system_protocol *efi_simple_file_system(
> -		struct blk_desc *desc, int part, struct efi_device_path *dp);
> +		efi_handle_t disk);
>  
>  /* open file from device-path: */
>  struct efi_file_handle *efi_file_from_path(struct efi_device_path *fp);
> diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
> index 0c4d79ee3fc9..180e8e10bb28 100644
> --- a/lib/efi_loader/efi_disk.c
> +++ b/lib/efi_loader/efi_disk.c
> @@ -9,6 +9,7 @@
>  #include <blk.h>
>  #include <dm.h>
>  #include <efi_loader.h>
> +#include <fs.h>
>  #include <part.h>
>  #include <malloc.h>
>  
> @@ -254,6 +255,40 @@ efi_fs_from_path(struct efi_device_path *full_path)
>  	return handler->protocol_interface;
>  }
>  
> +/*
> + * Set block device for later block io's from file system protocol
> + *
> + * @disk	handle to uefi disk device
> + * @return	0 for success, -1 for failure
> + */
> +int efi_disk_set_blk_dev(efi_handle_t disk)
> +{
> +	struct efi_disk_obj *diskobj;
> +
> +	diskobj = container_of(disk, struct efi_disk_obj, header);
> +
> +	return fs_set_blk_dev_with_part(diskobj->desc, diskobj->part);
> +}
> +
> +/*
> + * Get disk/partition information
> + *
> + * @disk	handle to uefi disk device
> + * @part	pointer to disk/partition information to be returned
> + * @return	0 for success, -1 for failure
> + */
> +int efi_disk_get_info(efi_handle_t disk, disk_partition_t *part)
> +{
> +	struct efi_disk_obj *diskobj;
> +
> +	diskobj = container_of(disk, struct efi_disk_obj, header);
> +
> +	if (diskobj->part >= 1)
> +		return part_get_info(diskobj->desc, diskobj->part, part);
> +	else
> +		return part_get_info_whole_disk(diskobj->desc, part);
> +}
> +
>  /*
>   * Create a handle for a partition or disk
>   *
> @@ -308,8 +343,7 @@ static efi_status_t efi_disk_add_dev(
>  	if (ret != EFI_SUCCESS)
>  		return ret;
>  	if (part >= 1) {
> -		diskobj->volume = efi_simple_file_system(desc, part,
> -							 diskobj->dp);
> +		diskobj->volume = efi_simple_file_system(&diskobj->header);
>  		ret = efi_add_protocol(&diskobj->header,
>  				       &efi_simple_file_system_protocol_guid,
>  				       diskobj->volume);
> diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c
> index beb4fba917d8..944383224f30 100644
> --- a/lib/efi_loader/efi_file.c
> +++ b/lib/efi_loader/efi_file.c
> @@ -17,9 +17,7 @@ const efi_guid_t efi_file_system_info_guid = EFI_FILE_SYSTEM_INFO_GUID;
>  
>  struct file_system {
>  	struct efi_simple_file_system_protocol base;
> -	struct efi_device_path *dp;
> -	struct blk_desc *desc;
> -	int part;
> +	efi_handle_t disk;

Is there a particular reason we can't just make this a struct
efi_disk_obj *?

Inside our own code base, we don't need to abstract things away to
handles, right? We also want to have the compiler catch the fact early
if people pass in non-disk-objects in as parameter.


Alex
AKASHI Takahiro Jan. 10, 2019, 12:37 a.m. | #2
Alex,

On Wed, Jan 09, 2019 at 10:18:16AM +0100, Alexander Graf wrote:
> 
> 
> On 15.11.18 05:58, AKASHI Takahiro wrote:
> > Logically, details on u-boot block device used to implement efi file
> > protocol are mostly unnecessary, as well as being duplicated, in
> > efi_file structure.
> > Moreover, a newly introduced flag, _EFI_DISK_FLAG_INVALID, should be
> > honored in any file operations via efi file protocol.
> > These observation suggests that those internal details be set behind
> > efi_disk object.
> > 
> > So rework in this patch addresses all those issues above although
> > there is little change in its functionality.
> > 
> > Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> > ---
> >  include/efi_loader.h      |  6 +++++-
> >  lib/efi_loader/efi_disk.c | 38 ++++++++++++++++++++++++++++++++++++--
> >  lib/efi_loader/efi_file.c | 21 ++++++++-------------
> >  3 files changed, 49 insertions(+), 16 deletions(-)
> > 
> > diff --git a/include/efi_loader.h b/include/efi_loader.h
> > index 3bae1844befb..108ef3fe52ee 100644
> > --- a/include/efi_loader.h
> > +++ b/include/efi_loader.h
> > @@ -264,6 +264,10 @@ efi_status_t efi_disk_register(void);
> >  bool efi_disk_is_valid(efi_handle_t handle);
> >  /* Called by bootefi to find and update disk storage information */
> >  efi_status_t efi_disk_update(void);
> > +/* Called by file protocol to set internal block io device */
> > +int efi_disk_set_blk_dev(efi_handle_t disk);
> > +/* Called by file protocol to get disk/partition information */
> > +int efi_disk_get_info(efi_handle_t disk, disk_partition_t *part);
> >  /* Create handles and protocols for the partitions of a block device */
> >  int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc,
> >  			       const char *if_typename, int diskid,
> > @@ -355,7 +359,7 @@ void efi_signal_event(struct efi_event *event, bool check_tpl);
> >  
> >  /* open file system: */
> >  struct efi_simple_file_system_protocol *efi_simple_file_system(
> > -		struct blk_desc *desc, int part, struct efi_device_path *dp);
> > +		efi_handle_t disk);
> >  
> >  /* open file from device-path: */
> >  struct efi_file_handle *efi_file_from_path(struct efi_device_path *fp);
> > diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
> > index 0c4d79ee3fc9..180e8e10bb28 100644
> > --- a/lib/efi_loader/efi_disk.c
> > +++ b/lib/efi_loader/efi_disk.c
> > @@ -9,6 +9,7 @@
> >  #include <blk.h>
> >  #include <dm.h>
> >  #include <efi_loader.h>
> > +#include <fs.h>
> >  #include <part.h>
> >  #include <malloc.h>
> >  
> > @@ -254,6 +255,40 @@ efi_fs_from_path(struct efi_device_path *full_path)
> >  	return handler->protocol_interface;
> >  }
> >  
> > +/*
> > + * Set block device for later block io's from file system protocol
> > + *
> > + * @disk	handle to uefi disk device
> > + * @return	0 for success, -1 for failure
> > + */
> > +int efi_disk_set_blk_dev(efi_handle_t disk)
> > +{
> > +	struct efi_disk_obj *diskobj;
> > +
> > +	diskobj = container_of(disk, struct efi_disk_obj, header);
> > +
> > +	return fs_set_blk_dev_with_part(diskobj->desc, diskobj->part);
> > +}
> > +
> > +/*
> > + * Get disk/partition information
> > + *
> > + * @disk	handle to uefi disk device
> > + * @part	pointer to disk/partition information to be returned
> > + * @return	0 for success, -1 for failure
> > + */
> > +int efi_disk_get_info(efi_handle_t disk, disk_partition_t *part)
> > +{
> > +	struct efi_disk_obj *diskobj;
> > +
> > +	diskobj = container_of(disk, struct efi_disk_obj, header);
> > +
> > +	if (diskobj->part >= 1)
> > +		return part_get_info(diskobj->desc, diskobj->part, part);
> > +	else
> > +		return part_get_info_whole_disk(diskobj->desc, part);
> > +}
> > +
> >  /*
> >   * Create a handle for a partition or disk
> >   *
> > @@ -308,8 +343,7 @@ static efi_status_t efi_disk_add_dev(
> >  	if (ret != EFI_SUCCESS)
> >  		return ret;
> >  	if (part >= 1) {
> > -		diskobj->volume = efi_simple_file_system(desc, part,
> > -							 diskobj->dp);
> > +		diskobj->volume = efi_simple_file_system(&diskobj->header);
> >  		ret = efi_add_protocol(&diskobj->header,
> >  				       &efi_simple_file_system_protocol_guid,
> >  				       diskobj->volume);
> > diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c
> > index beb4fba917d8..944383224f30 100644
> > --- a/lib/efi_loader/efi_file.c
> > +++ b/lib/efi_loader/efi_file.c
> > @@ -17,9 +17,7 @@ const efi_guid_t efi_file_system_info_guid = EFI_FILE_SYSTEM_INFO_GUID;
> >  
> >  struct file_system {
> >  	struct efi_simple_file_system_protocol base;
> > -	struct efi_device_path *dp;
> > -	struct blk_desc *desc;
> > -	int part;
> > +	efi_handle_t disk;
> 
> Is there a particular reason we can't just make this a struct
> efi_disk_obj *?

Just because efi_disk_obj is an internally-defined structure in efi_disk.c.

> Inside our own code base, we don't need to abstract things away to
> handles, right? We also want to have the compiler catch the fact early
> if people pass in non-disk-objects in as parameter.

If you don't mind efi_disk_obj definition being moved to, say, efi_loader.h,
I would follow your suggestion.

Thanks,
-Takahiro Akashi

> 
> Alex
Alexander Graf Jan. 10, 2019, 6:22 a.m. | #3
On 10.01.19 01:37, AKASHI Takahiro wrote:
> Alex,
> 
> On Wed, Jan 09, 2019 at 10:18:16AM +0100, Alexander Graf wrote:
>>
>>
>> On 15.11.18 05:58, AKASHI Takahiro wrote:
>>> Logically, details on u-boot block device used to implement efi file
>>> protocol are mostly unnecessary, as well as being duplicated, in
>>> efi_file structure.
>>> Moreover, a newly introduced flag, _EFI_DISK_FLAG_INVALID, should be
>>> honored in any file operations via efi file protocol.
>>> These observation suggests that those internal details be set behind
>>> efi_disk object.
>>>
>>> So rework in this patch addresses all those issues above although
>>> there is little change in its functionality.
>>>
>>> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
>>> ---
>>>  include/efi_loader.h      |  6 +++++-
>>>  lib/efi_loader/efi_disk.c | 38 ++++++++++++++++++++++++++++++++++++--
>>>  lib/efi_loader/efi_file.c | 21 ++++++++-------------
>>>  3 files changed, 49 insertions(+), 16 deletions(-)
>>>
>>> diff --git a/include/efi_loader.h b/include/efi_loader.h
>>> index 3bae1844befb..108ef3fe52ee 100644
>>> --- a/include/efi_loader.h
>>> +++ b/include/efi_loader.h
>>> @@ -264,6 +264,10 @@ efi_status_t efi_disk_register(void);
>>>  bool efi_disk_is_valid(efi_handle_t handle);
>>>  /* Called by bootefi to find and update disk storage information */
>>>  efi_status_t efi_disk_update(void);
>>> +/* Called by file protocol to set internal block io device */
>>> +int efi_disk_set_blk_dev(efi_handle_t disk);
>>> +/* Called by file protocol to get disk/partition information */
>>> +int efi_disk_get_info(efi_handle_t disk, disk_partition_t *part);
>>>  /* Create handles and protocols for the partitions of a block device */
>>>  int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc,
>>>  			       const char *if_typename, int diskid,
>>> @@ -355,7 +359,7 @@ void efi_signal_event(struct efi_event *event, bool check_tpl);
>>>  
>>>  /* open file system: */
>>>  struct efi_simple_file_system_protocol *efi_simple_file_system(
>>> -		struct blk_desc *desc, int part, struct efi_device_path *dp);
>>> +		efi_handle_t disk);
>>>  
>>>  /* open file from device-path: */
>>>  struct efi_file_handle *efi_file_from_path(struct efi_device_path *fp);
>>> diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
>>> index 0c4d79ee3fc9..180e8e10bb28 100644
>>> --- a/lib/efi_loader/efi_disk.c
>>> +++ b/lib/efi_loader/efi_disk.c
>>> @@ -9,6 +9,7 @@
>>>  #include <blk.h>
>>>  #include <dm.h>
>>>  #include <efi_loader.h>
>>> +#include <fs.h>
>>>  #include <part.h>
>>>  #include <malloc.h>
>>>  
>>> @@ -254,6 +255,40 @@ efi_fs_from_path(struct efi_device_path *full_path)
>>>  	return handler->protocol_interface;
>>>  }
>>>  
>>> +/*
>>> + * Set block device for later block io's from file system protocol
>>> + *
>>> + * @disk	handle to uefi disk device
>>> + * @return	0 for success, -1 for failure
>>> + */
>>> +int efi_disk_set_blk_dev(efi_handle_t disk)
>>> +{
>>> +	struct efi_disk_obj *diskobj;
>>> +
>>> +	diskobj = container_of(disk, struct efi_disk_obj, header);
>>> +
>>> +	return fs_set_blk_dev_with_part(diskobj->desc, diskobj->part);
>>> +}
>>> +
>>> +/*
>>> + * Get disk/partition information
>>> + *
>>> + * @disk	handle to uefi disk device
>>> + * @part	pointer to disk/partition information to be returned
>>> + * @return	0 for success, -1 for failure
>>> + */
>>> +int efi_disk_get_info(efi_handle_t disk, disk_partition_t *part)
>>> +{
>>> +	struct efi_disk_obj *diskobj;
>>> +
>>> +	diskobj = container_of(disk, struct efi_disk_obj, header);
>>> +
>>> +	if (diskobj->part >= 1)
>>> +		return part_get_info(diskobj->desc, diskobj->part, part);
>>> +	else
>>> +		return part_get_info_whole_disk(diskobj->desc, part);
>>> +}
>>> +
>>>  /*
>>>   * Create a handle for a partition or disk
>>>   *
>>> @@ -308,8 +343,7 @@ static efi_status_t efi_disk_add_dev(
>>>  	if (ret != EFI_SUCCESS)
>>>  		return ret;
>>>  	if (part >= 1) {
>>> -		diskobj->volume = efi_simple_file_system(desc, part,
>>> -							 diskobj->dp);
>>> +		diskobj->volume = efi_simple_file_system(&diskobj->header);
>>>  		ret = efi_add_protocol(&diskobj->header,
>>>  				       &efi_simple_file_system_protocol_guid,
>>>  				       diskobj->volume);
>>> diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c
>>> index beb4fba917d8..944383224f30 100644
>>> --- a/lib/efi_loader/efi_file.c
>>> +++ b/lib/efi_loader/efi_file.c
>>> @@ -17,9 +17,7 @@ const efi_guid_t efi_file_system_info_guid = EFI_FILE_SYSTEM_INFO_GUID;
>>>  
>>>  struct file_system {
>>>  	struct efi_simple_file_system_protocol base;
>>> -	struct efi_device_path *dp;
>>> -	struct blk_desc *desc;
>>> -	int part;
>>> +	efi_handle_t disk;
>>
>> Is there a particular reason we can't just make this a struct
>> efi_disk_obj *?
> 
> Just because efi_disk_obj is an internally-defined structure in efi_disk.c.
> 
>> Inside our own code base, we don't need to abstract things away to
>> handles, right? We also want to have the compiler catch the fact early
>> if people pass in non-disk-objects in as parameter.
> 
> If you don't mind efi_disk_obj definition being moved to, say, efi_loader.h,
> I would follow your suggestion.

I don't think we need to move the definition, just the hint that the
name exists.

If you add the following to efi_loader.h:

  struct efi_disk_obj;

that should be enough to enable other subsystems (and APIs) to use
pointers to that struct.


Alex
AKASHI Takahiro Jan. 10, 2019, 6:36 a.m. | #4
On Thu, Jan 10, 2019 at 07:22:49AM +0100, Alexander Graf wrote:
> 
> 
> On 10.01.19 01:37, AKASHI Takahiro wrote:
> > Alex,
> > 
> > On Wed, Jan 09, 2019 at 10:18:16AM +0100, Alexander Graf wrote:
> >>
> >>
> >> On 15.11.18 05:58, AKASHI Takahiro wrote:
> >>> Logically, details on u-boot block device used to implement efi file
> >>> protocol are mostly unnecessary, as well as being duplicated, in
> >>> efi_file structure.
> >>> Moreover, a newly introduced flag, _EFI_DISK_FLAG_INVALID, should be
> >>> honored in any file operations via efi file protocol.
> >>> These observation suggests that those internal details be set behind
> >>> efi_disk object.
> >>>
> >>> So rework in this patch addresses all those issues above although
> >>> there is little change in its functionality.
> >>>
> >>> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> >>> ---
> >>>  include/efi_loader.h      |  6 +++++-
> >>>  lib/efi_loader/efi_disk.c | 38 ++++++++++++++++++++++++++++++++++++--
> >>>  lib/efi_loader/efi_file.c | 21 ++++++++-------------
> >>>  3 files changed, 49 insertions(+), 16 deletions(-)
> >>>
> >>> diff --git a/include/efi_loader.h b/include/efi_loader.h
> >>> index 3bae1844befb..108ef3fe52ee 100644
> >>> --- a/include/efi_loader.h
> >>> +++ b/include/efi_loader.h
> >>> @@ -264,6 +264,10 @@ efi_status_t efi_disk_register(void);
> >>>  bool efi_disk_is_valid(efi_handle_t handle);
> >>>  /* Called by bootefi to find and update disk storage information */
> >>>  efi_status_t efi_disk_update(void);
> >>> +/* Called by file protocol to set internal block io device */
> >>> +int efi_disk_set_blk_dev(efi_handle_t disk);
> >>> +/* Called by file protocol to get disk/partition information */
> >>> +int efi_disk_get_info(efi_handle_t disk, disk_partition_t *part);
> >>>  /* Create handles and protocols for the partitions of a block device */
> >>>  int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc,
> >>>  			       const char *if_typename, int diskid,
> >>> @@ -355,7 +359,7 @@ void efi_signal_event(struct efi_event *event, bool check_tpl);
> >>>  
> >>>  /* open file system: */
> >>>  struct efi_simple_file_system_protocol *efi_simple_file_system(
> >>> -		struct blk_desc *desc, int part, struct efi_device_path *dp);
> >>> +		efi_handle_t disk);
> >>>  
> >>>  /* open file from device-path: */
> >>>  struct efi_file_handle *efi_file_from_path(struct efi_device_path *fp);
> >>> diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
> >>> index 0c4d79ee3fc9..180e8e10bb28 100644
> >>> --- a/lib/efi_loader/efi_disk.c
> >>> +++ b/lib/efi_loader/efi_disk.c
> >>> @@ -9,6 +9,7 @@
> >>>  #include <blk.h>
> >>>  #include <dm.h>
> >>>  #include <efi_loader.h>
> >>> +#include <fs.h>
> >>>  #include <part.h>
> >>>  #include <malloc.h>
> >>>  
> >>> @@ -254,6 +255,40 @@ efi_fs_from_path(struct efi_device_path *full_path)
> >>>  	return handler->protocol_interface;
> >>>  }
> >>>  
> >>> +/*
> >>> + * Set block device for later block io's from file system protocol
> >>> + *
> >>> + * @disk	handle to uefi disk device
> >>> + * @return	0 for success, -1 for failure
> >>> + */
> >>> +int efi_disk_set_blk_dev(efi_handle_t disk)
> >>> +{
> >>> +	struct efi_disk_obj *diskobj;
> >>> +
> >>> +	diskobj = container_of(disk, struct efi_disk_obj, header);
> >>> +
> >>> +	return fs_set_blk_dev_with_part(diskobj->desc, diskobj->part);
> >>> +}
> >>> +
> >>> +/*
> >>> + * Get disk/partition information
> >>> + *
> >>> + * @disk	handle to uefi disk device
> >>> + * @part	pointer to disk/partition information to be returned
> >>> + * @return	0 for success, -1 for failure
> >>> + */
> >>> +int efi_disk_get_info(efi_handle_t disk, disk_partition_t *part)
> >>> +{
> >>> +	struct efi_disk_obj *diskobj;
> >>> +
> >>> +	diskobj = container_of(disk, struct efi_disk_obj, header);
> >>> +
> >>> +	if (diskobj->part >= 1)
> >>> +		return part_get_info(diskobj->desc, diskobj->part, part);
> >>> +	else
> >>> +		return part_get_info_whole_disk(diskobj->desc, part);
> >>> +}
> >>> +
> >>>  /*
> >>>   * Create a handle for a partition or disk
> >>>   *
> >>> @@ -308,8 +343,7 @@ static efi_status_t efi_disk_add_dev(
> >>>  	if (ret != EFI_SUCCESS)
> >>>  		return ret;
> >>>  	if (part >= 1) {
> >>> -		diskobj->volume = efi_simple_file_system(desc, part,
> >>> -							 diskobj->dp);
> >>> +		diskobj->volume = efi_simple_file_system(&diskobj->header);
> >>>  		ret = efi_add_protocol(&diskobj->header,
> >>>  				       &efi_simple_file_system_protocol_guid,
> >>>  				       diskobj->volume);
> >>> diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c
> >>> index beb4fba917d8..944383224f30 100644
> >>> --- a/lib/efi_loader/efi_file.c
> >>> +++ b/lib/efi_loader/efi_file.c
> >>> @@ -17,9 +17,7 @@ const efi_guid_t efi_file_system_info_guid = EFI_FILE_SYSTEM_INFO_GUID;
> >>>  
> >>>  struct file_system {
> >>>  	struct efi_simple_file_system_protocol base;
> >>> -	struct efi_device_path *dp;
> >>> -	struct blk_desc *desc;
> >>> -	int part;
> >>> +	efi_handle_t disk;
> >>
> >> Is there a particular reason we can't just make this a struct
> >> efi_disk_obj *?
> > 
> > Just because efi_disk_obj is an internally-defined structure in efi_disk.c.
> > 
> >> Inside our own code base, we don't need to abstract things away to
> >> handles, right? We also want to have the compiler catch the fact early
> >> if people pass in non-disk-objects in as parameter.
> > 
> > If you don't mind efi_disk_obj definition being moved to, say, efi_loader.h,
> > I would follow your suggestion.
> 
> I don't think we need to move the definition, just the hint that the
> name exists.
> 
> If you add the following to efi_loader.h:
> 
>   struct efi_disk_obj;

> that should be enough to enable other subsystems (and APIs) to use
> pointers to that struct.

Ah, right. What we need to have in struct file_system is a *pointer*.
So such a declaration is good enough.

Thanks,
-Takahiro Akashi
> 
> 
> Alex

Patch

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 3bae1844befb..108ef3fe52ee 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -264,6 +264,10 @@  efi_status_t efi_disk_register(void);
 bool efi_disk_is_valid(efi_handle_t handle);
 /* Called by bootefi to find and update disk storage information */
 efi_status_t efi_disk_update(void);
+/* Called by file protocol to set internal block io device */
+int efi_disk_set_blk_dev(efi_handle_t disk);
+/* Called by file protocol to get disk/partition information */
+int efi_disk_get_info(efi_handle_t disk, disk_partition_t *part);
 /* Create handles and protocols for the partitions of a block device */
 int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc,
 			       const char *if_typename, int diskid,
@@ -355,7 +359,7 @@  void efi_signal_event(struct efi_event *event, bool check_tpl);
 
 /* open file system: */
 struct efi_simple_file_system_protocol *efi_simple_file_system(
-		struct blk_desc *desc, int part, struct efi_device_path *dp);
+		efi_handle_t disk);
 
 /* open file from device-path: */
 struct efi_file_handle *efi_file_from_path(struct efi_device_path *fp);
diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
index 0c4d79ee3fc9..180e8e10bb28 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -9,6 +9,7 @@ 
 #include <blk.h>
 #include <dm.h>
 #include <efi_loader.h>
+#include <fs.h>
 #include <part.h>
 #include <malloc.h>
 
@@ -254,6 +255,40 @@  efi_fs_from_path(struct efi_device_path *full_path)
 	return handler->protocol_interface;
 }
 
+/*
+ * Set block device for later block io's from file system protocol
+ *
+ * @disk	handle to uefi disk device
+ * @return	0 for success, -1 for failure
+ */
+int efi_disk_set_blk_dev(efi_handle_t disk)
+{
+	struct efi_disk_obj *diskobj;
+
+	diskobj = container_of(disk, struct efi_disk_obj, header);
+
+	return fs_set_blk_dev_with_part(diskobj->desc, diskobj->part);
+}
+
+/*
+ * Get disk/partition information
+ *
+ * @disk	handle to uefi disk device
+ * @part	pointer to disk/partition information to be returned
+ * @return	0 for success, -1 for failure
+ */
+int efi_disk_get_info(efi_handle_t disk, disk_partition_t *part)
+{
+	struct efi_disk_obj *diskobj;
+
+	diskobj = container_of(disk, struct efi_disk_obj, header);
+
+	if (diskobj->part >= 1)
+		return part_get_info(diskobj->desc, diskobj->part, part);
+	else
+		return part_get_info_whole_disk(diskobj->desc, part);
+}
+
 /*
  * Create a handle for a partition or disk
  *
@@ -308,8 +343,7 @@  static efi_status_t efi_disk_add_dev(
 	if (ret != EFI_SUCCESS)
 		return ret;
 	if (part >= 1) {
-		diskobj->volume = efi_simple_file_system(desc, part,
-							 diskobj->dp);
+		diskobj->volume = efi_simple_file_system(&diskobj->header);
 		ret = efi_add_protocol(&diskobj->header,
 				       &efi_simple_file_system_protocol_guid,
 				       diskobj->volume);
diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c
index beb4fba917d8..944383224f30 100644
--- a/lib/efi_loader/efi_file.c
+++ b/lib/efi_loader/efi_file.c
@@ -17,9 +17,7 @@  const efi_guid_t efi_file_system_info_guid = EFI_FILE_SYSTEM_INFO_GUID;
 
 struct file_system {
 	struct efi_simple_file_system_protocol base;
-	struct efi_device_path *dp;
-	struct blk_desc *desc;
-	int part;
+	efi_handle_t disk;
 };
 #define to_fs(x) container_of(x, struct file_system, base)
 
@@ -49,7 +47,10 @@  static char *basename(struct file_handle *fh)
 
 static int set_blk_dev(struct file_handle *fh)
 {
-	return fs_set_blk_dev_with_part(fh->fs->desc, fh->fs->part);
+	if (!efi_disk_is_valid(fh->fs->disk))
+		return -1;
+
+	return efi_disk_set_blk_dev(fh->fs->disk);
 }
 
 /**
@@ -570,10 +571,7 @@  static efi_status_t EFIAPI efi_file_getinfo(struct efi_file_handle *file,
 		efi_uintn_t required_size;
 		int r;
 
-		if (fh->fs->part >= 1)
-			r = part_get_info(fh->fs->desc, fh->fs->part, &part);
-		else
-			r = part_get_info_whole_disk(fh->fs->desc, &part);
+		r = efi_disk_get_info(fh->fs->disk, &part);
 		if (r < 0) {
 			ret = EFI_DEVICE_ERROR;
 			goto error;
@@ -694,17 +692,14 @@  efi_open_volume(struct efi_simple_file_system_protocol *this,
 }
 
 struct efi_simple_file_system_protocol *
-efi_simple_file_system(struct blk_desc *desc, int part,
-		       struct efi_device_path *dp)
+efi_simple_file_system(efi_handle_t disk)
 {
 	struct file_system *fs;
 
 	fs = calloc(1, sizeof(*fs));
 	fs->base.rev = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;
 	fs->base.open_volume = efi_open_volume;
-	fs->desc = desc;
-	fs->part = part;
-	fs->dp = dp;
+	fs->disk = disk;
 
 	return &fs->base;
 }