How to open a file by it's full path in UEFI
<p>I'm a beginner in UEFI. I'm trying to open a file from my UEFI application. The path of file is</p>

<pre><code>fs1:/myfolder/myfile.txt
</code></pre>

<p>The code <em>(With the help of <a href="https://stackoverflow.com/a/32382199/2006333">this answer</a>)</em> :</p>

<pre><code>efiStatus = bs-&gt;LocateHandleBuffer(ByProtocol, 
                                   &amp;sfspGuid, 
                                   NULL, 
                                   &amp;handleCount, 
                                   &amp;handles);

for (index = 0; index &lt; (int)handleCount; ++ index)
{
    EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* fs = NULL;

    efiStatus = bs-&gt;HandleProtocol(
        handles[index],
        &amp;sfspGuid,
        (void**)&amp;fs);

    EFI_FILE_PROTOCOL* root = NULL;
    ...
    efiStatus = fs-&gt;OpenVolume(fs, &amp;root);

    EFI_FILE_PROTOCOL* token = NULL;

    efiStatus = root-&gt;Open(
        root, 
        &amp;token,
        L"myfolder\\myfile.txt",
        EFI_FILE_MODE_READ,
        EFI_FILE_READ_ONLY | EFI_FILE_HIDDEN | EFI_FILE_SYSTEM);
}
</code></pre>

<p>But using this method, I can only go through all the file system handles and open each volume and try opening my file.</p>

<p>But I want to give full path to my file and open it in it's volume.</p>

<p>How can I acheive this?</p>

<hr>

<p><strong>EDIT:</strong></p>

<p>I tried using Shell APIs for opening the file as suggested by @Alex in comments.
Below is the code. But it hangs in function <code>OpenFileByName</code> .</p>

<p>What is the mistake in this code? (argv[ 1 ] would be my file path <code>fs1:\myfile.txt</code> )</p>

<pre><code>EFI_STATUS
EFIAPI
main (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{

    EFI_STATUS      status;
    UINTN           argc;
    CHAR16          **argv;
    SHELL_FILE_HANDLE Handle;

    status = get_args(&amp;argc, &amp;argv);
    if (EFI_ERROR(status)) {
       Print(L"ERROR: Parsing command line arguments: %d\n", status);
       return status;
    }

    if (argc &lt;= 1){
        Print(L"No file name to open\n");
        return (EFI_UNSUPPORTED);  //need to have at least one parameter
    }

    Print(L"File to open is: %s\n", argv[1]);

    status = gEfiShellProtocol-&gt;OpenFileByName (argv[1], &amp;Handle, 
        EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE);

    if (EFI_ERROR(status)) {
        Print(L"\nFile Open did not work %s\n", argv[1]);
        return (status);
    }else{
        Print(L"\nFile Open worked %s\n", argv[1]);
        gEfiShellProtocol-&gt;CloseFile(Handle);
    }

    return EFI_SUCCESS;
}
</code></pre>

<p>And the code hangs even if I try <code>GetCurDir</code> function.</p>

<pre><code>Print(L"Dir: %s \n",gEfiShellProtocol-&gt;GetCurDir(NULL));
</code></pre>

<p>Any pointers would be helpful.</p>