コード例 #1
0
void
PartitionCoreModule::init()
{
    CoreBackend* backend = CoreBackendManager::self()->backend();
    auto devices = backend->scanDevices();

    // Remove the device which contains / from the list
    for ( auto it = devices.begin(); it != devices.end(); )
        if ( hasRootPartition( *it ) )
            it = devices.erase( it );
        else
            ++it;

    for ( auto device : devices )
    {
        auto deviceInfo = new DeviceInfo( device );
        m_deviceInfos << deviceInfo;

        deviceInfo->partitionModel->init( device );
    }
    m_deviceModel->init( devices );

    m_bootLoaderModel->init( devices );

    if ( QDir( "/sys/firmware/efi/efivars" ).exists() )
        scanForEfiSystemPartitions(); //FIXME: this should be removed in favor of
                                      //       proper KPM support for EFI
}
コード例 #2
0
void
PartitionCoreModule::init()
{
    CoreBackend* backend = CoreBackendManager::self()->backend();
    auto devices = backend->scanDevices( true );

    // Remove the device which contains / from the list
    for ( auto it = devices.begin(); it != devices.end(); )
        if ( hasRootPartition( *it ) )
            it = devices.erase( it );
        else
            ++it;

    for ( auto device : devices )
    {
        auto deviceInfo = new DeviceInfo( device );
        m_deviceInfos << deviceInfo;
    }
    m_deviceModel->init( devices );

    // The following PartUtils::runOsprober call in turn calls PartUtils::canBeResized,
    // which relies on a working DeviceModel.
    m_osproberLines = PartUtils::runOsprober( this );

    for ( auto deviceInfo : m_deviceInfos )
    {
        deviceInfo->partitionModel->init( deviceInfo->device.data(), m_osproberLines );
    }

    m_bootLoaderModel->init( devices );

    if ( QDir( "/sys/firmware/efi/efivars" ).exists() )
        scanForEfiSystemPartitions(); //FIXME: this should be removed in favor of
                                      //       proper KPM support for EFI
}
コード例 #3
0
Device*
PartitionCoreModule::createImmutableDeviceCopy( Device* device ) const
{
    CoreBackend* backend = CoreBackendManager::self()->backend();

    Device* deviceBefore = backend->scanDevice( device->deviceNode() );
    return deviceBefore;
}
コード例 #4
0
Calamares::JobResult
CreatePartitionTableJob::exec()
{
    Report report( 0 );
    QString message = tr( "The installer failed to create a partition table on %1." ).arg( m_device->name() );

    CoreBackend* backend = CoreBackendManager::self()->backend();
    QScopedPointer< CoreBackendDevice > backendDevice( backend->openDevice( m_device->deviceNode() ) );
    if ( !backendDevice.data() )
    {
        return Calamares::JobResult::error(
                   message,
                   tr( "Could not open device %1." ).arg( m_device->deviceNode() )
               );
    }

    QScopedPointer< PartitionTable > table( createTable() );
    cDebug() << "Creating new partition table of type" << table->typeName()
             << ", uncommitted yet:\n" << table;

    QProcess lsblk;
    lsblk.setProgram( "lsblk" );
    lsblk.setProcessChannelMode( QProcess::MergedChannels );
    lsblk.start();
    lsblk.waitForFinished();
    cDebug() << "lsblk:\n" << lsblk.readAllStandardOutput();

    QProcess mount;
    mount.setProgram( "mount" );
    mount.setProcessChannelMode( QProcess::MergedChannels );
    mount.start();
    mount.waitForFinished();
    cDebug() << "mount:\n" << mount.readAllStandardOutput();

    bool ok = backendDevice->createPartitionTable( report, *table );
    if ( !ok )
    {
        return Calamares::JobResult::error(
                    message,
                    QString( "Text: %1\nCommand: %2\nOutput: %3\nStatus: %4" )
                        .arg( report.toText() )
                        .arg( report.command() )
                        .arg( report.output() )
                        .arg( report.status() )
               );
    }

    return Calamares::JobResult::ok();
}
コード例 #5
0
Calamares::JobResult
DeletePartitionJob::exec()
{
    Report report( 0 );
    QString message = tr( "The installer failed to delete partition %1." ).arg( m_partition->devicePath() );

    if ( m_device->deviceNode() != m_partition->devicePath() )
    {
        return Calamares::JobResult::error(
                   message,
                   tr( "Partition (%1) and device (%2) do not match." )
                   .arg( m_partition->devicePath() )
                   .arg( m_device->deviceNode() )
               );
    }

    CoreBackend* backend = CoreBackendManager::self()->backend();
    QScopedPointer<CoreBackendDevice> backendDevice( backend->openDevice( m_device->deviceNode() ) );
    if ( !backendDevice.data() )
    {
        return Calamares::JobResult::error(
                   message,
                   tr( "Could not open device %1." ).arg( m_device->deviceNode() )
               );
    }

    QScopedPointer<CoreBackendPartitionTable> backendPartitionTable( backendDevice->openPartitionTable() );
    if ( !backendPartitionTable.data() )
    {
        return Calamares::JobResult::error(
                   message,
                   tr( "Could not open partition table." )
               );
    }

    bool ok = backendPartitionTable->deletePartition( report, *m_partition );
    if ( !ok )
    {
        return Calamares::JobResult::error(
                   message,
                   report.toText()
               );
    }

    backendPartitionTable->commit();
    return Calamares::JobResult::ok();
}
コード例 #6
0
Calamares::JobResult
CreatePartitionJob::exec()
{
    int step = 0;
    const qreal stepCount = 4;

    Report report( 0 );
    QString message = tr( "The installer failed to create partition on disk '%1'." ).arg( m_device->name() );

    progress( step++ / stepCount );
    CoreBackend* backend = CoreBackendManager::self()->backend();
    QScopedPointer<CoreBackendDevice> backendDevice( backend->openDevice( m_device->deviceNode() ) );
    if ( !backendDevice.data() )
    {
        return Calamares::JobResult::error(
                   message,
                   tr( "Could not open device '%1'." ).arg( m_device->deviceNode() )
               );
    }

    progress( step++ / stepCount );
    QScopedPointer<CoreBackendPartitionTable> backendPartitionTable( backendDevice->openPartitionTable() );
    if ( !backendPartitionTable.data() )
    {
        return Calamares::JobResult::error(
                   message,
                   tr( "Could not open partition table." )
               );
    }

    progress( step++ / stepCount );
    QString partitionPath = backendPartitionTable->createPartition( report, *m_partition );
    if ( partitionPath.isEmpty() )
    {
        return Calamares::JobResult::error(
                   message,
                   report.toText()
               );
    }
    m_partition->setPartitionPath( partitionPath );
    backendPartitionTable->commit();

    progress( step++ / stepCount );
    FileSystem& fs = m_partition->fileSystem();
    if ( fs.type() == FileSystem::Unformatted || fs.type() == FileSystem::Extended )
        return Calamares::JobResult::ok();

    if ( !fs.create( report, partitionPath ) )
    {
        return Calamares::JobResult::error(
                   tr( "The installer failed to create file system on partition %1." ).arg( partitionPath ),
                   report.toText()
               );
    }

    if ( !backendPartitionTable->setPartitionSystemType( report, *m_partition ) )
    {
        return Calamares::JobResult::error(
                   tr( "The installer failed to update partition table on disk '%1'." ).arg( m_device->name() ),
                   report.toText()
               );
    }

    backendPartitionTable->commit();
    return Calamares::JobResult::ok();
}
コード例 #7
0
void
PartitionCoreModule::doInit()
{
    FileSystemFactory::init();

    using DeviceList = QList< Device* >;

    CoreBackend* backend = CoreBackendManager::self()->backend();
    DeviceList devices = backend->scanDevices( true );

    cDebug() << "Winnowing" << devices.count() << "devices.";

    // Remove the device which contains / from the list
    for ( DeviceList::iterator it = devices.begin(); it != devices.end(); )
        if ( ! (*it) || hasRootPartition( *it ) ||
             (*it)->deviceNode().startsWith( "/dev/zram") ||
             isIso9660( *it ) )
        {
            cDebug() << "  .. Winnowing" << ( (*it) ? (*it)->deviceNode() : QString( "<null device>" ) );
            it = devices.erase( it );
        }
        else
            ++it;

    cDebug() << "LIST OF DETECTED DEVICES:";
    cDebug() << "node\tcapacity\tname\tprettyName";
    for ( auto device : devices )
    {
        auto deviceInfo = new DeviceInfo( device );
        m_deviceInfos << deviceInfo;
        cDebug() << device->deviceNode() << device->capacity() << device->name() << device->prettyName();
    }
    cDebug() << ".." << devices.count() << "devices detected.";
    m_deviceModel->init( devices );

    // The following PartUtils::runOsprober call in turn calls PartUtils::canBeResized,
    // which relies on a working DeviceModel.
    m_osproberLines = PartUtils::runOsprober( this );

    // We perform a best effort of filling out filesystem UUIDs in m_osproberLines
    // because we will need them later on in PartitionModel if partition paths
    // change.
    // It is a known fact that /dev/sda1-style device paths aren't persistent
    // across reboots (and this doesn't affect us), but partition numbers can also
    // change at runtime against our will just for shits and giggles.
    // But why would that ever happen? What system could possibly be so poorly
    // designed that it requires a partition path rearrangement at runtime?
    // Logical partitions on an MSDOS disklabel of course.
    // See DeletePartitionJob::updatePreview.
    for ( auto deviceInfo : m_deviceInfos )
    {
        for ( auto it = PartitionIterator::begin( deviceInfo->device.data() );
              it != PartitionIterator::end( deviceInfo->device.data() ); ++it )
        {
            Partition* partition = *it;
            for ( auto jt = m_osproberLines.begin();
                  jt != m_osproberLines.end(); ++jt )
            {
                if ( jt->path == partition->partitionPath() &&
                     partition->fileSystem().supportGetUUID() != FileSystem::cmdSupportNone &&
                     !partition->fileSystem().uuid().isEmpty() )
                {
                    jt->uuid = partition->fileSystem().uuid();
                }
            }
        }
    }

    for ( auto deviceInfo : m_deviceInfos )
    {
        deviceInfo->partitionModel->init( deviceInfo->device.data(), m_osproberLines );
    }

    m_bootLoaderModel->init( devices );

    if ( QDir( "/sys/firmware/efi/efivars" ).exists() )
        scanForEfiSystemPartitions(); //FIXME: this should be removed in favor of
                                      //       proper KPM support for EFI
}