From de346177b5be649c3a87cfcf7d3eaee7cde6e490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Sat, 3 Oct 2020 12:41:18 +0100 Subject: [PATCH] Do not allow moving partitions without partition table. --- src/core/partition.cpp | 9 +++++++++ src/core/partition.h | 4 +++- src/ops/resizeoperation.cpp | 14 +++++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/core/partition.cpp b/src/core/partition.cpp index 87d308d..61c59f4 100644 --- a/src/core/partition.cpp +++ b/src/core/partition.cpp @@ -261,6 +261,15 @@ bool Partition::hasChildren() const return false; } +/** @return returns the Partition Table which contains this Partition */ +const PartitionTable* Partition::partitionTable() const { + const PartitionNode *p = this; + while (p->parent() != nullptr) { + p = p->parent(); + } + return static_cast(p); +} + /** Sets an extended Partition to mounted if any of its children are mounted */ void Partition::checkChildrenMounted() { diff --git a/src/core/partition.h b/src/core/partition.h index 2074261..e25678b 100644 --- a/src/core/partition.h +++ b/src/core/partition.h @@ -1,7 +1,7 @@ /* SPDX-FileCopyrightText: 2008-2010 Volker Lanz SPDX-FileCopyrightText: 2008 Laurent Montel - SPDX-FileCopyrightText: 2013-2019 Andrius Štikonas + SPDX-FileCopyrightText: 2013-2020 Andrius Štikonas SPDX-FileCopyrightText: 2015 Chris Campbell SPDX-FileCopyrightText: 2015 Teo Mrnjavac SPDX-FileCopyrightText: 2020 Gaël PORTAY @@ -96,6 +96,8 @@ public: return false; /**< @return always false for Partition */ } + const PartitionTable* partitionTable() const; + PartitionNode* parent() override { return m_Parent; /**< @return the Partition's parent PartitionNode */ } diff --git a/src/ops/resizeoperation.cpp b/src/ops/resizeoperation.cpp index 0aedb66..5e99c40 100644 --- a/src/ops/resizeoperation.cpp +++ b/src/ops/resizeoperation.cpp @@ -1,6 +1,6 @@ /* SPDX-FileCopyrightText: 2008-2012 Volker Lanz - SPDX-FileCopyrightText: 2012-2018 Andrius Štikonas + SPDX-FileCopyrightText: 2012-2020 Andrius Štikonas SPDX-FileCopyrightText: 2015 Teo Mrnjavac SPDX-FileCopyrightText: 2016 Chantara Tith SPDX-FileCopyrightText: 2018 Caio Jordão Carvalho @@ -326,6 +326,10 @@ bool ResizeOperation::canGrow(const Partition* p) if (p == nullptr) return false; + // Whole block device filesystems cannot be resized + if (p->partitionTable()->type() == PartitionTable::TableType::none) + return false; + if (isLVMPVinNewlyVG(p)) return false; @@ -348,6 +352,10 @@ bool ResizeOperation::canShrink(const Partition* p) if (p == nullptr) return false; + // Whole block device filesystems cannot be resized + if (p->partitionTable()->type() == PartitionTable::TableType::none) + return false; + if (isLVMPVinNewlyVG(p)) return false; @@ -373,6 +381,10 @@ bool ResizeOperation::canMove(const Partition* p) if (p == nullptr) return false; + // Whole block device filesystems cannot be moved + if (p->partitionTable()->type() == PartitionTable::TableType::none) + return false; + if (isLVMPVinNewlyVG(p)) return false;