Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int efi_block_boot ( unsigned int drive, const char *filename ) {
- EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
- struct san_device *sandev;
- - EFI_HANDLE *handles;
- + EFI_HANDLE *handles, *blockhandles;
- EFI_HANDLE image = NULL;
- UINTN count;
- unsigned int i;
- + unsigned int index;
- EFI_STATUS efirc;
- int rc;
- -
- + EFI_DEVICE_PATH *devpath;
- + EFI_BLOCK_IO *blkio;
- + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *simplefs;
- +
- /* Find SAN device */
- sandev = sandev_find ( drive );
- if ( ! sandev ) {
- + efirc = bs->LocateHandleBuffer (
- + ByProtocol, &efi_block_io_protocol_guid, NULL,
- + &count, &blockhandles);
- +
- + index = 0;
- + for(i=0; i < count; i++)
- + {
- + efirc = bs->HandleProtocol(
- + blockhandles[i], &efi_device_path_protocol_guid,
- + (void**)&devpath);
- +
- + if (EFI_ERROR(efirc))
- + continue;
- +
- + efirc = bs->HandleProtocol(
- + blockhandles[i], &efi_block_io_protocol_guid,
- + (void**)&blkio);
- +
- + if (EFI_ERROR(efirc))
- + continue;
- +
- + if (!blkio->Media->LogicalPartition)
- + continue;
- +
- + efirc = bs->HandleProtocol(
- + blockhandles[i], &efi_simple_file_system_protocol_guid,
- + (void**)&simplefs);
- +
- + if (EFI_ERROR(efirc))
- + continue;
- +
- + // 0x80 = 128
- + if (index == drive - 128)
- + {
- + struct efi_block_data *block =
- + container_of ( blkio, struct efi_block_data, block_io );
- + struct san_device localdev;
- + sandev = &localdev;
- + block->sandev = sandev;
- + block->path = devpath;
- + sandev->drive = drive;
- + sandev->priv = block;
- +
- + if ( ( rc = efi_block_boot_image ( sandev, blockhandles[i], filename,
- + &image ) ) != 0 )
- + continue;
- + DBGC ( sandev, "EFIBLK %#02x found boot image\n",
- + sandev->drive );
- + efirc = bs->StartImage ( image, NULL, NULL );
- + rc = ( efirc ? -EEFI ( efirc ) : 0 );
- + bs->UnloadImage ( image );
- + DBGC ( sandev, "EFIBLK %#02x boot image returned: %s\n",
- + sandev->drive, strerror ( rc ) );
- + break;
- + }
- + else
- + {
- + index ++;
- + }
- + }
- +
- DBG ( "EFIBLK cannot find drive %#02x\n", drive );
- rc = -ENODEV;
- goto err_sandev_find;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement