clean up the plugin interface a bit.

svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1097594
This commit is contained in:
Volker Lanz 2010-03-01 18:30:35 +00:00
parent 856ef859eb
commit 0ab3817d46
12 changed files with 95 additions and 90 deletions

17
TODO
View File

@ -1,7 +1,6 @@
Random plans and ideas for 1.1 and beyond:
* The whole lvm/dm debacle. Nothing much useful can be done about it without
the backend stuff mentioned above, though.
* The whole lvm/dm debacle.
* The interface between core and the file systems needs some more thought.
Ideally we'd be free to use either external helper apps (like we do now) or
@ -17,3 +16,17 @@ Random plans and ideas for 1.1 and beyond:
* The KPart works but has problems: The context menus don't show up, the status
bar is missing, maybe more.
Bugs:
* When creating a new partition table the info pane isn't updated with the new
type.
* Setting flags for partitions appears to work but no flags are set.
* Creating a msdos partition table with cylinder alignment off still creates it
will cylinder alignment
* Resizing fat32 file systems (a libparted handled one) crashes related to the
ped timer stuff and Job::emitProgress somewhere.

View File

@ -48,7 +48,7 @@ class LIBPARTITIONMANAGERPRIVATE_EXPORT CoreBackendDevice
virtual CoreBackendPartitionTable* openPartitionTable() = 0;
virtual bool createPartitionTable(Report& report, PartitionTable& ptable) = 0;
virtual bool createPartitionTable(Report& report, const PartitionTable& ptable) = 0;
virtual bool readSectors(void* buffer, qint64 offset, qint64 numSectors) = 0;
virtual bool writeSectors(void* buffer, qint64 offset, qint64 numSectors) = 0;

View File

@ -43,12 +43,13 @@ class LIBPARTITIONMANAGERPRIVATE_EXPORT CoreBackendPartitionTable
virtual CoreBackendPartition* getExtendedPartition() = 0;
virtual CoreBackendPartition* getPartitionBySector(qint64 sector) = 0;
virtual bool createPartition(Report& report, Partition& partition) = 0;
virtual bool deletePartition(Report& report, Partition& partition) = 0;
virtual bool updateGeometry(Report& report, Partition& partition, qint64 sector_start, qint64 sector_end) = 0;
virtual bool clobberFileSystem(Report& report, Partition& partition) = 0;
virtual bool resizeFileSystem(Report& report, Partition& partition, qint64 newLength) = 0;
virtual FileSystem::Type detectFileSystemBySector(Report& report, Device& device, qint64 sector) = 0;
virtual bool deletePartition(Report& report, const Partition& partition) = 0;
virtual bool clobberFileSystem(Report& report, const Partition& partition) = 0;
virtual bool resizeFileSystem(Report& report, const Partition& partition, qint64 newLength) = 0;
virtual FileSystem::Type detectFileSystemBySector(Report& report, const Device& device, qint64 sector) = 0;
virtual bool createPartition(Report& report, const Partition& partition, quint32& new_number) = 0;
virtual bool updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end) = 0;
};
#endif

View File

