sfdisk: Move GPT Attributes functions to new sfdiskgptattributes
This centralizes the two get functions related to GPT Attributes.
This commit is contained in:
parent
547fa609fe
commit
6f4b883130
|
@ -16,6 +16,7 @@
|
||||||
set (pmsfdiskbackendplugin_SRCS
|
set (pmsfdiskbackendplugin_SRCS
|
||||||
sfdiskbackend.cpp
|
sfdiskbackend.cpp
|
||||||
sfdiskdevice.cpp
|
sfdiskdevice.cpp
|
||||||
|
sfdiskgptattributes.cpp
|
||||||
sfdiskpartitiontable.cpp
|
sfdiskpartitiontable.cpp
|
||||||
${CMAKE_SOURCE_DIR}/src/backend/corebackenddevice.cpp
|
${CMAKE_SOURCE_DIR}/src/backend/corebackenddevice.cpp
|
||||||
${CMAKE_SOURCE_DIR}/src/core/copysourcedevice.cpp
|
${CMAKE_SOURCE_DIR}/src/core/copysourcedevice.cpp
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
#include "plugins/sfdisk/sfdiskbackend.h"
|
#include "plugins/sfdisk/sfdiskbackend.h"
|
||||||
#include "plugins/sfdisk/sfdiskdevice.h"
|
#include "plugins/sfdisk/sfdiskdevice.h"
|
||||||
|
#include "plugins/sfdisk/sfdiskgptattributes.h"
|
||||||
|
|
||||||
#include "core/copysourcedevice.h"
|
#include "core/copysourcedevice.h"
|
||||||
#include "core/copytargetbytearray.h"
|
#include "core/copytargetbytearray.h"
|
||||||
|
@ -305,17 +306,8 @@ void SfdiskBackend::scanDevicePartitions(Device& d, const QJsonArray& jsonPartit
|
||||||
part->setLabel(partitionObject[QLatin1String("name")].toString());
|
part->setLabel(partitionObject[QLatin1String("name")].toString());
|
||||||
part->setUUID(partitionObject[QLatin1String("uuid")].toString());
|
part->setUUID(partitionObject[QLatin1String("uuid")].toString());
|
||||||
part->setType(partitionObject[QLatin1String("type")].toString());
|
part->setType(partitionObject[QLatin1String("type")].toString());
|
||||||
quint64 attrs = 0;
|
QString attrs = partitionObject[QLatin1String("attrs")].toString();
|
||||||
for (auto& attr: QStringList(partitionObject[QLatin1String("attrs")].toString().split(QLatin1Char(' '))))
|
part->setAttributes(SfdiskGptAttributes::toULongLong(attrs.split(QLatin1Char(' '))));
|
||||||
if (attr.compare(QStringLiteral("RequiredPartition")) == 0)
|
|
||||||
attrs |= 0x0000000000000001;
|
|
||||||
else if (attr.compare(QStringLiteral("NoBlockIOProtocol")) == 0)
|
|
||||||
attrs |= 0x0000000000000002;
|
|
||||||
else if (attr.compare(QStringLiteral("LegacyBIOSBootable")) == 0)
|
|
||||||
attrs |= 0x0000000000000004;
|
|
||||||
else if (attr.startsWith(QStringLiteral("GUID:")))
|
|
||||||
attrs |= 1ULL << QStringRef(&attr, 5, attr.length() - 5).toULongLong();
|
|
||||||
part->setAttributes(attrs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fs->supportGetUUID() != FileSystem::cmdSupportNone)
|
if (fs->supportGetUUID() != FileSystem::cmdSupportNone)
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*************************************************************************
|
||||||
|
* Copyright (C) 2020 by Gaël PORTAY <gael.portay@collabora.com> *
|
||||||
|
* *
|
||||||
|
* 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/sfdiskgptattributes.h"
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
const static QString requiredPartition = QStringLiteral("RequiredPartition");
|
||||||
|
const static QString noBlockIoProtocol = QStringLiteral("NoBlockIOProtocol");
|
||||||
|
const static QString legacyBiosBootable = QStringLiteral("LegacyBIOSBootable");
|
||||||
|
const static QString guid = QStringLiteral("GUID:");
|
||||||
|
|
||||||
|
quint64 SfdiskGptAttributes::toULongLong(const QStringList& attrs)
|
||||||
|
{
|
||||||
|
quint64 attributes = 0;
|
||||||
|
for (auto& attr: attrs)
|
||||||
|
if (attr.compare(requiredPartition) == 0)
|
||||||
|
attributes |= 0x1ULL;
|
||||||
|
else if (attr.compare(noBlockIoProtocol) == 0)
|
||||||
|
attributes |= 0x2ULL;
|
||||||
|
else if (attr.compare(legacyBiosBootable) == 0)
|
||||||
|
attributes |= 0x4ULL;
|
||||||
|
else if (attr.startsWith(guid))
|
||||||
|
attributes |= 1ULL << QStringRef(&attr, guid.length(), attr.length() - guid.length()).toULongLong();
|
||||||
|
|
||||||
|
return attributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList SfdiskGptAttributes::toStringList(quint64 attrs)
|
||||||
|
{
|
||||||
|
QStringList list;
|
||||||
|
if (attrs & 0x1)
|
||||||
|
list += requiredPartition;
|
||||||
|
if (attrs & 0x2)
|
||||||
|
list += noBlockIoProtocol;
|
||||||
|
if (attrs & 0x4)
|
||||||
|
list += legacyBiosBootable;
|
||||||
|
for (int bit = 48; bit < 64; bit++)
|
||||||
|
if (attrs & (1 << bit))
|
||||||
|
list += guid + QString::number(bit);
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*************************************************************************
|
||||||
|
* Copyright (C) 2020 by Gaël PORTAY <gael.portay@collabora.com> *
|
||||||
|
* *
|
||||||
|
* 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(SFDISKGPTATTRIBUTES__H)
|
||||||
|
|
||||||
|
#define SFDISKGPTATTRIBUTES__H
|
||||||
|
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
|
class QStringList;
|
||||||
|
|
||||||
|
/** Sfdisk GPT Attributes helpers.
|
||||||
|
@author Gaël PORTAY <gael.portay@collabora.com>
|
||||||
|
*/
|
||||||
|
class SfdiskGptAttributes
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static quint64 toULongLong(const QStringList& attrs);
|
||||||
|
static QStringList toStringList(quint64 attrs);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -16,6 +16,7 @@
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
#include "plugins/sfdisk/sfdiskpartitiontable.h"
|
#include "plugins/sfdisk/sfdiskpartitiontable.h"
|
||||||
|
#include "plugins/sfdisk/sfdiskgptattributes.h"
|
||||||
|
|
||||||
#include "backend/corebackend.h"
|
#include "backend/corebackend.h"
|
||||||
#include "backend/corebackendmanager.h"
|
#include "backend/corebackendmanager.h"
|
||||||
|
@ -213,22 +214,6 @@ static QLatin1String getPartitionType(FileSystem::Type t, PartitionTable::TableT
|
||||||
return QLatin1String();
|
return QLatin1String();
|
||||||
}
|
}
|
||||||
|
|
||||||
static QStringList getAttributeList(quint64 attrs)
|
|
||||||
{
|
|
||||||
QStringList list;
|
|
||||||
if (attrs & 0x01)
|
|
||||||
list += QStringLiteral("RequiredPartition");
|
|
||||||
if (attrs & 0x02)
|
|
||||||
list += QStringLiteral("NoBlockIOProtocol");
|
|
||||||
if (attrs & 0x04)
|
|
||||||
list += QStringLiteral("LegacyBIOSBootable");
|
|
||||||
for (int bit = 48; bit < 64; bit++)
|
|
||||||
if (attrs & (1 << bit))
|
|
||||||
list += QString::number(bit);
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SfdiskPartitionTable::setPartitionLabel(Report& report, const Partition& partition, const QString& label)
|
bool SfdiskPartitionTable::setPartitionLabel(Report& report, const Partition& partition, const QString& label)
|
||||||
{
|
{
|
||||||
if (label.isEmpty())
|
if (label.isEmpty())
|
||||||
|
@ -264,7 +249,7 @@ bool SfdiskPartitionTable::setPartitionUUID(Report& report, const Partition& par
|
||||||
|
|
||||||
bool SfdiskPartitionTable::setPartitionAttributes(Report& report, const Partition& partition, quint64 attrs)
|
bool SfdiskPartitionTable::setPartitionAttributes(Report& report, const Partition& partition, quint64 attrs)
|
||||||
{
|
{
|
||||||
QStringList attributes = getAttributeList(attrs);
|
QStringList attributes = SfdiskGptAttributes::toStringList(attrs);
|
||||||
if (attributes.isEmpty())
|
if (attributes.isEmpty())
|
||||||
return true;
|
return true;
|
||||||
ExternalCommand sfdiskCommand(report, QStringLiteral("sfdisk"), { QStringLiteral("--part-attrs"), m_device->deviceNode(), QString::number(partition.number()),
|
ExternalCommand sfdiskCommand(report, QStringLiteral("sfdisk"), { QStringLiteral("--part-attrs"), m_device->deviceNode(), QString::number(partition.number()),
|
||||||
|
|
Loading…
Reference in New Issue