diff --git a/recovery/multiimagewritethread.cpp b/recovery/multiimagewritethread.cpp index cdc307a5..adb62f7b 100644 --- a/recovery/multiimagewritethread.cpp +++ b/recovery/multiimagewritethread.cpp @@ -530,7 +530,13 @@ bool MultiImageWriteThread::processImage(OsInfo *image) QVariantList vpartitions; foreach (PartitionInfo *p, *partitions) { - vpartitions.append(p->partitionDevice()); + QString part = p->partitionDevice(); + if (part.left(13) != "/dev/mmcblk0p") + { + part = getPartUUID(part); + } + vpartitions.append(part); + } QSettings settings("/settings/noobs.conf", QSettings::IniFormat); int videomode = settings.value("display_mode", 0).toInt(); @@ -1009,31 +1015,6 @@ void MultiImageWriteThread::patchConfigTxt() } -QByteArray MultiImageWriteThread::getLabel(const QString part) -{ - QByteArray result; - QProcess p; - p.start("/sbin/blkid -s LABEL -o value "+part); - p.waitForFinished(); - - if (p.exitCode() == 0) - result = p.readAll().trimmed(); - - return result; -} - -QByteArray MultiImageWriteThread::getUUID(const QString part) -{ - QByteArray result; - QProcess p; - p.start("/sbin/blkid -s UUID -o value "+part); - p.waitForFinished(); - - if (p.exitCode() == 0) - result = p.readAll().trimmed(); - - return result; -} QString MultiImageWriteThread::getDescription(const QString &folder, const QString &flavour) { @@ -1065,35 +1046,3 @@ bool MultiImageWriteThread::isURL(const QString &s) return s.startsWith("http:") || s.startsWith("https:"); } -QByteArray MultiImageWriteThread::getDiskId(const QString &device) -{ - mbr_table mbr; - - QFile f(device); - f.open(f.ReadOnly); - f.read((char *) &mbr, sizeof(mbr)); - f.close(); - - quint32 diskid = qFromLittleEndian(mbr.diskid); - return QByteArray::number(diskid, 16).rightJustified(8, '0');; -} - -QByteArray MultiImageWriteThread::getPartUUID(const QString &devpart) -{ - QByteArray r; - - QRegExp partnrRx("([0-9]+)$"); - if (partnrRx.indexIn(devpart) != -1) - { - QString drive = devpart.left(partnrRx.pos()); - if (drive.endsWith("p")) - drive.chop(1); - - r = "PARTUUID="+getDiskId(drive); - int partnr = partnrRx.cap(1).toInt(); - QByteArray partnrstr = QByteArray::number(partnr, 16).rightJustified(2, '0'); - r += '-'+partnrstr; - } - - return r; -} diff --git a/recovery/multiimagewritethread.h b/recovery/multiimagewritethread.h index b1d6be45..255916fb 100644 --- a/recovery/multiimagewritethread.h +++ b/recovery/multiimagewritethread.h @@ -27,14 +27,10 @@ class MultiImageWriteThread : public QThread bool partclone_restore(const QString &imagePath, const QString &device); bool untar(const QString &tarball); bool isLabelAvailable(const QByteArray &label); - QByteArray getLabel(const QString part); - QByteArray getUUID(const QString part); void patchConfigTxt(); QString getDescription(const QString &folder, const QString &flavour); bool writePartitionTable(const QString &drive, const QMap &partitionMap); bool isURL(const QString &s); - QByteArray getDiskId(const QString &device); - QByteArray getPartUUID(const QString &devpart); /* key: folder, value: flavour */ diff --git a/recovery/util.cpp b/recovery/util.cpp index ef6bf2a5..7dfc4f82 100644 --- a/recovery/util.cpp +++ b/recovery/util.cpp @@ -1,4 +1,5 @@ #include "util.h" +#include "mbr.h" #include #include #include @@ -10,6 +11,7 @@ #include #include #include +#include /* * Convenience functions @@ -173,3 +175,62 @@ QByteArray sysclassblock(const QString &drivedev, int partnr) return "/sys/class/block/"+ b; } + +QByteArray getLabel(const QString part) +{ + QByteArray result; + QProcess p; + p.start("/sbin/blkid -s LABEL -o value "+part); + p.waitForFinished(); + + if (p.exitCode() == 0) + result = p.readAll().trimmed(); + + return result; +} + +QByteArray getUUID(const QString part) +{ + QByteArray result; + QProcess p; + p.start("/sbin/blkid -s UUID -o value "+part); + p.waitForFinished(); + + if (p.exitCode() == 0) + result = p.readAll().trimmed(); + + return result; +} + +QByteArray getDiskId(const QString &device) +{ + mbr_table mbr; + + QFile f(device); + f.open(f.ReadOnly); + f.read((char *) &mbr, sizeof(mbr)); + f.close(); + + quint32 diskid = qFromLittleEndian(mbr.diskid); + return QByteArray::number(diskid, 16).rightJustified(8, '0');; +} + +QByteArray getPartUUID(const QString &devpart) +{ + QByteArray r; + + QRegExp partnrRx("([0-9]+)$"); + if (partnrRx.indexIn(devpart) != -1) + { + QString drive = devpart.left(partnrRx.pos()); + if (drive.endsWith("p")) + drive.chop(1); + + r = "PARTUUID="+getDiskId(drive); + int partnr = partnrRx.cap(1).toInt(); + QByteArray partnrstr = QByteArray::number(partnr, 16).rightJustified(2, '0'); + r += '-'+partnrstr; + } + + return r; +} diff --git a/recovery/util.h b/recovery/util.h index 100778e0..3e745e0f 100644 --- a/recovery/util.h +++ b/recovery/util.h @@ -23,4 +23,10 @@ bool canBootOs(const QString& name, const QVariantMap& values); void setRebootPartition(QByteArray partition); QByteArray partdev(const QString &drivedev, int nr); QByteArray sysclassblock(const QString &drivedev, int partnr = -1); + +QByteArray getLabel(const QString part); +QByteArray getUUID(const QString part); +QByteArray getDiskId(const QString &device); +QByteArray getPartUUID(const QString &devpart); + #endif // UTIL_H