diff --git a/src/ops/resizevolumegroupoperation.cpp b/src/ops/resizevolumegroupoperation.cpp index daf8c9c..c9e95c1 100644 --- a/src/ops/resizevolumegroupoperation.cpp +++ b/src/ops/resizevolumegroupoperation.cpp @@ -18,12 +18,11 @@ #include "ops/resizevolumegroupoperation.h" #include "core/lvmdevice.h" -#include "fs/lvm2_pv.h" -#include "fs/luks.h" #include "core/partition.h" - +#include "fs/lvm2_pv.h" #include "jobs/resizevolumegroupjob.h" #include "jobs/movephysicalvolumejob.h" +#include "util/helpers.h" #include @@ -61,24 +60,21 @@ ResizeVolumeGroupOperation::ResizeVolumeGroupOperation(LvmDevice& d, const QList qint64 currentFreePE = 0; for (const auto &p : currentList()) { - const FS::lvm2_pv* lvm2PVFs = p->roles().has(PartitionRole::Luks) ? - static_cast(static_cast(&p->fileSystem())->innerFS()) : // LVM inside LUKS partition - static_cast(&p->fileSystem()); // simple LVM + FS::lvm2_pv *lvm2PVFs; + innerFS(p, lvm2PVFs); currentFreePE += lvm2PVFs->freePE(); } qint64 removedFreePE = 0; for (const auto &p : toRemoveList) { // FIXME: qAsConst - const FS::lvm2_pv* lvm2PVFs = p->roles().has(PartitionRole::Luks) ? - static_cast(static_cast(&p->fileSystem())->innerFS()) : // LVM inside LUKS partition - static_cast(&p->fileSystem()); // simple LVM + FS::lvm2_pv *lvm2PVFs; + innerFS(p, lvm2PVFs); removedFreePE += lvm2PVFs->freePE(); } qint64 freePE = currentFreePE - removedFreePE; qint64 movePE = 0; for (const auto &p : toRemoveList) { // FIXME: qAsConst - const FS::lvm2_pv* lvm2PVFs = p->roles().has(PartitionRole::Luks) ? - static_cast(static_cast(&p->fileSystem())->innerFS()) : // LVM inside LUKS partition - static_cast(&p->fileSystem()); // simple LVM + FS::lvm2_pv *lvm2PVFs; + innerFS(p, lvm2PVFs); movePE += lvm2PVFs->allocatedPE(); } qint64 growPE = 0; diff --git a/src/util/helpers.h b/src/util/helpers.h index 39b95e8..a43860d 100644 --- a/src/util/helpers.h +++ b/src/util/helpers.h @@ -19,12 +19,15 @@ #define HELPERS__H +#include "core/partition.h" #include "fs/filesystem.h" +#include "fs/luks.h" #include "util/libpartitionmanagerexport.h" class KAboutData; +class Partition; class QString; class QPoint; class QTreeWidget; @@ -41,4 +44,18 @@ LIBKPMCORE_EXPORT bool isMounted(const QString& deviceNode); LIBKPMCORE_EXPORT KAboutData aboutKPMcore(); +/** Pointer to the file system (which might be inside LUKS container) contained in the partition + * @param p Partition where we look for file system + * @return pointer to the FileSystem +*/ +template +inline LIBKPMCORE_EXPORT void innerFS (const Partition* p, T& fs) +{ + Partition* partition = const_cast(p); + if (p->roles().has(PartitionRole::Luks)) + fs = dynamic_cast(dynamic_cast(&p->fileSystem())->innerFS()); + else + fs = dynamic_cast(&partition->fileSystem()); +} + #endif