Move setFlags function from CoreBackendPartition to CoreBackendPartitionTable.
setFlags function now takes additional argument const Partition& partition. This allows us to completely remove CoreBackendPartition class. Remove getPartitionBySector and getExtendedPartitions. These functions were designed around libparted API and are not very convenient with other backends.
This commit is contained in:
parent
0d88e26c8c
commit
80de99fc73
|
@ -2,7 +2,6 @@ set(BACKEND_SRC
|
|||
backend/corebackendmanager.cpp
|
||||
backend/corebackenddevice.cpp
|
||||
backend/corebackend.cpp
|
||||
backend/corebackendpartition.cpp
|
||||
backend/corebackendpartitiontable.cpp
|
||||
)
|
||||
|
||||
|
@ -10,6 +9,5 @@ set(BACKEND_LIB_HDRS
|
|||
backend/corebackend.h
|
||||
backend/corebackenddevice.h
|
||||
backend/corebackendmanager.h
|
||||
backend/corebackendpartition.h
|
||||
backend/corebackendpartitiontable.h
|
||||
)
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
/*************************************************************************
|
||||
* Copyright (C) 2010 by Volker Lanz <vl@fidra.de> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 3 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
||||
*************************************************************************/
|
||||
|
||||
#include "backend/corebackendpartition.h"
|
||||
|
||||
|
||||
CoreBackendPartition::CoreBackendPartition()
|
||||
{
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
/*************************************************************************
|
||||
* Copyright (C) 2010 by Volker Lanz <vl@fidra.de> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 3 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
||||
*************************************************************************/
|
||||
|
||||
#if !defined(KPMCORE_COREBACKENDPARTITION_H)
|
||||
|
||||
#define KPMCORE_COREBACKENDPARTITION_H
|
||||
|
||||
#include "util/libpartitionmanagerexport.h"
|
||||
|
||||
#include "core/partitiontable.h"
|
||||
|
||||
class Report;
|
||||
|
||||
/**
|
||||
* Represents a partition in the backend plugin.
|
||||
* @author Volker Lanz <vl@fidra.de>
|
||||
*/
|
||||
class LIBKPMCORE_EXPORT CoreBackendPartition
|
||||
{
|
||||
public:
|
||||
CoreBackendPartition();
|
||||
virtual ~CoreBackendPartition() {}
|
||||
|
||||
public:
|
||||
/**
|
||||
* Set a flag for the partition
|
||||
* @param report the Report to write information to
|
||||
* @param flag the flag to set
|
||||
* @param state the state to set the flag to (i.e., on or off)
|
||||
* @return true on success
|
||||
*/
|
||||
virtual bool setFlag(Report& report, PartitionTable::Flag flag, bool state) = 0;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -19,9 +19,9 @@
|
|||
|
||||
#define KPMCORE_COREBACKENDPARTITIONTABLE_H
|
||||
|
||||
#include "util/libpartitionmanagerexport.h"
|
||||
|
||||
#include "core/partitiontable.h"
|
||||
#include "fs/filesystem.h"
|
||||
#include "util/libpartitionmanagerexport.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
|
@ -52,17 +52,6 @@ public:
|
|||
*/
|
||||
virtual bool commit(quint32 timeout = 10) = 0;
|
||||
|
||||
/**
|
||||
* @return pointer to the extended partition as a CoreBackendPartition or nullptr if there is none
|
||||
*/
|
||||
virtual CoreBackendPartition* getExtendedPartition() = 0;
|
||||
|
||||
/**
|
||||
* @param sector sector the partition occupies
|
||||
* @return the CoreBackendPartition to occupy the given sector or nullptr if not found
|
||||
*/
|
||||
virtual CoreBackendPartition* getPartitionBySector(qint64 sector) = 0;
|
||||
|
||||
/**
|
||||
* Delete a partition.
|
||||
* @param report the report to write information to
|
||||
|
@ -123,6 +112,15 @@ public:
|
|||
* @return true on success
|
||||
*/
|
||||
virtual bool setPartitionSystemType(Report& report, const Partition& partition) = 0;
|
||||
|
||||
/**
|
||||
* Set a flag for the partition
|
||||
* @param report the Report to write information to
|
||||
* @param flag the flag to set
|
||||
* @param state the state to set the flag to (i.e., on or off)
|
||||
* @return true on success
|
||||
*/
|
||||
virtual bool setFlag(Report& report, const Partition& partition, PartitionTable::Flag flag, bool state) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include "backend/corebackend.h"
|
||||
#include "backend/corebackendmanager.h"
|
||||
#include "backend/corebackenddevice.h"
|
||||
#include "backend/corebackendpartition.h"
|
||||
#include "backend/corebackendpartitiontable.h"
|
||||
|
||||
#include "core/device.h"
|
||||
|
@ -63,29 +62,18 @@ bool SetPartFlagsJob::run(Report& parent)
|
|||
CoreBackendPartitionTable* backendPartitionTable = backendDevice->openPartitionTable();
|
||||
|
||||
if (backendPartitionTable) {
|
||||
CoreBackendPartition* backendPartition = (partition().roles().has(PartitionRole::Extended))
|
||||
? backendPartitionTable->getExtendedPartition()
|
||||
: backendPartitionTable->getPartitionBySector(partition().firstSector());
|
||||
int count = 0;
|
||||
|
||||
if (backendPartition) {
|
||||
int count = 0;
|
||||
for (const auto &f : PartitionTable::flagList()) {
|
||||
emit progress(++count);
|
||||
|
||||
for (const auto &f : PartitionTable::flagList()) {
|
||||
emit progress(++count);
|
||||
const bool state = (flags() & f) ? true : false;
|
||||
|
||||
const bool state = (flags() & f) ? true : false;
|
||||
if (!backendPartitionTable->setFlag(*report, partition(), f, state)) {
|
||||
report->line() << xi18nc("@info:progress", "There was an error setting flag %1 for partition <filename>%2</filename> to state %3.", PartitionTable::flagName(f), partition().deviceNode(), state ? xi18nc("@info:progress flag turned on, active", "on") : xi18nc("@info:progress flag turned off, inactive", "off"));
|
||||
|
||||
if (!backendPartition->setFlag(*report, f, state)) {
|
||||
report->line() << xi18nc("@info:progress", "There was an error setting flag %1 for partition <filename>%2</filename> to state %3.", PartitionTable::flagName(f), partition().deviceNode(), state ? xi18nc("@info:progress flag turned on, active", "on") : xi18nc("@info:progress flag turned off, inactive", "off"));
|
||||
|
||||
rval = false;
|
||||
}
|
||||
rval = false;
|
||||
}
|
||||
|
||||
delete backendPartition;
|
||||
} else {
|
||||
report->line() << xi18nc("@info:progress", "Could not find partition <filename>%1</filename> on device <filename>%2</filename> to set partition flags.", partition().deviceNode(), device().deviceNode());
|
||||
rval = false;
|
||||
}
|
||||
|
||||
if (rval)
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
set (pmdummybackendplugin_SRCS
|
||||
dummybackend.cpp
|
||||
dummydevice.cpp
|
||||
dummypartition.cpp
|
||||
dummypartitiontable.cpp
|
||||
)
|
||||
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
/*************************************************************************
|
||||
* Copyright (C) 2010 by Volker Lanz <vl@fidra.de> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 3 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
||||
*************************************************************************/
|
||||
|
||||
#include "plugins/dummy/dummypartition.h"
|
||||
#include "plugins/dummy/dummybackend.h"
|
||||
|
||||
#include "util/report.h"
|
||||
|
||||
DummyPartition::DummyPartition() :
|
||||
CoreBackendPartition()
|
||||
{
|
||||
}
|
||||
|
||||
bool DummyPartition::setFlag(Report& report, PartitionTable::Flag partitionManagerFlag, bool state)
|
||||
{
|
||||
Q_UNUSED(report);
|
||||
Q_UNUSED(partitionManagerFlag);
|
||||
Q_UNUSED(state);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
/*************************************************************************
|
||||
* Copyright (C) 2010 by Volker Lanz <vl@fidra.de> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 3 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
||||
*************************************************************************/
|
||||
|
||||
#if !defined(KPMCORE_DUMMYPARTITION_H)
|
||||
|
||||
#define KPMCORE_DUMMYPARTITION_H
|
||||
|
||||
#include "backend/corebackendpartition.h"
|
||||
|
||||
#include "core/partitiontable.h"
|
||||
|
||||
class Report;
|
||||
|
||||
class DummyPartition : public CoreBackendPartition
|
||||
{
|
||||
Q_DISABLE_COPY(DummyPartition)
|
||||
|
||||
public:
|
||||
DummyPartition();
|
||||
|
||||
public:
|
||||
bool setFlag(Report& report, PartitionTable::Flag flag, bool state) override;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
|
@ -16,7 +16,6 @@
|
|||
*************************************************************************/
|
||||
|
||||
#include "plugins/dummy/dummypartitiontable.h"
|
||||
#include "plugins/dummy/dummypartition.h"
|
||||
#include "plugins/dummy/dummybackend.h"
|
||||
|
||||
#include "core/partition.h"
|
||||
|
@ -43,71 +42,59 @@ bool DummyPartitionTable::open()
|
|||
|
||||
bool DummyPartitionTable::commit(quint32 timeout)
|
||||
{
|
||||
Q_UNUSED(timeout);
|
||||
Q_UNUSED(timeout)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
CoreBackendPartition* DummyPartitionTable::getExtendedPartition()
|
||||
{
|
||||
return new DummyPartition();
|
||||
}
|
||||
|
||||
CoreBackendPartition* DummyPartitionTable::getPartitionBySector(qint64 sector)
|
||||
{
|
||||
Q_UNUSED(sector);
|
||||
|
||||
return new DummyPartition();
|
||||
}
|
||||
|
||||
QString DummyPartitionTable::createPartition(Report& report, const Partition& partition)
|
||||
{
|
||||
Q_UNUSED(report);
|
||||
Q_UNUSED(partition);
|
||||
Q_UNUSED(report)
|
||||
Q_UNUSED(partition)
|
||||
|
||||
return QStringLiteral("dummy");
|
||||
}
|
||||
|
||||
bool DummyPartitionTable::deletePartition(Report& report, const Partition& partition)
|
||||
{
|
||||
Q_UNUSED(report);
|
||||
Q_UNUSED(partition);
|
||||
Q_UNUSED(report)
|
||||
Q_UNUSED(partition)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DummyPartitionTable::updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end)
|
||||
{
|
||||
Q_UNUSED(report);
|
||||
Q_UNUSED(partition);
|
||||
Q_UNUSED(sector_start);
|
||||
Q_UNUSED(sector_end);
|
||||
Q_UNUSED(report)
|
||||
Q_UNUSED(partition)
|
||||
Q_UNUSED(sector_start)
|
||||
Q_UNUSED(sector_end)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DummyPartitionTable::clobberFileSystem(Report& report, const Partition& partition)
|
||||
{
|
||||
Q_UNUSED(report);
|
||||
Q_UNUSED(partition);
|
||||
Q_UNUSED(report)
|
||||
Q_UNUSED(partition)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DummyPartitionTable::resizeFileSystem(Report& report, const Partition& partition, qint64 newLength)
|
||||
{
|
||||
Q_UNUSED(report);
|
||||
Q_UNUSED(partition);
|
||||
Q_UNUSED(newLength);
|
||||
Q_UNUSED(report)
|
||||
Q_UNUSED(partition)
|
||||
Q_UNUSED(newLength)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
FileSystem::Type DummyPartitionTable::detectFileSystemBySector(Report& report, const Device& device, qint64 sector)
|
||||
{
|
||||
Q_UNUSED(report);
|
||||
Q_UNUSED(device);
|
||||
Q_UNUSED(sector);
|
||||
Q_UNUSED(report)
|
||||
Q_UNUSED(device)
|
||||
Q_UNUSED(sector)
|
||||
|
||||
FileSystem::Type rval = FileSystem::Unknown;
|
||||
return rval;
|
||||
|
@ -115,8 +102,18 @@ FileSystem::Type DummyPartitionTable::detectFileSystemBySector(Report& report, c
|
|||
|
||||
bool DummyPartitionTable::setPartitionSystemType(Report& report, const Partition& partition)
|
||||
{
|
||||
Q_UNUSED(report);
|
||||
Q_UNUSED(partition);
|
||||
Q_UNUSED(report)
|
||||
Q_UNUSED(partition)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DummyPartitionTable::setFlag(Report& report, const Partition& partition, PartitionTable::Flag partitionManagerFlag, bool state)
|
||||
{
|
||||
Q_UNUSED(report)
|
||||
Q_UNUSED(partition)
|
||||
Q_UNUSED(partitionManagerFlag)
|
||||
Q_UNUSED(state)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -40,9 +40,6 @@ public:
|
|||
|
||||
bool commit(quint32 timeout = 10) override;
|
||||
|
||||
CoreBackendPartition* getExtendedPartition() override;
|
||||
CoreBackendPartition* getPartitionBySector(qint64 sector) override;
|
||||
|
||||
QString createPartition(Report& report, const Partition& partition) override;
|
||||
bool deletePartition(Report& report, const Partition& partition) override;
|
||||
bool updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end) override;
|
||||
|
@ -50,6 +47,7 @@ public:
|
|||
bool resizeFileSystem(Report& report, const Partition& partition, qint64 newLength) override;
|
||||
FileSystem::Type detectFileSystemBySector(Report& report, const Device& device, qint64 sector) override;
|
||||
bool setPartitionSystemType(Report& report, const Partition& partition) override;
|
||||
bool setFlag(Report& report, const Partition& partition, PartitionTable::Flag partitionManagerFlag, bool state) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -28,7 +28,6 @@ include_directories(${LIBPARTED_INCLUDE_DIR})
|
|||
set (pmlibpartedbackendplugin_SRCS
|
||||
libpartedbackend.cpp
|
||||
libparteddevice.cpp
|
||||
libpartedpartition.cpp
|
||||
libpartedpartitiontable.cpp
|
||||
)
|
||||
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
/*************************************************************************
|
||||
* Copyright (C) 2010 by Volker Lanz <vl@fidra.de> *
|
||||
* Copyright (C) 2016 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 3 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
||||
*************************************************************************/
|
||||
|
||||
#include "plugins/libparted/libpartedpartition.h"
|
||||
#include "plugins/libparted/libpartedbackend.h"
|
||||
|
||||
#include "util/report.h"
|
||||
|
||||
#include <KLocalizedString>
|
||||
|
||||
LibPartedPartition::LibPartedPartition(PedPartition* ped_partition) :
|
||||
CoreBackendPartition(),
|
||||
m_PedPartition(ped_partition)
|
||||
{
|
||||
}
|
||||
|
||||
bool LibPartedPartition::setFlag(Report& report, PartitionTable::Flag partitionManagerFlag, bool state)
|
||||
{
|
||||
Q_ASSERT(pedPartition() != nullptr);
|
||||
|
||||
const PedPartitionFlag f = LibPartedBackend::getPedFlag(partitionManagerFlag);
|
||||
|
||||
// ignore flags that don't exist for this partition
|
||||
if (!ped_partition_is_flag_available(pedPartition(), f)) {
|
||||
report.line() << xi18nc("@info:progress", "The flag \"%1\" is not available on the partition's partition table.", PartitionTable::flagName(partitionManagerFlag));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Workaround: libparted claims the hidden flag is available for extended partitions, but
|
||||
// throws an error when we try to set or clear it. So skip this combination.
|
||||
if (pedPartition()->type == PED_PARTITION_EXTENDED && partitionManagerFlag == PartitionTable::FlagHidden)
|
||||
return true;
|
||||
|
||||
if (!ped_partition_set_flag(pedPartition(), f, state ? 1 : 0))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
/*************************************************************************
|
||||
* Copyright (C) 2010 by Volker Lanz <vl@fidra.de> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 3 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
||||
*************************************************************************/
|
||||
|
||||
#if !defined(KPMCORE_LIBPARTEDPARTITION_H)
|
||||
|
||||
#define KPMCORE_LIBPARTEDPARTITION_H
|
||||
|
||||
#include "backend/corebackendpartition.h"
|
||||
|
||||
#include "core/partitiontable.h"
|
||||
|
||||
#include <parted/parted.h>
|
||||
|
||||
class Report;
|
||||
|
||||
class LibPartedPartition : public CoreBackendPartition
|
||||
{
|
||||
Q_DISABLE_COPY(LibPartedPartition)
|
||||
|
||||
public:
|
||||
LibPartedPartition(PedPartition* ped_partition);
|
||||
|
||||
public:
|
||||
bool setFlag(Report& report, PartitionTable::Flag flag, bool state) override;
|
||||
|
||||
private:
|
||||
PedPartition* pedPartition() {
|
||||
return m_PedPartition;
|
||||
}
|
||||
|
||||
private:
|
||||
PedPartition* m_PedPartition;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -17,7 +17,6 @@
|
|||
*************************************************************************/
|
||||
|
||||
#include "plugins/libparted/libpartedpartitiontable.h"
|
||||
#include "plugins/libparted/libpartedpartition.h"
|
||||
#include "plugins/libparted/libpartedbackend.h"
|
||||
|
||||
#include "backend/corebackend.h"
|
||||
|
@ -76,26 +75,6 @@ bool LibPartedPartitionTable::commit(PedDisk* pd, quint32 timeout)
|
|||
return rval;
|
||||
}
|
||||
|
||||
CoreBackendPartition* LibPartedPartitionTable::getExtendedPartition()
|
||||
{
|
||||
PedPartition* pedPartition = ped_disk_extended_partition(pedDisk());
|
||||
|
||||
if (pedPartition == nullptr)
|
||||
return nullptr;
|
||||
|
||||
return new LibPartedPartition(pedPartition);
|
||||
}
|
||||
|
||||
CoreBackendPartition* LibPartedPartitionTable::getPartitionBySector(qint64 sector)
|
||||
{
|
||||
PedPartition* pedPartition = ped_disk_get_partition_by_sector(pedDisk(), sector);
|
||||
|
||||
if (pedPartition == nullptr)
|
||||
return nullptr;
|
||||
|
||||
return new LibPartedPartition(pedPartition);
|
||||
}
|
||||
|
||||
static const struct {
|
||||
FileSystem::Type type;
|
||||
QString name;
|
||||
|
@ -302,9 +281,9 @@ bool LibPartedPartitionTable::resizeFileSystem(Report& report, const Partition&
|
|||
} else
|
||||
report.line() << xi18nc("@info:progress", "Could not read geometry for partition <filename>%1</filename> while trying to resize the file system.", partition.deviceNode());
|
||||
#else
|
||||
Q_UNUSED(report);
|
||||
Q_UNUSED(partition);
|
||||
Q_UNUSED(newLength);
|
||||
Q_UNUSED(report)
|
||||
Q_UNUSED(partition)
|
||||
Q_UNUSED(newLength)
|
||||
#endif
|
||||
|
||||
return rval;
|
||||
|
@ -344,3 +323,34 @@ bool LibPartedPartitionTable::setPartitionSystemType(Report& report, const Parti
|
|||
return ped_partition_set_system(pedPartition, pedFsType) != 0;
|
||||
}
|
||||
|
||||
bool LibPartedPartitionTable::setFlag(Report& report, const Partition& partition, PartitionTable::Flag partitionManagerFlag, bool state)
|
||||
{
|
||||
PedPartition* pedPartition;
|
||||
if (partition.roles().has(PartitionRole::Extended))
|
||||
pedPartition = ped_disk_extended_partition(pedDisk());
|
||||
else
|
||||
pedPartition = ped_disk_get_partition_by_sector(pedDisk(), partition.firstSector());
|
||||
if (pedPartition == nullptr) {
|
||||
QString deviceNode = QString::fromUtf8(pedDevice()->path);
|
||||
report.line() << xi18nc("@info:progress", "Could not find partition <filename>%1</filename> on device <filename>%2</filename> to set partition flags.", partition.deviceNode(), deviceNode);
|
||||
return false;
|
||||
}
|
||||
|
||||
const PedPartitionFlag f = LibPartedBackend::getPedFlag(partitionManagerFlag);
|
||||
|
||||
// ignore flags that don't exist for this partition
|
||||
if (!ped_partition_is_flag_available(pedPartition, f)) {
|
||||
report.line() << xi18nc("@info:progress", "The flag \"%1\" is not available on the partition's partition table.", PartitionTable::flagName(partitionManagerFlag));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Workaround: libparted claims the hidden flag is available for extended partitions, but
|
||||
// throws an error when we try to set or clear it. So skip this combination.
|
||||
if (pedPartition->type == PED_PARTITION_EXTENDED && partitionManagerFlag == PartitionTable::FlagHidden)
|
||||
return true;
|
||||
|
||||
if (!ped_partition_set_flag(pedPartition, f, state ? 1 : 0))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -43,9 +43,6 @@ public:
|
|||
bool commit(quint32 timeout = 10) override;
|
||||
static bool commit(PedDisk* pd, quint32 timeout = 10);
|
||||
|
||||
CoreBackendPartition* getExtendedPartition() override;
|
||||
CoreBackendPartition* getPartitionBySector(qint64 sector) override;
|
||||
|
||||
QString createPartition(Report& report, const Partition& partition) override;
|
||||
bool deletePartition(Report& report, const Partition& partition) override;
|
||||
bool updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end) override;
|
||||
|
@ -53,6 +50,7 @@ public:
|
|||
bool resizeFileSystem(Report& report, const Partition& partition, qint64 newLength) override;
|
||||
FileSystem::Type detectFileSystemBySector(Report& report, const Device& device, qint64 sector) override;
|
||||
bool setPartitionSystemType(Report& report, const Partition& partition) override;
|
||||
bool setFlag(Report& report, const Partition& partition, PartitionTable::Flag partitionManagerFlag, bool state) override;
|
||||
|
||||
private:
|
||||
PedDevice* pedDevice() {
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
set (pmsfdiskbackendplugin_SRCS
|
||||
sfdiskbackend.cpp
|
||||
sfdiskdevice.cpp
|
||||
sfdiskpartition.cpp
|
||||
sfdiskpartitiontable.cpp
|
||||
)
|
||||
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
/*************************************************************************
|
||||
* Copyright (C) 2017 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 3 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
||||
*************************************************************************/
|
||||
|
||||
#include "plugins/sfdisk/sfdiskpartition.h"
|
||||
#include "plugins/sfdisk/sfdiskbackend.h"
|
||||
|
||||
#include "util/report.h"
|
||||
|
||||
SfdiskPartition::SfdiskPartition() :
|
||||
CoreBackendPartition()
|
||||
{
|
||||
}
|
||||
|
||||
bool SfdiskPartition::setFlag(Report& report, PartitionTable::Flag partitionManagerFlag, bool state)
|
||||
{
|
||||
Q_UNUSED(report);
|
||||
Q_UNUSED(partitionManagerFlag);
|
||||
Q_UNUSED(state);
|
||||
|
||||
return true;
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
/*************************************************************************
|
||||
* Copyright (C) 2017 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 3 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
||||
*************************************************************************/
|
||||
|
||||
#if !defined(SFDISKPARTITION__H)
|
||||
|
||||
#define SFDISKPARTITION__H
|
||||
|
||||
#include "backend/corebackendpartition.h"
|
||||
|
||||
#include "core/partitiontable.h"
|
||||
|
||||
class Report;
|
||||
|
||||
class SfdiskPartition : public CoreBackendPartition
|
||||
{
|
||||
Q_DISABLE_COPY(SfdiskPartition);
|
||||
|
||||
public:
|
||||
SfdiskPartition();
|
||||
|
||||
public:
|
||||
bool setFlag(Report& report, PartitionTable::Flag flag, bool state) override;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
|
@ -16,7 +16,6 @@
|
|||
*************************************************************************/
|
||||
|
||||
#include "plugins/sfdisk/sfdiskpartitiontable.h"
|
||||
#include "plugins/sfdisk/sfdiskpartition.h"
|
||||
|
||||
#include "backend/corebackend.h"
|
||||
#include "backend/corebackendmanager.h"
|
||||
|
@ -62,18 +61,6 @@ bool SfdiskPartitionTable::commit(quint32 timeout)
|
|||
return true;
|
||||
}
|
||||
|
||||
CoreBackendPartition* SfdiskPartitionTable::getExtendedPartition()
|
||||
{
|
||||
return new SfdiskPartition();
|
||||
}
|
||||
|
||||
CoreBackendPartition* SfdiskPartitionTable::getPartitionBySector(qint64 sector)
|
||||
{
|
||||
Q_UNUSED(sector);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QString SfdiskPartitionTable::createPartition(Report& report, const Partition& partition)
|
||||
{
|
||||
if ( !(partition.roles().has(PartitionRole::Extended) || partition.roles().has(PartitionRole::Logical) || partition.roles().has(PartitionRole::Primary) ) ) {
|
||||
|
@ -139,9 +126,9 @@ bool SfdiskPartitionTable::clobberFileSystem(Report& report, const Partition& pa
|
|||
bool SfdiskPartitionTable::resizeFileSystem(Report& report, const Partition& partition, qint64 newLength)
|
||||
{
|
||||
// sfdisk does not have any partition resize capabilities
|
||||
Q_UNUSED(report);
|
||||
Q_UNUSED(partition);
|
||||
Q_UNUSED(newLength);
|
||||
Q_UNUSED(report)
|
||||
Q_UNUSED(partition)
|
||||
Q_UNUSED(newLength)
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -171,8 +158,18 @@ FileSystem::Type SfdiskPartitionTable::detectFileSystemBySector(Report& report,
|
|||
|
||||
bool SfdiskPartitionTable::setPartitionSystemType(Report& report, const Partition& partition)
|
||||
{
|
||||
Q_UNUSED(report);
|
||||
Q_UNUSED(partition);
|
||||
Q_UNUSED(report)
|
||||
Q_UNUSED(partition)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SfdiskPartitionTable::setFlag(Report& report, const Partition& partition, PartitionTable::Flag partitionManagerFlag, bool state)
|
||||
{
|
||||
Q_UNUSED(report)
|
||||
Q_UNUSED(partition)
|
||||
Q_UNUSED(partitionManagerFlag)
|
||||
Q_UNUSED(state)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -40,9 +40,6 @@ public:
|
|||
|
||||
bool commit(quint32 timeout = 10) override;
|
||||
|
||||
CoreBackendPartition* getExtendedPartition() override;
|
||||
CoreBackendPartition* getPartitionBySector(qint64 sector) override;
|
||||
|
||||
QString createPartition(Report& report, const Partition& partition) override;
|
||||
bool deletePartition(Report& report, const Partition& partition) override;
|
||||
bool updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end) override;
|
||||
|
@ -50,6 +47,7 @@ public:
|
|||
bool resizeFileSystem(Report& report, const Partition& partition, qint64 newLength) override;
|
||||
FileSystem::Type detectFileSystemBySector(Report& report, const Device& device, qint64 sector) override;
|
||||
bool setPartitionSystemType(Report& report, const Partition& partition) override;
|
||||
bool setFlag(Report& report, const Partition& partition, PartitionTable::Flag flag, bool state) override;
|
||||
|
||||
private:
|
||||
QString m_deviceNode;
|
||||
|
|
Loading…
Reference in New Issue