File indexing completed on 2024-05-12 05:48:28
0001 /* 0002 SPDX-FileCopyrightText: 2020 Gaƫl PORTAY <gael.portay@collabora.com> 0003 0004 SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #include "plugins/sfdisk/sfdiskgptattributes.h" 0008 0009 #include <QString> 0010 #include <QStringList> 0011 #include <QStringView> 0012 0013 const static QString requiredPartition = QStringLiteral("RequiredPartition"); 0014 const static QString noBlockIoProtocol = QStringLiteral("NoBlockIOProtocol"); 0015 const static QString legacyBiosBootable = QStringLiteral("LegacyBIOSBootable"); 0016 const static QString guid = QStringLiteral("GUID:"); 0017 0018 quint64 SfdiskGptAttributes::toULongLong(const QStringList& attrs) 0019 { 0020 quint64 attributes = 0; 0021 for (auto& attr: attrs) 0022 if (attr.compare(requiredPartition) == 0) 0023 attributes |= 0x1ULL; 0024 else if (attr.compare(noBlockIoProtocol) == 0) 0025 attributes |= 0x2ULL; 0026 else if (attr.compare(legacyBiosBootable) == 0) 0027 attributes |= 0x4ULL; 0028 else if (attr.startsWith(guid)) 0029 attributes |= 1ULL << QStringView{ attr }.mid(guid.length(), attr.length() - guid.length()).toULongLong(); 0030 0031 return attributes; 0032 } 0033 0034 QStringList SfdiskGptAttributes::toStringList(quint64 attrs) 0035 { 0036 QStringList list; 0037 if (attrs & 0x1) 0038 list += requiredPartition; 0039 if (attrs & 0x2) 0040 list += noBlockIoProtocol; 0041 if (attrs & 0x4) 0042 list += legacyBiosBootable; 0043 for (int bit = 48; bit < 64; bit++) 0044 if (attrs & (1LL << bit)) 0045 list += guid + QString::number(bit); 0046 0047 return list; 0048 }