コード例 #1
0
// TODO: remove duplicated code on DriveEnumerateAta and DriveEnumerateScsi
std::shared_ptr<IDrive> cDriveEnumeratorAta::EnumerateDrive(const std::shared_ptr<IDevice>& Device)
{
    DeviceHandle deviceHandle;
    eErrorCode errorCode;

    try
    {
        deviceHandle = Device->Handle();
    }
    catch (std::exception ex)
    {
        //fprintf(stderr, "\nEnumerateDrive was not successful. Exception:%s.", ex.what());
        //TODO: handle error
        return( nullptr );
    }

    sStorageAdapterProperty storageAdapterProperty;
    errorCode = GetStorageAdapterProperty( deviceHandle, storageAdapterProperty );

    if ( eErrorCode::None != errorCode )
    {
        //TODO: handle error
        return( nullptr );
    }

    U32 physicalDiskNumber;
    errorCode = GetPhysicalDiskNumber(deviceHandle, physicalDiskNumber);
    if (eErrorCode::None != errorCode)
    {
        //TODO: handle error
        return(nullptr);
    }

    tchar* devicePath;
    Device->DevicePath(devicePath);

    // Add drive propeties to the container
    std::shared_ptr<vtStor::sDriveProperties> driveProperties = std::make_shared<vtStor::sDriveProperties>();
    driveProperties->PhysicalDiskNumber = physicalDiskNumber;
    driveProperties->DevicePath = devicePath;

    if ( true == IsAtaDeviceBus( storageAdapterProperty ) )
    {
        std::shared_ptr<IDrive> drive = std::make_shared<cDriveAta>(Device, deviceHandle, driveProperties);

        return( drive );
    }

    return( nullptr );
}
コード例 #2
0
eErrorCode cDriveEnumeratorAta::EnumerateDrives( Vector_Drives& AddToList, U32& Count )
{
    Count = 0;

    std::vector<String> devicePaths;
    vtStor::GetStorageDevicePaths( devicePaths, eOnErrorBehavior::Continue );

    DeviceHandle deviceHandle;
    eErrorCode errorCode;
    for ( const auto& devicePath : devicePaths )
    {
        errorCode = GetStorageDeviceHandle( devicePath, deviceHandle );
        if ( eErrorCode::None != errorCode )
        {
            //TODO: handle error
            continue;
        }

        sStorageAdapterProperty storageAdapterProperty;
        errorCode = GetStorageAdapterProperty( deviceHandle, storageAdapterProperty );
        if ( eErrorCode::None != errorCode )
        {
            CloseHandle(deviceHandle);
            //TODO: handle error
            continue;
        }

        if ( true == IsAtaDeviceBus( storageAdapterProperty ) )
        {
            std::shared_ptr<cDriveInterface> drive = std::make_shared<cDriveAta>(std::make_shared<String>(devicePath));

            AddToList.push_back( drive );
            ++Count;
        }
    }

    return( eErrorCode::None );
}