EfiLib/driver_support.c
VOID
ConnectFilesystemDriver(
    EFI_HANDLE DriverHandle
) {
    EFI_STATUS                            Status;
    UINTN                                 HandleCount = 0;
    UINTN                                 Index;
    UINTN                                 OpenInfoIndex;
    EFI_HANDLE                            *Handles = NULL;
    MY_EFI_SIMPLE_FILE_SYSTEM_PROTOCOL    *Fs;
    MY_EFI_BLOCK_IO_PROTOCOL              *BlockIo;
    EFI_OPEN_PROTOCOL_INFORMATION_ENTRY   *OpenInfo;
    UINTN                                 OpenInfoCount;
    EFI_HANDLE                            DriverHandleList[2];

    //
    // Get all DiskIo handles
    //
    Status = refit_call5_wrapper(
        gBS->LocateHandleBuffer,
        ByProtocol,
        &gMyEfiDiskIoProtocolGuid,
        NULL,
        &HandleCount,
        &Handles
    );
    if (EFI_ERROR(Status) || HandleCount == 0) {
        return;
    }

    //
    // Check every DiskIo handle
    //
    for (Index = 0; Index < HandleCount; Index++) {
        //
        // If this is not partition - skip it.
        // This is then whole disk and DiskIo
        // should be opened here BY_DRIVER by Partition driver
        // to produce partition volumes.
        //
        Status = refit_call3_wrapper(
            gBS->HandleProtocol,
            Handles[Index],
            &gMyEfiBlockIoProtocolGuid,
            (VOID **) &BlockIo
        );
        if (EFI_ERROR (Status)) {
            continue;
        }
        if (BlockIo->Media == NULL || !BlockIo->Media->LogicalPartition) {
            continue;
        }

        //
        // If SimpleFileSystem is already produced - skip it, this is ok
        //
        Status = refit_call3_wrapper(
            gBS->HandleProtocol,
            Handles[Index],
            &gMyEfiSimpleFileSystemProtocolGuid,
            (VOID **) &Fs
        );
        if (Status == EFI_SUCCESS) {
            continue;
        }

        //
        // If no SimpleFileSystem on this handle but DiskIo is opened BY_DRIVER
        // then disconnect this connection and try to connect our driver to it
        //
        Status = refit_call4_wrapper(
            gBS->OpenProtocolInformation,
            Handles[Index],
            &gMyEfiDiskIoProtocolGuid,
            &OpenInfo,
            &OpenInfoCount
        );
        if (EFI_ERROR (Status)) {
            continue;
        }

        DriverHandleList[1] = NULL;
        for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
            if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) == EFI_OPEN_PROTOCOL_BY_DRIVER) {
                Status = refit_call3_wrapper(
                    gBS->DisconnectController,
                    Handles[Index],
                    OpenInfo[OpenInfoIndex].AgentHandle,
                    NULL
                );
                if (!(EFI_ERROR(Status))) {
                    DriverHandleList[0] = DriverHandle;
                    refit_call4_wrapper(
                        gBS->ConnectController,
                        Handles[Index],
                        DriverHandleList,
                        NULL,
                        FALSE
                    );
                } // if
            } // if
        } // for
        FreePool (OpenInfo);
    }
    FreePool(Handles);
}
/**
 * Some UEFI's (like HPQ EFI from HP notebooks) have DiskIo protocols
 * opened BY_DRIVER (by Partition driver in HP case) even when no file system
 * is produced from this DiskIo. This then blocks our FS drivers from connecting
 * and producing file systems.
 * To fix it: we will disconnect drivers that connected to DiskIo BY_DRIVER
 * if this is partition volume and if those drivers did not produce file system,
 * then try to connect every unconnected device to the driver whose handle is
 * passed to us. This should have no effect on systems unaffected by this EFI
 * bug/quirk.
 */
Some UEFI's (like HPQ EFI from HP notebooks) have DiskIo protocols
opened BY_DRIVER (by Partition driver in HP case) even when no file system
is produced from this DiskIo. This then blocks our FS drivers from connecting
and producing file systems.
To fix it: we will disconnect drivers that connected to DiskIo BY_DRIVER
if this is partition volume and if those drivers did not produce file system,
then try to connect every unconnected device to the driver whose handle is
passed to us. This should have no effect on systems unaffected by this EFI
bug/quirk.
Some UEFI ' s ( like HPQ EFI from HP notebooks ) have DiskIo protocols opened BY_DRIVER ( by Partition driver in HP case ) even when no file system is produced from this DiskIo . This then blocks our FS drivers from connecting and producing file systems . To fix it : we will disconnect drivers that connected to DiskIo BY_DRIVER if this is partition volume and if those drivers did not produce file system then try to connect every unconnected device to the driver whose handle is passed to us . This should have no effect on systems unaffected by this EFI bug / quirk .
VOID
ConnectFilesystemDriver(
    EFI_HANDLE DriverHandle
) {
    EFI_STATUS                            Status;
    UINTN                                 HandleCount = 0;
    UINTN                                 Index;
    UINTN                                 OpenInfoIndex;
    EFI_HANDLE                            *Handles = NULL;
    MY_EFI_SIMPLE_FILE_SYSTEM_PROTOCOL    *Fs;
    MY_EFI_BLOCK_IO_PROTOCOL              *BlockIo;
    EFI_OPEN_PROTOCOL_INFORMATION_ENTRY   *OpenInfo;
    UINTN                                 OpenInfoCount;
    EFI_HANDLE                            DriverHandleList[2];
     Get all DiskIo handles
    Status = refit_call5_wrapper(
        gBS->LocateHandleBuffer,
        ByProtocol,
        &gMyEfiDiskIoProtocolGuid,
        NULL,
        &HandleCount,
        &Handles
    );
    if (EFI_ERROR(Status) || HandleCount == 0) {
        return;
    }
     Check every DiskIo handle
    for (Index = 0; Index < HandleCount; Index++) {
         If this is not partition - skip it.
         This is then whole disk and DiskIo
         should be opened here BY_DRIVER by Partition driver
         to produce partition volumes.
        Status = refit_call3_wrapper(
            gBS->HandleProtocol,
            Handles[Index],
            &gMyEfiBlockIoProtocolGuid,
            (VOID **) &BlockIo
        );
        if (EFI_ERROR (Status)) {
            continue;
        }
        if (BlockIo->Media == NULL || !BlockIo->Media->LogicalPartition) {
            continue;
        }
         If SimpleFileSystem is already produced - skip it, this is ok
        Status = refit_call3_wrapper(
            gBS->HandleProtocol,
            Handles[Index],
            &gMyEfiSimpleFileSystemProtocolGuid,
            (VOID **) &Fs
        );
        if (Status == EFI_SUCCESS) {
            continue;
        }
         If no SimpleFileSystem on this handle but DiskIo is opened BY_DRIVER
         then disconnect this connection and try to connect our driver to it
        Status = refit_call4_wrapper(
            gBS->OpenProtocolInformation,
            Handles[Index],
            &gMyEfiDiskIoProtocolGuid,
            &OpenInfo,
            &OpenInfoCount
        );
        if (EFI_ERROR (Status)) {
            continue;
        }
        DriverHandleList[1] = NULL;
        for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) {
            if ((OpenInfo[OpenInfoIndex].Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) == EFI_OPEN_PROTOCOL_BY_DRIVER) {
                Status = refit_call3_wrapper(
                    gBS->DisconnectController,
                    Handles[Index],
                    OpenInfo[OpenInfoIndex].AgentHandle,
                    NULL
                );
                if (!(EFI_ERROR(Status))) {
                    DriverHandleList[0] = DriverHandle;
                    refit_call4_wrapper(
                        gBS->ConnectController,
                        Handles[Index],
                        DriverHandleList,
                        NULL,
                        FALSE
                    );
                }  if
            }  if
        }  for
        FreePool (OpenInfo);
    }
    FreePool(Handles);
}
VOID ConnectFilesystemDriver ( EFI_HANDLE DriverHandle ) { EFI_STATUS Status ; UINTN HandleCount = 0 ; UINTN Index ; UINTN OpenInfoIndex ; EFI_HANDLE * Handles = NULL ; MY_EFI_SIMPLE_FILE_SYSTEM_PROTOCOL * Fs ; MY_EFI_BLOCK_IO_PROTOCOL * BlockIo ; EFI_OPEN_PROTOCOL_INFORMATION_ENTRY * OpenInfo ; UINTN OpenInfoCount ; EFI_HANDLE DriverHandleList [ 2 ] ; Status = refit_call5_wrapper ( gBS -> LocateHandleBuffer , ByProtocol , & gMyEfiDiskIoProtocolGuid , NULL , & HandleCount , & Handles ) ; if ( EFI_ERROR ( Status ) || HandleCount == 0 ) { return ; } for ( Index = 0 ; Index < HandleCount ; Index ++ ) { Status = refit_call3_wrapper ( gBS -> HandleProtocol , Handles [ Index ] , & gMyEfiBlockIoProtocolGuid , ( VOID * * ) & BlockIo ) ; if ( EFI_ERROR ( Status ) ) { continue ; } if ( BlockIo -> Media == NULL || ! BlockIo -> Media -> LogicalPartition ) { continue ; } Status = refit_call3_wrapper ( gBS -> HandleProtocol , Handles [ Index ] , & gMyEfiSimpleFileSystemProtocolGuid , ( VOID * * ) & Fs ) ; if ( Status == EFI_SUCCESS ) { continue ; } Status = refit_call4_wrapper ( gBS -> OpenProtocolInformation , Handles [ Index ] , & gMyEfiDiskIoProtocolGuid , & OpenInfo , & OpenInfoCount ) ; if ( EFI_ERROR ( Status ) ) { continue ; } DriverHandleList [ 1 ] = NULL ; for ( OpenInfoIndex = 0 ; OpenInfoIndex < OpenInfoCount ; OpenInfoIndex ++ ) { if ( ( OpenInfo [ OpenInfoIndex ] . Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER ) == EFI_OPEN_PROTOCOL_BY_DRIVER ) { Status = refit_call3_wrapper ( gBS -> DisconnectController , Handles [ Index ] , OpenInfo [ OpenInfoIndex ] . AgentHandle , NULL ) ; if ( ! ( EFI_ERROR ( Status ) ) ) { DriverHandleList [ 0 ] = DriverHandle ; refit_call4_wrapper ( gBS -> ConnectController , Handles [ Index ] , DriverHandleList , NULL , FALSE ) ; } } } FreePool ( OpenInfo ) ; } FreePool ( Handles ) ; }
Some UEFI's (like HPQ EFI from HP notebooks) have DiskIo protocols
 opened BY_DRIVER (by Partition driver in HP case) even when no file system
 is produced from this DiskIo.
Some UEFI ' s ( like HPQ EFI from HP notebooks ) have DiskIo protocols opened BY_DRIVER ( by Partition driver in HP case ) even when no file system is produced from this DiskIo .
// // Get all DiskIo handles // // // Check every DiskIo handle // // // If this is not partition - skip it. // This is then whole disk and DiskIo // should be opened here BY_DRIVER by Partition driver // to produce partition volumes. // // // If SimpleFileSystem is already produced - skip it, this is ok // // // If no SimpleFileSystem on this handle but DiskIo is opened BY_DRIVER // then disconnect this connection and try to connect our driver to it // // if // if // for