From 6bd5736d358335c77b62d675981907cf6f3acfdf Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Thu, 25 Sep 2014 16:49:13 +0200 Subject: [PATCH] Add findPartitionByPath to PMUtils --- src/modules/partition/core/PMUtils.cpp | 19 ++++++++++++++++++- src/modules/partition/core/PMUtils.h | 6 ++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/modules/partition/core/PMUtils.cpp b/src/modules/partition/core/PMUtils.cpp index 20030a0e5..7f5d2ac78 100644 --- a/src/modules/partition/core/PMUtils.cpp +++ b/src/modules/partition/core/PMUtils.cpp @@ -28,16 +28,19 @@ namespace PMUtils { + bool isPartitionFreeSpace( Partition* partition ) { return partition->roles().has( PartitionRole::Unallocated ); } + bool isPartitionNew( Partition* partition ) { return partition->state() == Partition::StateNew; } + Partition* findPartitionByMountPoint( const QList< Device* >& devices, const QString& mountPoint ) { @@ -48,6 +51,18 @@ findPartitionByMountPoint( const QList< Device* >& devices, const QString& mount return nullptr; } + +Partition* +findPartitionByPath( const QList< Device* >& devices, const QString& path ) +{ + for ( auto device : devices ) + for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it ) + if ( ( *it )->partitionPath() == path.simplified() ) + return *it; + return nullptr; +} + + Partition* createNewPartition( PartitionNode* parent, const Device& device, const PartitionRole& role, FileSystem::Type fsType, qint64 firstSector, qint64 lastSector ) { @@ -66,6 +81,7 @@ createNewPartition( PartitionNode* parent, const Device& device, const Partition ); } + Partition* clonePartition( Device* device, Partition* partition ) { @@ -80,7 +96,8 @@ clonePartition( Device* device, Partition* partition ) partition->roles(), fs, fs->firstSector(), fs->lastSector(), partition->partitionPath() - ); + ); } + } // namespace diff --git a/src/modules/partition/core/PMUtils.h b/src/modules/partition/core/PMUtils.h index e2a3a39f8..81778ae3b 100644 --- a/src/modules/partition/core/PMUtils.h +++ b/src/modules/partition/core/PMUtils.h @@ -49,6 +49,12 @@ bool isPartitionNew( Partition* ); */ Partition* findPartitionByMountPoint( const QList< Device* >& devices, const QString& mountPoint ); +/** + * Iterates on all devices and partitions and returns a pointer to the Partition object + * for the given path, or nullptr if a Partition for the given path cannot be found. + */ +Partition* findPartitionByPath( const QList< Device* >& devices, const QString& path ); + /** * Helper function to create a new Partition object (does not create anything * on the disk) associated with a FileSystem.