/* This function opens a file with the open mode according to the file path. The Attributes is valid only for EFI_FILE_MODE_CREATE. */
EFI_STATUS EFIAPI ShellOpenFileByDevicePath(IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath, OUT SHELL_FILE_HANDLE *FileHandle, IN UINT64 OpenMode, IN UINT64 Attributes)
/* This function opens a file with the open mode according to the file path. The Attributes is valid only for EFI_FILE_MODE_CREATE. */
EFI_STATUS EFIAPI ShellOpenFileByDevicePath(IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath, OUT SHELL_FILE_HANDLE *FileHandle, IN UINT64 OpenMode, IN UINT64 Attributes)
{
  CHAR16             *FileName;
  EFI_STATUS         Status;
  EFI_FILE_PROTOCOL  *File;
  if ((FilePath == NULL) || (FileHandle == NULL)) {
    return (EFI_INVALID_PARAMETER);
  }
  if (gEfiShellProtocol != NULL) {
    FileName = gEfiShellProtocol->GetFilePathFromDevicePath (*FilePath);
    if (FileName == NULL) {
      return (EFI_INVALID_PARAMETER);
    }
    Status = ShellOpenFileByName (FileName, FileHandle, OpenMode, Attributes);
    FreePool (FileName);
    return (Status);
  }
  Status = EfiOpenFileByDevicePath (FilePath, &File, OpenMode, Attributes);
  if (EFI_ERROR (Status)) {
    return Status;
  }
  *FileHandle = (VOID *)File;
  return (EFI_SUCCESS);
}