@ -50,7 +50,11 @@
K_PLUGIN_FACTORY(LibPartedBackendFactory, registerPlugin<LibPartedBackend>(); )
K_EXPORT_PLUGIN(LibPartedBackendFactory("pluginpmlibparted"))
static const LibPartedBackend::FlagMap flagmap[] =
static struct
{
PedPartitionFlag pedFlag;
PartitionTable::Flag flag;
} flagmap[] =
{
{ PED_PARTITION_BOOT, PartitionTable::FlagBoot },
{ PED_PARTITION_ROOT, PartitionTable::FlagRoot },
@ -242,11 +246,21 @@ static PartitionTable::Flags availableFlags(PedPartition* p)
return flags;
}
/** Constructs a LibParted object. */
LibPartedBackend::LibPartedBackend(QObject*, const QList<QVariant>&) :
CoreBackend()
{
ped_exception_set_handler(pedExceptionHandler);
}
QString LibPartedBackend::about() const
{
return QString("LibPartedBackend (%1)").arg(ped_get_version());
}
/** Scans a Device for Partitions.
This function will scan a Device for all Partitions on it, detect the FileSystem for each Partition,
This method will scan a Device for all Partitions on it, detect the FileSystem for each Partition,
try to determine the FileSystem usage, read the FileSystem label and store it all in newly created
objects that are in the end added to the Device's PartitionTable.
@ -254,7 +268,7 @@ static PartitionTable::Flags availableFlags(PedPartition* p)
@param d Device
@param pedDisk libparted pointer to the partition table
*/
static void scanDevicePartitions(PedDevice* pedDevice, Device& d, PedDisk* pedDisk)
void LibPartedBackend::scanDevicePartitions(PedDevice* pedDevice, Device& d, PedDisk* pedDisk)
{
Q_ASSERT(pedDevice);
Q_ASSERT(pedDisk);
@ -273,7 +287,7 @@ static void scanDevicePartitions(PedDevice* pedDevice, Device& d, PedDisk* pedDi
continue;
PartitionRole::Roles r = PartitionRole::None;
FileSystem::Type type = LibPartedBackend::detectFileSystem(pedDevice, pedPartition);
FileSystem::Type type = detectFileSystem(pedDevice, pedPartition);
switch(pedPartition->type)
{
@ -331,31 +345,6 @@ static void scanDevicePartitions(PedDevice* pedDevice, Device& d, PedDisk* pedDi
ped_disk_destroy(pedDisk);
}
/** Constructs a LibParted object. */
LibPartedBackend::LibPartedBackend(QObject*, const QList<QVariant>&) :
CoreBackend()
{
ped_exception_set_handler(pedExceptionHandler);
}
QString LibPartedBackend::about() const
{
return QString("LibPartedBackend (%1)").arg(ped_get_version());
}
/** Return a map of partition flags from libparted flags to PartitionTable::Flags
@return the map
*/
const LibPartedBackend::FlagMap* LibPartedBackend::flagMap()
{
return flagmap;
}
quint32 LibPartedBackend::flagMapSize()
{
return sizeof(flagmap) / sizeof(flagmap[0]);
}
/** Create a Device for the given device_node and scan it for partitions.
@param device_node the device node (e.g. "/dev/sda")
@return the created Device object. callers need to free this.
@ -486,3 +475,13 @@ FileSystem::Type LibPartedBackend::detectFileSystem(PedDevice* pedDevice, PedPar
return rval;
}
PedPartitionFlag LibPartedBackend::getPedFlag(PartitionTable::Flag flag)
{
for (quint32 i = 0; i < sizeof(flagmap) / sizeof(flagmap[0]); i++)
if (flagmap[i].flag == flag)
return flagmap[i].pedFlag;
return static_cast<PedPartitionFlag>(-1);
}

View File

@ -33,45 +33,42 @@
#include <QVariant>
#include <qglobal.h>
class LibPartedDevice;
class LibPartedPartitionTable;
class LibPartedPartition;
class Device;
class KPluginFactory;
class QString;
/** @brief Device scanning done by libparted.
More libparted-related stuff is in the @link Job Job-derived @endlink classes.
/** @brief Backend plugin for libparted.
@author vl@fidra.de
*/
class LibPartedBackend : public CoreBackend
{
friend class KPluginFactory;
friend class LibPartedPartition;
friend class LibPartedDevice;
friend class LibPartedPartitionTable;
Q_DISABLE_COPY(LibPartedBackend)
public:
typedef struct
{
PedPartitionFlag pedFlag;
PartitionTable::Flag flag;
} FlagMap;
private:
LibPartedBackend(QObject* parent, const QList<QVariant>& args);
public:
static const FlagMap* flagMap();
static quint32 flagMapSize();
virtual QString about() const;
virtual CoreBackendDevice* openDevice(const QString& device_node);
virtual CoreBackendDevice* openDeviceExclusive(const QString& device_node);
virtual bool closeDevice(CoreBackendDevice* core_device);
virtual Device* scanDevice(const QString& device_node);
virtual QString about() const;
Device* scanDevice(const QString& device_node);
private:
static FileSystem::Type detectFileSystem(PedDevice* pedDevice, PedPartition* pedPartition);
static PedPartitionFlag getPedFlag(PartitionTable::Flag flag);
static void scanDevicePartitions(PedDevice* pedDevice, Device& d, PedDisk* pedDisk);
};
#endif

View File

@ -91,7 +91,7 @@ CoreBackendPartitionTable* LibPartedDevice::openPartitionTable()
return ptable;
}
bool LibPartedDevice::createPartitionTable(Report& report, PartitionTable& ptable)
bool LibPartedDevice::createPartitionTable(Report& report, const PartitionTable& ptable)
{
PedDiskType* pedDiskType = ped_disk_type_get(ptable.typeName().toAscii());

View File

@ -47,7 +47,7 @@ class LibPartedDevice : public CoreBackendDevice
virtual CoreBackendPartitionTable* openPartitionTable();
virtual bool createPartitionTable(Report& report, PartitionTable& ptable);
virtual bool createPartitionTable(Report& report, const PartitionTable& ptable);
virtual bool readSectors(void* buffer, qint64 offset, qint64 numSectors);
virtual bool writeSectors(void* buffer, qint64 offset, qint64 numSectors);

View File

@ -30,20 +30,11 @@ LibPartedPartition::LibPartedPartition(PedPartition* ped_partition) :
{
}
static PedPartitionFlag getPedFlag(PartitionTable::Flag flag)
{
for (quint32 i = 0; i < LibPartedBackend::flagMapSize(); i++)
if (LibPartedBackend::flagMap()[i].flag == flag)
return LibPartedBackend::flagMap()[i].pedFlag;
return static_cast<PedPartitionFlag>(-1);
}
bool LibPartedPartition::setFlag(Report& report, PartitionTable::Flag partitionManagerFlag, bool state)
{
Q_ASSERT(pedPartition() != NULL);
const PedPartitionFlag f = getPedFlag(partitionManagerFlag);
const PedPartitionFlag f = LibPartedBackend::getPedFlag(partitionManagerFlag);
// ignore flags that don't exist for this partition
if (!ped_partition_is_flag_available(pedPartition(), f))

View File

@ -143,7 +143,7 @@ static PedFileSystemType* getPedFileSystemType(FileSystem::Type t)
return ped_file_system_type_get("ext2");
}
bool LibPartedPartitionTable::createPartition(Report& report, Partition& partition)
bool LibPartedPartitionTable::createPartition(Report& report, const Partition& partition, quint32& new_number)
{
Q_ASSERT(partition.devicePath() == pedDevice()->path);
@ -191,12 +191,7 @@ bool LibPartedPartitionTable::createPartition(Report& report, Partition& partiti
if (ped_disk_add_partition(pedDisk(), pedPartition, pedConstraint) && commit())
{
partition.setNumber(pedPartition->num);
partition.setState(Partition::StateNone);
partition.setFirstSector(pedPartition->geom.start);
partition.setLastSector(pedPartition->geom.end);
new_number = pedPartition->num;
rval = true;
}
else
@ -207,7 +202,7 @@ bool LibPartedPartitionTable::createPartition(Report& report, Partition& partiti
return rval;
}
bool LibPartedPartitionTable::deletePartition(Report& report, Partition& partition)
bool LibPartedPartitionTable::deletePartition(Report& report, const Partition& partition)
{
Q_ASSERT(partition.devicePath() == pedDevice()->path);
@ -230,7 +225,7 @@ bool LibPartedPartitionTable::deletePartition(Report& report, Partition& partiti
return rval;
}
bool LibPartedPartitionTable::updateGeometry(Report& report, Partition& partition, qint64 sector_start, qint64 sector_end)
bool LibPartedPartitionTable::updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end)
{
Q_ASSERT(partition.devicePath() == pedDevice()->path);
@ -247,11 +242,7 @@ bool LibPartedPartitionTable::updateGeometry(Report& report, Partition& partitio
if (PedConstraint* pedConstraint = ped_constraint_exact(pedGeometry))
{
if (ped_disk_set_partition_geom(pedDisk(), pedPartition, pedConstraint, sector_start, sector_end) && commit())
{
rval = true;
partition.setFirstSector(pedPartition->geom.start);
partition.setLastSector(pedPartition->geom.end);
}
else
report.line() << i18nc("@info/plain", "Could not set geometry for partition <filename>%1</filename> while trying to resize/move it.", partition.deviceNode());
}
@ -267,7 +258,7 @@ bool LibPartedPartitionTable::updateGeometry(Report& report, Partition& partitio
return rval;
}
bool LibPartedPartitionTable::clobberFileSystem(Report& report, Partition& partition)
bool LibPartedPartitionTable::clobberFileSystem(Report& report, const Partition& partition)
{
bool rval = false;
@ -311,7 +302,7 @@ static void pedTimerHandler(PedTimer* pedTimer, void* ctx)
}
}
bool LibPartedPartitionTable::resizeFileSystem(Report& report, Partition& partition, qint64 newLength)
bool LibPartedPartitionTable::resizeFileSystem(Report& report, const Partition& partition, qint64 newLength)
{
bool rval = false;
@ -342,7 +333,7 @@ bool LibPartedPartitionTable::resizeFileSystem(Report& report, Partition& partit
return rval;
}
FileSystem::Type LibPartedPartitionTable::detectFileSystemBySector(Report& report, Device& device, qint64 sector)
FileSystem::Type LibPartedPartitionTable::detectFileSystemBySector(Report& report, const Device& device, qint64 sector)
{
PedPartition* pedPartition = ped_disk_get_partition_by_sector(pedDisk(), sector);

View File

@ -48,12 +48,12 @@ class LibPartedPartitionTable : public CoreBackendPartitionTable
virtual CoreBackendPartition* getExtendedPartition();
virtual CoreBackendPartition* getPartitionBySector(qint64 sector);
virtual bool createPartition(Report& report, Partition& partition);
virtual bool deletePartition(Report& report, Partition& partition);
virtual bool updateGeometry(Report& report, Partition& partition, qint64 sector_start, qint64 sector_end);
virtual bool clobberFileSystem(Report& report, Partition& partition);
virtual bool resizeFileSystem(Report& report, Partition& partition, qint64 newLength);
virtual FileSystem::Type detectFileSystemBySector(Report& report, Device& device, qint64 sector);
virtual bool createPartition(Report& report, const Partition& partition, quint32& new_number);
virtual bool deletePartition(Report& report, const Partition& partition);
virtual bool updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end);
virtual bool clobberFileSystem(Report& report, const Partition& partition);
virtual bool resizeFileSystem(Report& report, const Partition& partition, qint64 newLength);
virtual FileSystem::Type detectFileSystemBySector(Report& report, const Device& device, qint64 sector);
private:
PedDevice* pedDevice() { return m_PedDevice; }

View File

@ -57,9 +57,15 @@ bool CreatePartitionJob::run(Report& parent)
if (backendPartitionTable)
{
rval = backendPartitionTable->createPartition(*report, partition());
quint32 num = -1;
rval = backendPartitionTable->createPartition(*report, partition(), num);
if (!rval)
if (rval)
{
partition().setNumber(num);
partition().setState(Partition::StateNone);
}
else
report->line() << i18nc("@info/plain", "Failed to add partition <filename>%1</filename> to device <filename>%2</filename>.", partition().deviceNode(), device().deviceNode());
delete backendPartitionTable;

View File

@ -64,6 +64,13 @@ bool SetPartGeometryJob::run(Report& parent)
if (backendPartitionTable)
{
rval = backendPartitionTable->updateGeometry(*report, partition(), newStart(), newStart() + newLength() - 1);
if (rval)
{
partition().setFirstSector(newStart());
partition().setLastSector(newStart() + newLength() - 1);
}
delete backendPartitionTable;
}