Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.50 KB | None | 0 0
  1.  static int efi_block_boot ( unsigned int drive, const char *filename ) {
  2.         EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
  3.         struct san_device *sandev;
  4. -       EFI_HANDLE *handles;
  5. +       EFI_HANDLE *handles, *blockhandles;
  6.         EFI_HANDLE image = NULL;
  7.         UINTN count;
  8.         unsigned int i;
  9. +       unsigned int index;
  10.         EFI_STATUS efirc;
  11.         int rc;
  12. -
  13. +       EFI_DEVICE_PATH *devpath;
  14. +       EFI_BLOCK_IO *blkio;
  15. +       EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *simplefs;
  16. +
  17.         /* Find SAN device */
  18.         sandev = sandev_find ( drive );
  19.         if ( ! sandev ) {
  20. +               efirc =  bs->LocateHandleBuffer (
  21. +                       ByProtocol, &efi_block_io_protocol_guid, NULL,
  22. +                       &count, &blockhandles);
  23. +
  24. +               index = 0;
  25. +               for(i=0; i < count; i++)
  26. +               {
  27. +                       efirc = bs->HandleProtocol(
  28. +                               blockhandles[i], &efi_device_path_protocol_guid,
  29. +                               (void**)&devpath);
  30. +
  31. +                       if (EFI_ERROR(efirc))
  32. +                               continue;
  33. +
  34. +                       efirc = bs->HandleProtocol(
  35. +                               blockhandles[i], &efi_block_io_protocol_guid,
  36. +                               (void**)&blkio);
  37. +
  38. +                       if (EFI_ERROR(efirc))
  39. +                               continue;
  40. +
  41. +                       if (!blkio->Media->LogicalPartition)
  42. +                               continue;
  43. +
  44. +                       efirc = bs->HandleProtocol(
  45. +                               blockhandles[i], &efi_simple_file_system_protocol_guid,
  46. +                               (void**)&simplefs);
  47. +
  48. +                       if (EFI_ERROR(efirc))
  49. +                               continue;
  50. +
  51. +                       // 0x80 = 128
  52. +                       if (index == drive - 128)
  53. +                       {
  54. +                               struct efi_block_data *block =
  55. +                                       container_of ( blkio, struct efi_block_data, block_io );
  56. +                               struct san_device localdev;
  57. +                               sandev = &localdev;
  58. +                               block->sandev = sandev;
  59. +                               block->path = devpath;
  60. +                               sandev->drive = drive;
  61. +                               sandev->priv = block;
  62. +
  63. +                               if ( ( rc = efi_block_boot_image ( sandev, blockhandles[i], filename,
  64. +                                                   &image ) ) != 0 )
  65. +                                       continue;
  66. +                               DBGC ( sandev, "EFIBLK %#02x found boot image\n",
  67. +                                      sandev->drive );
  68. +                               efirc = bs->StartImage ( image, NULL, NULL );
  69. +                                       rc = ( efirc ? -EEFI ( efirc ) : 0 );
  70. +                                       bs->UnloadImage ( image );
  71. +                               DBGC ( sandev, "EFIBLK %#02x boot image returned: %s\n",
  72. +                                      sandev->drive, strerror ( rc ) );
  73. +                               break;
  74. +                       }
  75. +                       else
  76. +                       {
  77. +                               index ++;
  78. +                       }
  79. +               }
  80. +
  81.                 DBG ( "EFIBLK cannot find drive %#02x\n", drive );
  82.                 rc = -ENODEV;
  83.                 goto err_sandev_find;
  84.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement