mirror of https://github.com/cutefishos/calamares
Add the ability to (re)create partition tables
parent
2e3f1c655c
commit
83a56a6bd3
@ -0,0 +1,96 @@
|
||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
||||
*
|
||||
* Calamares is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Calamares is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <CreatePartitionTableJob.h>
|
||||
|
||||
#include <utils/Logger.h>
|
||||
|
||||
// CalaPM
|
||||
#include <backend/corebackend.h>
|
||||
#include <backend/corebackendmanager.h>
|
||||
#include <backend/corebackenddevice.h>
|
||||
#include <backend/corebackendpartition.h>
|
||||
#include <backend/corebackendpartitiontable.h>
|
||||
#include <core/device.h>
|
||||
#include <core/partition.h>
|
||||
#include <core/partitiontable.h>
|
||||
#include <fs/filesystem.h>
|
||||
#include <util/report.h>
|
||||
|
||||
// Qt
|
||||
#include <QScopedPointer>
|
||||
|
||||
CreatePartitionTableJob::CreatePartitionTableJob( Device* device )
|
||||
: m_device( device )
|
||||
{
|
||||
}
|
||||
|
||||
QString
|
||||
CreatePartitionTableJob::prettyName() const
|
||||
{
|
||||
return tr( "Create partition table" ); // FIXME
|
||||
}
|
||||
|
||||
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() );
|
||||
bool ok = backendDevice->createPartitionTable( report, *table );
|
||||
if ( !ok )
|
||||
{
|
||||
return Calamares::JobResult::error(
|
||||
message,
|
||||
report.toText()
|
||||
);
|
||||
}
|
||||
|
||||
return Calamares::JobResult::ok();
|
||||
}
|
||||
|
||||
void
|
||||
CreatePartitionTableJob::updatePreview()
|
||||
{
|
||||
// Device takes ownership of its table, but does not destroy the current
|
||||
// one when setPartitionTable() is called, so do it ourself
|
||||
delete m_device->partitionTable();
|
||||
m_device->setPartitionTable( createTable() );
|
||||
m_device->partitionTable()->updateUnallocated( *m_device );
|
||||
}
|
||||
|
||||
PartitionTable*
|
||||
CreatePartitionTableJob::createTable()
|
||||
{
|
||||
PartitionTable::TableType type = PartitionTable::msdos;
|
||||
return new PartitionTable(type,
|
||||
PartitionTable::defaultFirstUsable( *m_device, type ),
|
||||
PartitionTable::defaultLastUsable( *m_device, type )
|
||||
);
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
|
||||
*
|
||||
* Calamares is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Calamares is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef CREATEPARTITIONTABLEJOB_H
|
||||
#define CREATEPARTITIONTABLEJOB_H
|
||||
|
||||
#include <Job.h>
|
||||
|
||||
class Device;
|
||||
class PartitionTable;
|
||||
|
||||
class CreatePartitionTableJob : public Calamares::Job
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CreatePartitionTableJob( Device* device );
|
||||
QString prettyName() const override;
|
||||
Calamares::JobResult exec() override;
|
||||
|
||||
void updatePreview();
|
||||
Device* device() const
|
||||
{
|
||||
return m_device;
|
||||
}
|
||||
|
||||
private:
|
||||
Device* m_device;
|
||||
PartitionTable* createTable();
|
||||
};
|
||||
|
||||
#endif /* CREATEPARTITIONTABLEJOB_H */
|
Loading…
Reference in New Issue