Пример #1
0
eErrorCode GetAdapterBus(DeviceHandle& Handle, String SysDevicePath)
{
    struct udev *udevObject;
    struct udev_device *udevDevice;

    udevObject = udev_new();
    if (nullptr == udevObject)
    {
        return(eErrorCode::Memory);
    }
    udevDevice = udev_device_new_from_syspath(udevObject, SysDevicePath.c_str());

    if (true == IsAtaDeviceBus(udevDevice))
    {
        Handle.Bus = eBusType::Ata;
    }
    else if (true == IsScsiDeviceBus(udevDevice))
    {
        Handle.Bus = eBusType::Scsi;
    }
    else
    {
        //! Adapter Property is not Ata or Scsi
        return(eErrorCode::FormatNotSupported);
    }

    udev_device_unref(udevDevice);
    udev_unref(udevObject);

    return(eErrorCode::None);
}
Пример #2
0
bool IsStorageDisk(udev_device* UdevDevice)
{
    const char* udevDeviceType = udev_device_get_devtype(UdevDevice);
    if (0 == strcmp(udevDeviceType, "disk"))
    {
        if (true == IsAtaDeviceBus(UdevDevice) || true == IsScsiDeviceBus(UdevDevice))
        {
            return true;
        }
    }
    return false;
}
Пример #3
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 );
}
Пример #4
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 );
}