File indexing completed on 2024-05-05 05:48:52
0001 /* 0002 SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de> 0003 SPDX-FileCopyrightText: 2014-2016 Andrius Štikonas <andrius@stikonas.eu> 0004 SPDX-FileCopyrightText: 2015 Chris Campbell <c.j.campbell@ed.ac.uk> 0005 SPDX-FileCopyrightText: 2018 Caio Jordão Carvalho <caiojcarvalho@gmail.com> 0006 0007 SPDX-License-Identifier: GPL-3.0-or-later 0008 */ 0009 0010 #ifndef KPMCORE_RESIZEOPERATION_H 0011 #define KPMCORE_RESIZEOPERATION_H 0012 0013 #include "util/libpartitionmanagerexport.h" 0014 0015 #include "ops/operation.h" 0016 0017 #include "core/partition.h" 0018 0019 #include <QString> 0020 0021 class Device; 0022 class OperationStack; 0023 class Report; 0024 0025 class CheckFileSystemJob; 0026 class SetPartGeometryJob; 0027 class ResizeFileSystemJob; 0028 class SetPartGeometryJob; 0029 class SetPartGeometryJob; 0030 class MoveFileSystemJob; 0031 class ResizeFileSystemJob; 0032 class CheckFileSystemJob; 0033 0034 /** Resizes a Partition and FileSystem. 0035 0036 Resize the given Partition and its FileSystem on the given Device so they start with the 0037 given new start sector and end with the given new last sector. 0038 0039 @author Volker Lanz <vl@fidra.de> 0040 */ 0041 class LIBKPMCORE_EXPORT ResizeOperation : public Operation 0042 { 0043 friend class OperationStack; 0044 0045 Q_DISABLE_COPY(ResizeOperation) 0046 0047 protected: 0048 /** A ResizeOperation can do a combination of things; this enum is used to determine what 0049 actually is going to be done. It is used so the ResizeOperation can describe itself and 0050 when it's actually executed. */ 0051 enum ResizeAction { 0052 None = 0, /**< Nothing */ 0053 MoveLeft = 1, /**< Move to the left */ 0054 MoveRight = 2, /**< Move to the right */ 0055 Grow = 4, /**< Grow */ 0056 Shrink = 8, /**< Shrink */ 0057 MoveLeftGrow = 5, /**< Move to the left then grow */ 0058 MoveRightGrow = 6, /**< Move to the right then grow */ 0059 MoveLeftShrink = 9, /**< Shrink then move to the left */ 0060 MoveRightShrink = 10 /**< Shrink then move to the right */ 0061 }; 0062 0063 public: 0064 ResizeOperation(Device& d, Partition& p, qint64 newfirst, qint64 newlast); 0065 0066 public: 0067 QString iconName() const override { 0068 return QStringLiteral("arrow-right-double"); 0069 } 0070 QString description() const override; 0071 bool execute(Report& parent) override; 0072 void preview() override; 0073 void undo() override; 0074 0075 bool targets(const Device& d) const override; 0076 bool targets(const Partition& p) const override; 0077 0078 static bool canGrow(const Partition* p); 0079 static bool canShrink(const Partition* p); 0080 static bool canMove(const Partition* p); 0081 0082 protected: 0083 Device& targetDevice() { 0084 return m_TargetDevice; 0085 } 0086 const Device& targetDevice() const { 0087 return m_TargetDevice; 0088 } 0089 0090 Partition& partition() { 0091 return m_Partition; 0092 } 0093 const Partition& partition() const { 0094 return m_Partition; 0095 } 0096 0097 bool shrink(Report& report); 0098 bool move(Report& report); 0099 bool grow(Report& report); 0100 0101 ResizeAction resizeAction() const; 0102 0103 qint64 origFirstSector() const { 0104 return m_OrigFirstSector; 0105 } 0106 qint64 origLastSector() const { 0107 return m_OrigLastSector; 0108 } 0109 qint64 origLength() const { 0110 return origLastSector() - origFirstSector() + 1; 0111 } 0112 0113 qint64 newFirstSector() const { 0114 return m_NewFirstSector; 0115 } 0116 qint64 newLastSector() const { 0117 return m_NewLastSector; 0118 } 0119 qint64 newLength() const { 0120 return newLastSector() - newFirstSector() + 1; 0121 } 0122 0123 CheckFileSystemJob* checkOriginalJob() { 0124 return m_CheckOriginalJob; 0125 } 0126 SetPartGeometryJob* moveExtendedJob() { 0127 return m_MoveExtendedJob; 0128 } 0129 ResizeFileSystemJob* shrinkResizeJob() { 0130 return m_ShrinkResizeJob; 0131 } 0132 SetPartGeometryJob* shrinkSetGeomJob() { 0133 return m_ShrinkSetGeomJob; 0134 } 0135 SetPartGeometryJob* moveSetGeomJob() { 0136 return m_MoveSetGeomJob; 0137 } 0138 MoveFileSystemJob* moveFileSystemJob() { 0139 return m_MoveFileSystemJob; 0140 } 0141 ResizeFileSystemJob* growResizeJob() { 0142 return m_GrowResizeJob; 0143 } 0144 SetPartGeometryJob* growSetGeomJob() { 0145 return m_GrowSetGeomJob; 0146 } 0147 CheckFileSystemJob* checkResizedJob() { 0148 return m_CheckResizedJob; 0149 } 0150 0151 private: 0152 static bool isLVMPVinNewlyVG(const Partition* p); 0153 0154 private: 0155 Device& m_TargetDevice; 0156 Partition& m_Partition; 0157 const qint64 m_OrigFirstSector; 0158 const qint64 m_OrigLastSector; 0159 qint64 m_NewFirstSector; 0160 qint64 m_NewLastSector; 0161 CheckFileSystemJob* m_CheckOriginalJob; 0162 SetPartGeometryJob* m_MoveExtendedJob; 0163 ResizeFileSystemJob* m_ShrinkResizeJob; 0164 SetPartGeometryJob* m_ShrinkSetGeomJob; 0165 SetPartGeometryJob* m_MoveSetGeomJob; 0166 MoveFileSystemJob* m_MoveFileSystemJob; 0167 ResizeFileSystemJob* m_GrowResizeJob; 0168 SetPartGeometryJob* m_GrowSetGeomJob; 0169 CheckFileSystemJob* m_CheckResizedJob; 0170 }; 0171 0172 #endif