public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: GN Keshava <keshava.gn@gmail.com>
Cc: "edk2-devel@lists.01.org" <edk2-devel@ml01.01.org>
Subject: Re: How to open a file by it's full path in UEFI
Date: Tue, 27 Sep 2016 11:49:13 +0200	[thread overview]
Message-ID: <765021a6-cea7-ba5f-58cf-5e8fce05bbf2@redhat.com> (raw)
In-Reply-To: <CABKwMdsVK_xpU_ktrPNgP2uc_aKQvVZK=zQnraS21q5LA6O1GA@mail.gmail.com>

On 09/27/16 11:25, GN Keshava wrote:
> Hi Laszlo,
> 
> Thanks for the reply. I meant I have complete file path. I believe the
> "device path" is different. Is it possible to obtain DevicePath using my
> full file path?

The pathname you seem to have (as "complete") is specific to a given
simple FS, so system-wide it cannot be considered complete (there can be
multiple filesystems).

In your original email I missed that you started with "FS1:". Andrew's
answer covers that case.

In summary, you can do three things:
- have a pathname that starts with FSx: (which is a shell-specific
mapping), and use Andrew's recommendation,
- have a complete UEFI device path, and then use what I recommended,
- have no information for selecting the filesystem (from the many
possible), and use your current iteration.

Options #1 and #2 actually correspond to each other, considering
"expressive power" / information content (as long as you are in the
shell); please see the MAP shell command.

Thanks
Laszlo

> On Tue, 27 Sep 2016 at 14:46 Laszlo Ersek <lersek@redhat.com
> <mailto:lersek@redhat.com>> wrote:
> 
>     On 09/27/16 11:03, GN Keshava wrote:
>     > Hi all,
>     >
>     >
>     > I'm trying to open a file from my UEFI application. The path of
>     file is
>     >
>     > fs1:/myfolder/myfile.txt
>     >
>     > The code :
>     >
>     > efiStatus = bs->LocateHandleBuffer(ByProtocol,
>     >                                    &sfspGuid,
>     >                                    NULL,
>     >                                    &handleCount,
>     >                                    &handles);
>     >
>     > for (index = 0; index < (int)handleCount; ++ index)
>     > {
>     >     EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* fs = NULL;
>     >
>     >     efiStatus = bs->HandleProtocol(
>     >         handles[index],
>     >         &sfspGuid,
>     >         (void**)&fs);
>     >
>     >     EFI_FILE_PROTOCOL* root = NULL;
>     >     ...
>     >     efiStatus = fs->OpenVolume(fs, &root);
>     >
>     >     EFI_FILE_PROTOCOL* token = NULL;
>     >
>     >     efiStatus = root->Open(
>     >         root,
>     >         &token,
>     >         L"myfolder\\myfile.txt",
>     >         EFI_FILE_MODE_READ,
>     >         EFI_FILE_READ_ONLY | EFI_FILE_HIDDEN | EFI_FILE_SYSTEM);
>     > }
>     >
>     > But using this method, I can only go through all the file system
>     handles
>     > and open each volume and try opening my file.
>     >
>     > But I want to give full path to my file and open it in it's volume.
>     >
>     > How can I acheive this?
>     > Thanks.
> 
>     If you have a complete device path, you can use gBS->LocateDevicePath()
>     with gEfiSimpleFileSystemProtocolGuid, to locate the handle with the
>     most specific device path (--> the longest device path prefix) with the
>     simple FS protocol installed on it. Then you can check if the remaining
>     device path (returned by the service) consist of nothing but one File
>     Path Media Device Path node. If so, you can open the simple FS protocol
>     on the handle found, then use that to open the file by pathname.
> 
>     Laszlo
> 



  reply	other threads:[~2016-09-27  9:49 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-27  9:03 How to open a file by it's full path in UEFI GN Keshava
2016-09-27  9:07 ` Andrew Fish
2016-09-27  9:28   ` GN Keshava
2016-09-27  9:16 ` Laszlo Ersek
2016-09-27  9:25   ` GN Keshava
2016-09-27  9:49     ` Laszlo Ersek [this message]
2016-09-27 10:46       ` GN Keshava
2016-09-27 11:17         ` Laszlo Ersek
2016-09-27 11:51           ` GN Keshava
2016-09-27 15:07             ` Carsey, Jaben
2016-09-27 15:13               ` Laszlo Ersek
2016-09-27 16:44             ` Jarlstrom, Laurie
2016-09-27 16:48               ` Andrew Fish
2016-09-27 16:56                 ` GN Keshava
2016-09-29 10:22               ` GN Keshava

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=765021a6-cea7-ba5f-58cf-5e8fce05bbf2@redhat.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox