title: Can't get file using "GetSectionFromAnyFv" or going over all files using firmware volume protocol->GetNextFile
body: <p>I donwloaded BIOS rom and get list of files using UEFITool:
  <a href="https://i.stack.imgur.com/pFRGc.gif" rel="nofollow noreferrer">ROM Structure</a></p>
  <p>So i know &quot;names&quot; of all files that exist. Then i tried to get file using &quot;GetSectionFromAnyFv&quot; but can't get all files, just files in volume <a href="https://i.stack.imgur.com/Kb4Rw.gif" rel="nofollow noreferrer">under red arrow</a>. For example volume <a href="https://i.stack.imgur.com/Kb4Rw.gif" rel="nofollow noreferrer">under violet arrow</a> also have files, but i can't get it.</p>
  <p>LocateHandleBuffer (ByProtocol, &amp;gEfiFirmwareVolume2ProtocolGuid, NULL, &amp;NumberOfHandles, &amp;HandleBuffer) return only 1 handle [NumberOfHandles = 1], but as i can see there are more than 1 volume.</p>
  <p>Same if i try get file using for(for NumberOfHandles) and iterate over all files getting guids. Just can't get all files.</p>
  <p>What could be the problem?
  P.S.: ProcessFirmwareVolume for every FV2 HOBs return 20 so that means that &quot;firmware volume block protocol&quot; is alredy processed.</p>
  <pre><code>#include &quot;FileByGuid.h&quot;
  
  EFI_GUID TextToGuid(CHAR16* stGUID)
  {
      EFI_GUID NameGuid;
  
      stGUID[8] = '\0';
      stGUID[13] = '\0';
      stGUID[18] = '\0';
      NameGuid.Data1 = (UINT32)StrHexToUintn(&amp;stGUID[0]);
      NameGuid.Data2 = (UINT16)StrHexToUintn(&amp;stGUID[9]);
      NameGuid.Data3 = (UINT16)StrHexToUintn(&amp;stGUID[14]);
  
      for (int i = 23; i &lt; 37; i++)
      {
          Print(L&quot;&quot;);
          stGUID[i] = stGUID[i + 1];
      }
  
      UINTN D4 = StrHexToUintn(&amp;stGUID[19]);
      for (int i = 7; i &gt;= 0; i--)
      {
          NameGuid.Data4[i] = (UINT8)(D4 &amp; 0xFF);
          D4 = D4 &gt;&gt; 8;
      }
      return NameGuid;
  }
  
  EFI_STATUS
  EFIAPI
  FileByGuidDriverEntryPoint(
      IN EFI_HANDLE        ImageHandle,
      IN EFI_SYSTEM_TABLE* SystemTable
  )
  {
      EFI_FIRMWARE_VOLUME2_PROTOCOL* fv;
      EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* fs;
      EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL* fvb;
      EFI_DEVICE_PATH_PROTOCOL* dp;
      EFI_BLOCK_IO2_PROTOCOL* bio;
      EFI_BLOCK_IO_PROTOCOL* bio2;
  
      EFI_FILE_PROTOCOL       *OpenedFileHandle;
      EFI_FILE_HANDLE         Root;
      EFI_STATUS              Status, GetSectionStatus;
      UINTN                   index;
      EFI_HANDLE              *sfsHandleBuffer = NULL;
      EFI_HANDLE              *fvHandleBuffer = NULL;
      EFI_HANDLE              *fvbHandleBuffer = NULL;
      EFI_HANDLE* bioHandleBuffer = NULL;
      EFI_HANDLE* bio2HandleBuffer = NULL;
      EFI_HANDLE              FvProtocolHandle;
      UINTN                   sfsHandleCount = 0;
      UINTN                   fvHandleCount = 0;
      UINTN                   fvbHandleCount = 0;
      UINTN                   bioHandleCount = 0;
      UINTN                   bio2HandleCount = 0;
      UINTN                   Size;
      EFI_FV_FILETYPE         FileType;
      UINTN                   counter = 0;
      VOID                    *Buffer;
      VOID                    *Key;
      EFI_GUID                fvNameGuid;
      EFI_GUID                NameGuid;
      CHAR16* stGUID = L&quot;114CA60C-D965-4C13-BEF7-C4062248E1FA&quot;;
  //  UINTN                   EventIndex;
  //  EFI_INPUT_KEY               Keys;
      EFI_FV_FILE_ATTRIBUTES  Attributes;
      EFI_FIRMWARE_VOLUME_HEADER  *FirmwareVolumeHeader;
      EFI_PEI_HOB_POINTERS    Hob;
  //  BOOLEAN MediaPresent;
  //  PARTITION_DETECT_ROUTINE* Routine;
  //  BOOLEAN MediaPresent;
  //  EFI_DISK_IO_PROTOCOL* DiskIo;
  //  EFI_DISK_IO2_PROTOCOL* DiskIo2;
  
      gBS-&gt;SetWatchdogTimer(0, 0, 0, NULL);
      gST = SystemTable;
  
  
      Status = gBS-&gt;LocateHandleBuffer(ByProtocol, &amp;gEfiFirmwareVolumeBlock2ProtocolGuid, NULL, &amp;fvbHandleCount, &amp;fvbHandleBuffer);
      AsciiPrint(&quot;\r\nfv2_block_HandleCount: %d\r\n&quot;, fvbHandleCount);
      for (index = 0; index &lt; (int)fvbHandleCount; index++)
      {
          //Status = gBS-&gt;OpenProtocol(fvbHandleBuffer[index], &amp;gEfiFirmwareVolumeBlock2ProtocolGuid, (VOID**)&amp;fvb, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
          Status = gBS-&gt;HandleProtocol(fvbHandleBuffer[index], &amp;gEfiFirmwareVolume2ProtocolGuid, &amp;fvb);
          AsciiPrint(&quot;-HP fv_block fv2 Status: %d; DevicePath: %s\r\n&quot;, Status, ConvertDevicePathToText(DevicePathFromHandle(fvbHandleBuffer[index]), TRUE, TRUE));
      }
  
      Status = gBS-&gt;LocateHandleBuffer(ByProtocol, &amp;gEfiSimpleFileSystemProtocolGuid, NULL, &amp;sfsHandleCount, &amp;sfsHandleBuffer);
      AsciiPrint(&quot;\r\nsfsHandleCount: %d\r\n&quot;, sfsHandleCount);
      for (index = 0; index &lt; (int)sfsHandleCount; index++)
          AsciiPrint(&quot;-sfs[%d] handle: %d; device path: %s\r\n&quot;, index, sfsHandleBuffer[index], ConvertDevicePathToText(DevicePathFromHandle(sfsHandleBuffer[index]), TRUE, TRUE));
      
      Status = gBS-&gt;LocateHandleBuffer(ByProtocol, &amp;gEfiDevicePathProtocolGuid, NULL, &amp;sfsHandleCount, &amp;sfsHandleBuffer);
      AsciiPrint(&quot;\r\nDevicePathHandleCount: %d\r\n&quot;, sfsHandleCount);
      //for (index = 0; index &lt; (int)sfsHandleCount; index++)
      //  AsciiPrint(&quot;dp[%d] device path: %s\r\n&quot;, index, ConvertDevicePathToText(DevicePathFromHandle(sfsHandleBuffer[index]), TRUE, TRUE));
  
      AsciiPrint(&quot;\r\nHOB:\r\n&quot;);
      for (Hob.Raw = GetHobList(); !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) 
      {
          if (GET_HOB_TYPE(Hob) == EFI_HOB_TYPE_FV2   || GET_HOB_TYPE(Hob) == EFI_HOB_TYPE_FV || GET_HOB_TYPE(Hob) == EFI_HOB_TYPE_FV3)
          {
              FvProtocolHandle = NULL;
  
              FirmwareVolumeHeader = (EFI_FIRMWARE_VOLUME_HEADER*)(UINTN)(Hob.FirmwareVolume-&gt;BaseAddress);
              Status = gDS-&gt;ProcessFirmwareVolume(FirmwareVolumeHeader, Hob.FirmwareVolume2-&gt;Length, &amp;FvProtocolHandle);
  
              if (GET_HOB_TYPE(Hob) == EFI_HOB_TYPE_FV3)
                  AsciiPrint(&quot;-FV3: Status: %d; FvProtocolHandle: %d; Extracted?:%d; AuthenStatus:%d;\r\n GUID:%g\r\n&quot;, Status, FvProtocolHandle, Hob.FirmwareVolume3-&gt;ExtractedFv, Hob.FirmwareVolume3-&gt;AuthenticationStatus, Hob.FirmwareVolume3-&gt;FvName);
              else if (GET_HOB_TYPE(Hob) == EFI_HOB_TYPE_FV2)
                  AsciiPrint(&quot;-FV2: Status: %d; FvProtocolHandle: %d; FileName: %g; \r\n GUID:%g\r\n&quot;, Status, FvProtocolHandle, Hob.FirmwareVolume2-&gt;FileName, Hob.FirmwareVolume2-&gt;FvName);
              else
                  AsciiPrint(&quot;-FV:  Status: %d; FvProtocolHandle: %d\r\n&quot;, Status, FvProtocolHandle);
          }
      }
      AsciiPrint(&quot;End HOB\r\n&quot;);
  
      Status = gBS-&gt;LocateHandleBuffer(ByProtocol, &amp;gEfiFirmwareVolume2ProtocolGuid, NULL, &amp;fvHandleCount, &amp;fvHandleBuffer);
      AsciiPrint(&quot;\r\nfv2HandleCount: %d\r\n&quot;, fvHandleCount);
      for (index = 0; index &lt; (int) fvHandleCount; index++)
      {
          Status = gBS-&gt;HandleProtocol(fvHandleBuffer[index], &amp;gEfiFirmwareVolume2ProtocolGuid, (VOID**) &amp;fv);
          AsciiPrint(&quot;-index: %d; HPfvStatus: %d; DevicePath: %s\r\n&quot;, index, Status, ConvertDevicePathToText(DevicePathFromHandle(fvbHandleBuffer[index]), TRUE, TRUE));
          if (EFI_ERROR(Status))
              continue;
  
          FileType = EFI_FV_FILETYPE_ALL;
          Key = AllocatePool(fv-&gt;KeySize);
          ZeroMem(Key, fv-&gt;KeySize);
  
          Status = fv-&gt;GetNextFile(fv, Key, &amp;FileType, &amp;fvNameGuid, &amp;Attributes, &amp;Size);
          while (Status!= EFI_NOT_FOUND)
          {
              FileType = EFI_FV_FILETYPE_ALL;
              counter++;
              //if (counter % 15 == 0)
              //  AsciiPrint(&quot;Status: %d;  __file_GUID:%g\r\n&quot;, Status, fvNameGuid);
              Status = fv-&gt;GetNextFile(fv, Key, &amp;FileType, &amp;fvNameGuid, &amp;Attributes, &amp;Size);
          }
  
          AsciiPrint(&quot;sectionFilesCount: %d\r\n&quot;, counter);
          counter = 0;
          FreePool(Key);
      }
      
      NameGuid = TextToGuid(stGUID);
      //AsciiPrint(&quot;\r\n%g\r\n&quot;, NameGuid);
  
      GetSectionStatus = GetSectionFromAnyFv(&amp;NameGuid, EFI_SECTION_ALL, 0, (VOID**)&amp;Buffer, &amp;Size);
      AsciiPrint(&quot;GetSectionFromAnyFvStatus = %d\r\n&quot;, Status);
  
  
  
      Status = gBS-&gt;LocateHandleBuffer(ByProtocol, &amp;gEfiBlockIoProtocolGuid, NULL, &amp;bioHandleCount, &amp;bioHandleBuffer);
      AsciiPrint(&quot;\r\nbioHandleCount: %d\r\n&quot;, bioHandleCount);
      for (index = 0; index &lt; (int)bioHandleCount; index++)
      {
          Status = gBS-&gt;HandleProtocol(bioHandleBuffer[index], &amp;gEfiBlockIoProtocolGuid, &amp;bio);
  
          dp = DevicePathFromHandle(bioHandleBuffer[index]);
          while (!IsDevicePathEnd(NextDevicePathNode(dp)))
              dp = NextDevicePathNode(dp);
  
          AsciiPrint(&quot;-HP BlockIO Status: %d; handle: %d; DevicePath: %s\r\n&quot;, Status, bioHandleBuffer[index], ConvertDevicePathToText(dp, TRUE, TRUE));
          AsciiPrint(&quot;--MediaPresent: %d; RemovableMedia: %d; LogicalPartition: %d\r\n&quot;, bio-&gt;Media-&gt;MediaPresent, bio-&gt;Media-&gt;RemovableMedia, bio-&gt;Media-&gt;LogicalPartition);
      }
  
      Status = gBS-&gt;LocateHandleBuffer(ByProtocol, &amp;gEfiBlockIo2ProtocolGuid, NULL, &amp;bio2HandleCount, &amp;bio2HandleBuffer);
      AsciiPrint(&quot;\r\nbio2HandleCount: %d\r\n&quot;, bio2HandleCount);
      for (index = 0; index &lt; (int)bio2HandleCount; index++)
      {
          Status = gBS-&gt;HandleProtocol(bio2HandleBuffer[index], &amp;gEfiBlockIo2ProtocolGuid, &amp;bio2);
  
          dp = DevicePathFromHandle(bio2HandleBuffer[index]);
          while (!IsDevicePathEnd(NextDevicePathNode(dp)))
              dp = NextDevicePathNode(dp);
  
          AsciiPrint(&quot;-HP BlockIO2 Status: %d; handle: %d; DevicePath: %s\r\n&quot;, Status, bio2HandleBuffer[index], ConvertDevicePathToText(dp, TRUE, TRUE));
          AsciiPrint(&quot;--MediaPresent: %d; RemovableMedia: %d; LogicalPartition: %d\r\n&quot;, bio2-&gt;Media-&gt;MediaPresent, bio2-&gt;Media-&gt;RemovableMedia, bio2-&gt;Media-&gt;LogicalPartition);
      }
  
  
      AsciiPrint(&quot;\r\n&quot;);
      //save
      if (!EFI_ERROR(GetSectionStatus))
      {
          Status = gBS-&gt;LocateHandleBuffer(ByProtocol, &amp;gEfiSimpleFileSystemProtocolGuid, NULL, &amp;sfsHandleCount, &amp;sfsHandleBuffer);
          for (index = 0; index &lt; (int)sfsHandleCount; index++)
          {
              fs = NULL;
              OpenedFileHandle = NULL;
              Root = NULL;
  
              Status = gBS-&gt;HandleProtocol(sfsHandleBuffer[index], &amp;gEfiSimpleFileSystemProtocolGuid, (VOID**)&amp;fs);
              if (EFI_ERROR(Status))
                  continue;
  
              Status = fs-&gt;OpenVolume(fs, &amp;Root);
              Status = Root-&gt;Open(Root, &amp;OpenedFileHandle, L&quot;EFI\\Boot&quot;, EFI_FILE_MODE_READ, 0);
              if (EFI_ERROR(Status))
                  continue;
  
              Status = Root-&gt;Open(Root, &amp;OpenedFileHandle, L&quot;file&quot;, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, 0);
  
              if (!EFI_ERROR(Status)) //уже существует
                  Root-&gt;Delete(OpenedFileHandle);
  
              Status = Root-&gt;Open(Root, &amp;OpenedFileHandle, L&quot;file&quot;, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0);
  
              if (!EFI_ERROR(Status))
              {
                  Status = Root-&gt;Write(OpenedFileHandle, &amp;Size, Buffer);
                  AsciiPrint(&quot;WriteSt:%d; DevicePath:%s\r\n&quot;, Status, ConvertDevicePathToText(DevicePathFromHandle(sfsHandleBuffer[index]), TRUE, TRUE));
              }
              Status = Root-&gt;Close(OpenedFileHandle);
          }
      }
  
      if (Buffer != NULL)
          FreePool(Buffer);
  
      return EFI_SUCCESS;
  }
  
  </code></pre>
  <ol>
  <li>Getting all handles that support FV2 protocol;</li>
  <li>Processing all HOBs so number of handles that support FV2 protocol may increase;</li>
  <li>For FV2 protocol i get count of handles and then get Volume names (device path for handle that support FV2 protocol) and files count: Here i can see that not all volumes are processd;</li>
  <li>GetSectionFromAnyFv(*) then not interresting part and last saving file using simple file system protocol.</li>
  </ol>