Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Use partuuid in installed_os.json & Move partuuid functions
Browse files Browse the repository at this point in the history
  • Loading branch information
procount committed May 15, 2018
1 parent 5cf2ef4 commit 08fa9ff
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 62 deletions.
65 changes: 7 additions & 58 deletions recovery/multiimagewritethread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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<quint32>(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;
}
4 changes: 0 additions & 4 deletions recovery/multiimagewritethread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, PartitionInfo *> &partitionMap);
bool isURL(const QString &s);
QByteArray getDiskId(const QString &device);
QByteArray getPartUUID(const QString &devpart);


/* key: folder, value: flavour */
Expand Down
61 changes: 61 additions & 0 deletions recovery/util.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "util.h"
#include "mbr.h"
#include <sys/ioctl.h>
#include <stdint.h>
#include <unistd.h>
Expand All @@ -10,6 +11,7 @@
#include <QProcess>
#include <QDebug>
#include <QList>
#include <QtEndian>

/*
* Convenience functions
Expand Down Expand Up @@ -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<quint32>(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;
}
6 changes: 6 additions & 0 deletions recovery/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 08fa9ff

Please sign in to comment.