diff --git a/src/backend/corebackendpartitiontable.h b/src/backend/corebackendpartitiontable.h index cc21902..c1cf5c6 100644 --- a/src/backend/corebackendpartitiontable.h +++ b/src/backend/corebackendpartitiontable.h @@ -106,7 +106,7 @@ class LIBPARTITIONMANAGERPRIVATE_EXPORT CoreBackendPartitionTable * @param partition the new partition to create on disk * @return the new number the OS sees the partition under (e.g. 7 for "/dev/sda7") or -1 on failure */ - virtual qint32 createPartition(Report& report, const Partition& partition) = 0; + virtual QString createPartition(Report& report, const Partition& partition) = 0; /** * Update the geometry for a partition in the partition table. diff --git a/src/core/partition.cpp b/src/core/partition.cpp index 5fdcfe6..5570338 100644 --- a/src/core/partition.cpp +++ b/src/core/partition.cpp @@ -41,16 +41,15 @@ @param fs pointer to the Partition's FileSystem object. The Partition object will take ownership of this. @param sectorStart the first sector of the Partition on its Device @param sectorEnd the last sector of the Partition on its Device - @param number the Partition's device number, e.g. 7 for /dev/sdd7 + @param partitionPath the Partition's path, e.g. /dev/sda4 or /dev/mmcblk0p1 @param availableFlags the flags available for this Partition @param mountPoint mount point for this Partition @param mounted true if the Partition is mounted @param activeFlags active flags for this Partition @param state the Partition's state */ -Partition::Partition(PartitionNode* parent, const Device& device, const PartitionRole& role, FileSystem* fs, qint64 sectorStart, qint64 sectorEnd, qint32 number, PartitionTable::Flags availableFlags, const QString& mountPoint, bool mounted, PartitionTable::Flags activeFlags, State state) : +Partition::Partition(PartitionNode* parent, const Device& device, const PartitionRole& role, FileSystem* fs, qint64 sectorStart, qint64 sectorEnd, QString partitionPath, PartitionTable::Flags availableFlags, const QString& mountPoint, bool mounted, PartitionTable::Flags activeFlags, State state) : PartitionNode(), - m_Number(number), m_Children(), m_Parent(parent), m_FileSystem(fs), @@ -65,6 +64,7 @@ Partition::Partition(PartitionNode* parent, const Device& device, const Partitio m_SectorSize(device.logicalSectorSize()), m_State(state) { + setPartitionPath(partitionPath); Q_ASSERT(m_Parent); } @@ -89,7 +89,6 @@ Partition::~Partition() */ Partition::Partition(const Partition& other) : PartitionNode(), - m_Number(other.m_Number), m_Children(), m_Parent(other.m_Parent), m_FileSystem(FileSystemFactory::create(other.fileSystem())), @@ -104,6 +103,7 @@ Partition::Partition(const Partition& other) : m_SectorSize(other.m_SectorSize), m_State(other.m_State) { + setPartitionPath(other.m_PartitionPath); foreach(const Partition* child, other.children()) { Partition* p = new Partition(*child); @@ -133,6 +133,7 @@ Partition& Partition::operator=(const Partition& other) m_FirstSector = other.m_FirstSector; m_LastSector = other.m_LastSector; m_DevicePath = other.m_DevicePath; + m_PartitionPath = other.m_PartitionPath; m_MountPoint = other.m_MountPoint; m_AvailableFlags = other.m_AvailableFlags; m_ActiveFlags = other.m_ActiveFlags; @@ -165,12 +166,10 @@ QString Partition::deviceNode() const if (state() == StateRestore) return i18nc("@item partition name", "Restored Partition"); - QString res = m_DevicePath + QString::number(number()); - if (state() == StateCopy) - return i18nc("@item partition name", "Copy of %1", res); + return i18nc("@item partition name", "Copy of %1", partitionPath()); - return res; + return partitionPath(); } /** @return the sectors used in the Partition's FileSystem or, in case of an extended partition, the sum of used sectors of the Partition's children */ @@ -216,10 +215,12 @@ void Partition::adjustLogicalNumbers(qint32 deletedNumber, qint32 insertedNumber foreach (Partition* p, children()) { + QString path = p->partitionPath(); + path.remove(QRegExp("([0-9]+$)")); if (deletedNumber > 4 && p->number() > deletedNumber) - p->setNumber(p->number() - 1); + p->setPartitionPath(path + QString::number(p->number() - 1)); else if (insertedNumber > 4 && p->number() >= insertedNumber) - p->setNumber(p->number() + 1); + p->setPartitionPath(path + QString::number(p->number() + 1)); } } @@ -352,6 +353,18 @@ void Partition::deleteFileSystem() m_FileSystem = NULL; } +void Partition::setPartitionPath(const QString& s) +{ + m_PartitionPath = s; + QRegExp rxPartitionNumber("([0-9]+$)"); + if (rxPartitionNumber.indexIn(partitionPath()) > -1) + { + setNumber(rxPartitionNumber.cap().toInt()); + return; + } + setNumber(-1); +} + void Partition::setFileSystem(FileSystem* fs) { m_FileSystem = fs; diff --git a/src/core/partition.h b/src/core/partition.h index b8db8f4..fe5d274 100644 --- a/src/core/partition.h +++ b/src/core/partition.h @@ -114,7 +114,7 @@ class LIBPARTITIONMANAGERPRIVATE_EXPORT Partition : public PartitionNode }; public: - Partition(PartitionNode* parent, const Device& device, const PartitionRole& role, FileSystem* fs, qint64 sectorStart, qint64 sectorEnd, qint32 number, PartitionTable::Flags availableFlags = PartitionTable::FlagNone, const QString& mountPoint = QString(), bool mounted = false, PartitionTable::Flags activeFlags = PartitionTable::FlagNone, State state = StateNone); + Partition(PartitionNode* parent, const Device& device, const PartitionRole& role, FileSystem* fs, qint64 sectorStart, qint64 sectorEnd, QString partitionPath, PartitionTable::Flags availableFlags = PartitionTable::FlagNone, const QString& mountPoint = QString(), bool mounted = false, PartitionTable::Flags activeFlags = PartitionTable::FlagNone, State state = StateNone); ~Partition(); public: @@ -136,6 +136,7 @@ class LIBPARTITIONMANAGERPRIVATE_EXPORT Partition : public PartitionNode const Partitions& children() const { return m_Children; } /**< @return the Partition's children. empty for non-extended. */ const QString& devicePath() const { return m_DevicePath; } /**< @return the Partition's device path, e.g. /dev/sdd */ + const QString& partitionPath() const { return m_PartitionPath; } /**< @return the Partition's path, e.g. /dev/sdd1 */ qint64 firstSector() const { return m_FirstSector; } /**< @return the Partition's first sector on the Device */ qint64 lastSector() const { return m_LastSector; } /**< @return the Partition's last sector on the Device */ @@ -179,6 +180,7 @@ class LIBPARTITIONMANAGERPRIVATE_EXPORT Partition : public PartitionNode protected: void append(Partition* p) { m_Children.append(p); } void setDevicePath(const QString& s) { m_DevicePath = s; } + void setPartitionPath(const QString& s); void setRoles(const PartitionRole& r) { m_Roles = r; } void setMountPoint(const QString& s) { m_MountPoint = s; } void setFlags(PartitionTable::Flags f) { m_ActiveFlags = f; } @@ -191,11 +193,12 @@ class LIBPARTITIONMANAGERPRIVATE_EXPORT Partition : public PartitionNode void unsetFlag(PartitionTable::Flag f) { m_ActiveFlags &= ~f; } void setParent(PartitionNode* p) { m_Parent = p; } void setFileSystem(FileSystem* fs); - void setNumber(qint32 n) { m_Number = n; } void setState(State s) { m_State = s; } void deleteFileSystem(); private: + void setNumber(qint32 n) { m_Number = n; } + qint32 m_Number; Partitions m_Children; PartitionNode* m_Parent; @@ -204,6 +207,7 @@ class LIBPARTITIONMANAGERPRIVATE_EXPORT Partition : public PartitionNode qint64 m_FirstSector; qint64 m_LastSector; QString m_DevicePath; + QString m_PartitionPath; QString m_MountPoint; PartitionTable::Flags m_AvailableFlags; PartitionTable::Flags m_ActiveFlags; diff --git a/src/core/partitiontable.cpp b/src/core/partitiontable.cpp index 6c430c2..2362aa3 100644 --- a/src/core/partitiontable.cpp +++ b/src/core/partitiontable.cpp @@ -257,7 +257,7 @@ Partition* createUnallocated(const Device& device, PartitionNode& parent, qint64 if (!PartitionTable::getUnallocatedRange(device, parent, start, end)) return NULL; - return new Partition(&parent, device, PartitionRole(r), FileSystemFactory::create(FileSystem::Unknown, start, end), start, end, -1); + return new Partition(&parent, device, PartitionRole(r), FileSystemFactory::create(FileSystem::Unknown, start, end), start, end, ""); } /** Removes all unallocated children from a PartitionNode diff --git a/src/gui/infopane.cpp b/src/gui/infopane.cpp index 6c69a16..d6b0c50 100644 --- a/src/gui/infopane.cpp +++ b/src/gui/infopane.cpp @@ -116,7 +116,7 @@ void InfoPane::showPartition(Qt::DockWidgetArea area, const Partition& p) int y = createHeader(p.deviceNode(), cols(area)); if (p.fileSystem().type() == FileSystem::Luks) { - QString deviceNode = p.devicePath() + QString::number(p.number()); + QString deviceNode = p.partitionPath(); createLabels(i18nc("@label partition", "File system:"), p.fileSystem().name(), cols(area), x, y); createLabels(i18nc("@label partition", "Capacity:"), Capacity::formatByteSize(p.capacity()), cols(area), x, y); createLabels(i18nc("@label partition", "Cipher name:"), FS::luks::getCipherName(deviceNode), cols(area), x, y); diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index ddf4c21..24f1f8a 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -891,7 +891,7 @@ void MainWindow::onImportPartitionTable() if (fs->supportSetLabel() != FileSystem::cmdSupportNone && !volumeLabel.isEmpty()) fs->setLabel(volumeLabel); - Partition* p = new Partition(parent, device, role, fs, firstSector, lastSector, -1, PartitionTable::FlagNone, QString(), false, PartitionTable::FlagNone, Partition::StateNew); + Partition* p = new Partition(parent, device, role, fs, firstSector, lastSector, "", PartitionTable::FlagNone, QString(), false, PartitionTable::FlagNone, Partition::StateNew); operationStack().push(new NewOperation(device, p)); } diff --git a/src/jobs/createpartitionjob.cpp b/src/jobs/createpartitionjob.cpp index 7fb620b..fd7b5ae 100644 --- a/src/jobs/createpartitionjob.cpp +++ b/src/jobs/createpartitionjob.cpp @@ -58,12 +58,12 @@ bool CreatePartitionJob::run(Report& parent) if (backendPartitionTable) { - qint32 num = backendPartitionTable->createPartition(*report, partition()); + QString partitionPath = backendPartitionTable->createPartition(*report, partition()); - if (num > 0) + if (partitionPath != "") { rval = true; - partition().setNumber(num); + partition().setPartitionPath(partitionPath); partition().setState(Partition::StateNone); backendPartitionTable->commit(); } diff --git a/src/ops/copyoperation.cpp b/src/ops/copyoperation.cpp index db59637..9d6b5d2 100644 --- a/src/ops/copyoperation.cpp +++ b/src/ops/copyoperation.cpp @@ -147,7 +147,7 @@ bool CopyOperation::execute(Report& parent) if (overwrittenPartition()) { copiedPartition().setDevicePath(overwrittenPartition()->devicePath()); - copiedPartition().setNumber(overwrittenPartition()->number()); + copiedPartition().setPartitionPath(overwrittenPartition()->devicePath()); } // now run the copy job itself @@ -273,8 +273,8 @@ Partition* CopyOperation::createCopy(const Partition& target, const Partition& s { Partition* p = target.roles().has(PartitionRole::Unallocated) ? new Partition(source) : new Partition(target); - p->setNumber(source.number()); p->setDevicePath(source.devicePath()); + p->setPartitionPath(source.partitionPath()); p->setState(Partition::StateCopy); p->deleteFileSystem(); diff --git a/src/ops/newoperation.cpp b/src/ops/newoperation.cpp index 77b793f..fb33d72 100644 --- a/src/ops/newoperation.cpp +++ b/src/ops/newoperation.cpp @@ -129,7 +129,7 @@ Partition* NewOperation::createNew(const Partition& cloneFrom) p->deleteFileSystem(); p->setFileSystem(FileSystemFactory::create(FileSystem::defaultFileSystem(), p->firstSector(), p->lastSector())); p->setState(Partition::StateNew); - p->setNumber(-1); + p->setPartitionPath(""); return p; } diff --git a/src/ops/restoreoperation.cpp b/src/ops/restoreoperation.cpp index f23335d..2698c84 100644 --- a/src/ops/restoreoperation.cpp +++ b/src/ops/restoreoperation.cpp @@ -126,7 +126,7 @@ bool RestoreOperation::execute(Report& parent) Report* report = parent.newChild(description()); if (overwrittenPartition()) - restorePartition().setNumber(overwrittenPartition()->number()); + restorePartition().setPartitionPath(overwrittenPartition()->devicePath()); if (overwrittenPartition() || (rval = createPartitionJob()->run(*report))) { @@ -229,7 +229,7 @@ Partition* RestoreOperation::createRestorePartition(const Device& device, Partit return NULL; const qint64 end = start + fileInfo.size() / device.logicalSectorSize() - 1; - Partition* p = new Partition(&parent, device, PartitionRole(r), FileSystemFactory::create(FileSystem::Unknown, start, end), start, end, -1); + Partition* p = new Partition(&parent, device, PartitionRole(r), FileSystemFactory::create(FileSystem::Unknown, start, end), start, end, ""); p->setState(Partition::StateRestore); return p; diff --git a/src/plugins/dummy/dummypartitiontable.cpp b/src/plugins/dummy/dummypartitiontable.cpp index 04c19e9..5c0029d 100644 --- a/src/plugins/dummy/dummypartitiontable.cpp +++ b/src/plugins/dummy/dummypartitiontable.cpp @@ -67,12 +67,12 @@ CoreBackendPartition* DummyPartitionTable::getPartitionBySector(qint64 sector) return new DummyPartition(); } -qint32 DummyPartitionTable::createPartition(Report& report, const Partition& partition) +QString DummyPartitionTable::createPartition(Report& report, const Partition& partition) { Q_UNUSED(report); Q_UNUSED(partition); - return true; + return "dummy"; } bool DummyPartitionTable::deletePartition(Report& report, const Partition& partition) diff --git a/src/plugins/dummy/dummypartitiontable.h b/src/plugins/dummy/dummypartitiontable.h index 65d241b..06890fe 100644 --- a/src/plugins/dummy/dummypartitiontable.h +++ b/src/plugins/dummy/dummypartitiontable.h @@ -45,7 +45,7 @@ class DummyPartitionTable : public CoreBackendPartitionTable virtual CoreBackendPartition* getExtendedPartition(); virtual CoreBackendPartition* getPartitionBySector(qint64 sector); - virtual qint32 createPartition(Report& report, const Partition& partition); + virtual QString createPartition(Report& report, const Partition& partition); 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); diff --git a/src/plugins/libparted/libpartedbackend.cpp b/src/plugins/libparted/libpartedbackend.cpp index 31d3e61..75ae85c 100644 --- a/src/plugins/libparted/libpartedbackend.cpp +++ b/src/plugins/libparted/libpartedbackend.cpp @@ -367,7 +367,7 @@ void LibPartedBackend::scanDevicePartitions(PedDevice*, Device& d, PedDisk* pedD if (parent == NULL) parent = d.partitionTable(); - const QString node = pedDisk->dev->path + QString::number(pedPartition->num); + const QString node = QString(ped_partition_get_path(pedPartition)); FileSystem* fs = FileSystemFactory::create(type, pedPartition->geom.start, pedPartition->geom.end); // libparted does not handle LUKS partitions @@ -384,7 +384,7 @@ void LibPartedBackend::scanDevicePartitions(PedDevice*, Device& d, PedDisk* pedD mounted = ped_partition_is_busy(pedPartition); } - Partition* part = new Partition(parent, d, PartitionRole(r), fs, pedPartition->geom.start, pedPartition->geom.end, pedPartition->num, availableFlags(pedPartition), mountPoint, mounted, activeFlags(pedPartition)); + Partition* part = new Partition(parent, d, PartitionRole(r), fs, pedPartition->geom.start, pedPartition->geom.end, node, availableFlags(pedPartition), mountPoint, mounted, activeFlags(pedPartition)); readSectorsUsed(pedDisk, d, *part, mountPoint); diff --git a/src/plugins/libparted/libpartedpartitiontable.cpp b/src/plugins/libparted/libpartedpartitiontable.cpp index 8b3d675..d954bfa 100644 --- a/src/plugins/libparted/libpartedpartitiontable.cpp +++ b/src/plugins/libparted/libpartedpartitiontable.cpp @@ -144,11 +144,11 @@ static PedFileSystemType* getPedFileSystemType(FileSystem::Type t) return ped_file_system_type_get("ext2"); } -qint32 LibPartedPartitionTable::createPartition(Report& report, const Partition& partition) +QString LibPartedPartitionTable::createPartition(Report& report, const Partition& partition) { Q_ASSERT(partition.devicePath() == pedDevice()->path); - qint32 rval = -1; + QString rval = ""; // According to libParted docs, PedPartitionType can be "NULL if unknown". That's obviously wrong, // it's a typedef for an enum. So let's use something the libparted devs will hopefully never @@ -165,7 +165,7 @@ qint32 LibPartedPartitionTable::createPartition(Report& report, const Partition& if (pedType == static_cast(0xffffffff)) { report.line() << i18nc("@info/plain", "Unknown partition role for new partition %1 (roles: %2)", partition.deviceNode(), partition.roles().toString()); - return false; + return ""; } PedFileSystemType* pedFsType = (partition.roles().has(PartitionRole::Extended) || partition.fileSystem().type() == FileSystem::Unformatted) ? NULL : getPedFileSystemType(partition.fileSystem().type()); @@ -175,7 +175,7 @@ qint32 LibPartedPartitionTable::createPartition(Report& report, const Partition& if (pedPartition == NULL) { report.line() << i18nc("@info/plain", "Failed to create new partition %1.", partition.deviceNode()); - return false; + return ""; } PedConstraint* pedConstraint = NULL; @@ -187,11 +187,11 @@ qint32 LibPartedPartitionTable::createPartition(Report& report, const Partition& if (pedConstraint == NULL) { report.line() << i18nc("@info/plain", "Failed to create a new partition: could not get geometry for constraint."); - return -1; + return ""; } if (ped_disk_add_partition(pedDisk(), pedPartition, pedConstraint)) - rval = pedPartition->num; + rval = QString(ped_partition_get_path(pedPartition)); else report.line() << i18nc("@info/plain", "Failed to add partition %1 to device %2.", partition.deviceNode(), pedDisk()->dev->path); diff --git a/src/plugins/libparted/libpartedpartitiontable.h b/src/plugins/libparted/libpartedpartitiontable.h index 1b9f2d6..4b9efd1 100644 --- a/src/plugins/libparted/libpartedpartitiontable.h +++ b/src/plugins/libparted/libpartedpartitiontable.h @@ -48,7 +48,7 @@ class LibPartedPartitionTable : public CoreBackendPartitionTable virtual CoreBackendPartition* getExtendedPartition(); virtual CoreBackendPartition* getPartitionBySector(qint64 sector); - virtual qint32 createPartition(Report& report, const Partition& partition); + virtual QString createPartition(Report& report, const Partition& partition); 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);