Skip to content
This repository was archived by the owner on Feb 27, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions recovery/initdrivethread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ void InitDriveThread::run()

bool InitDriveThread::method_resizePartitions()
{
int newStartOfRescuePartition = getFileContents(sysclassblock(_drive, 1)+"/start").trimmed().toInt();
int newSizeOfRescuePartition = sizeofBootFilesInKB()*1.024/1000 + 100;
uint newStartOfRescuePartition = getFileContents(sysclassblock(_drive, 1)+"/start").trimmed().toUInt();
uint newSizeOfRescuePartition = sizeofBootFilesInKB()*1.024/1000 + 100;

if (!umountSystemPartition())
{
Expand Down Expand Up @@ -245,12 +245,12 @@ bool InitDriveThread::method_resizePartitions()
emit statusUpdate(tr("Creating extended partition"));

QByteArray partitionTable;
int startOfOurPartition = getFileContents(sysclassblock(_drive, 1)+"/start").trimmed().toInt();
int sizeOfOurPartition = getFileContents(sysclassblock(_drive, 1)+"/size").trimmed().toInt();
int startOfExtended = startOfOurPartition+sizeOfOurPartition;
uint startOfOurPartition = getFileContents(sysclassblock(_drive, 1)+"/start").trimmed().toUInt();
uint sizeOfOurPartition = getFileContents(sysclassblock(_drive, 1)+"/size").trimmed().toUInt();
uint startOfExtended = startOfOurPartition+sizeOfOurPartition;

// Align start of settings partition on 4 MiB boundary
int startOfSettings = startOfExtended + PARTITION_GAP;
uint startOfSettings = startOfExtended + PARTITION_GAP;
if (startOfSettings % PARTITION_ALIGNMENT != 0)
startOfSettings += PARTITION_ALIGNMENT-(startOfSettings % PARTITION_ALIGNMENT);

Expand Down Expand Up @@ -292,11 +292,11 @@ int InitDriveThread::sizeofBootFilesInKB()
return proc.readAll().split('\t').first().toInt();
}

int InitDriveThread::sizeofSDCardInBlocks()
uint InitDriveThread::sizeofSDCardInBlocks()
{
QFile f(sysclassblock(_drive)+"/size");
f.open(f.ReadOnly);
int blocks = f.readAll().trimmed().toULongLong();
uint blocks = f.readAll().trimmed().toUInt();
f.close();

return blocks;
Expand Down Expand Up @@ -408,12 +408,12 @@ bool InitDriveThread::partitionDrive()
* First logical partition has NOOBS persistent settings partition
*/
QByteArray partitionTable;
int sizeOfOurPartition = RESCUE_PARTITION_SIZE*1024*2;
int startOfOurPartition = PARTITION_ALIGNMENT;
int startOfExtended = startOfOurPartition+sizeOfOurPartition;
uint sizeOfOurPartition = RESCUE_PARTITION_SIZE*1024*2;
uint startOfOurPartition = PARTITION_ALIGNMENT;
uint startOfExtended = startOfOurPartition+sizeOfOurPartition;

// Align start of settings partition on 4 MiB boundary
int startOfSettings = startOfExtended + PARTITION_GAP;
uint startOfSettings = startOfExtended + PARTITION_GAP;
if (startOfSettings % PARTITION_ALIGNMENT != 0)
startOfSettings += PARTITION_ALIGNMENT-(startOfSettings % PARTITION_ALIGNMENT);

Expand Down
2 changes: 1 addition & 1 deletion recovery/initdrivethread.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class InitDriveThread : public QThread

bool method_resizePartitions();
int sizeofBootFilesInKB();
int sizeofSDCardInBlocks();
uint sizeofSDCardInBlocks();
bool mountSystemPartition();
bool umountSystemPartition();
bool zeroMbr();
Expand Down
8 changes: 4 additions & 4 deletions recovery/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ void MainWindow::populate()

// Fill in list of images
repopulate();
_availableMB = (getFileContents(sysclassblock(_drive)+"/size").trimmed().toULongLong()-getFileContents(sysclassblock(_drive, 5)+"/start").trimmed().toULongLong()-getFileContents(sysclassblock(_drive, 5)+"/size").trimmed().toULongLong())/2048;
_availableMB = (getFileContents(sysclassblock(_drive)+"/size").trimmed().toUInt()-getFileContents(sysclassblock(_drive, 5)+"/start").trimmed().toUInt()-getFileContents(sysclassblock(_drive, 5)+"/size").trimmed().toUInt())/2048;
updateNeeded();

if (ui->list->count() != 0)
Expand Down Expand Up @@ -1382,12 +1382,12 @@ void MainWindow::updateNeeded()
foreach (QListWidgetItem *item, selected)
{
QVariantMap entry = item->data(Qt::UserRole).toMap();
_neededMB += entry.value("nominal_size").toInt();
_neededMB += entry.value("nominal_size").toUInt();

if (nameMatchesRiscOS(entry.value("name").toString()))
{
/* RiscOS needs to start at a predetermined sector, calculate the extra space needed for that */
int startSector = getFileContents(sysclassblock(_drive, 5)+"/start").trimmed().toULongLong()+getFileContents(sysclassblock(_drive, 5)+"/size").trimmed().toULongLong();
uint startSector = getFileContents(sysclassblock(_drive, 5)+"/start").trimmed().toUInt()+getFileContents(sysclassblock(_drive, 5)+"/size").trimmed().toUInt();
if (RISCOS_SECTOR_OFFSET > startSector)
{
_neededMB += (RISCOS_SECTOR_OFFSET - startSector)/2048;
Expand Down Expand Up @@ -1769,7 +1769,7 @@ void MainWindow::on_targetCombo_currentIndexChanged(int index)

qDebug() << "New drive selected:" << devname;
_drive = "/dev/"+devname;
_availableMB = (getFileContents(sysclassblock(_drive)+"/size").trimmed().toULongLong()-getFileContents(sysclassblock(_drive, 5)+"/start").trimmed().toULongLong()-getFileContents(sysclassblock(_drive, 5)+"/size").trimmed().toULongLong())/2048;
_availableMB = (getFileContents(sysclassblock(_drive)+"/size").trimmed().toUInt()-getFileContents(sysclassblock(_drive, 5)+"/start").trimmed().toUInt()-getFileContents(sysclassblock(_drive, 5)+"/size").trimmed().toUInt())/2048;
filterList();
updateNeeded();
}
Expand Down
3 changes: 2 additions & 1 deletion recovery/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class MainWindow : public QMainWindow
bool _hasWifi;
int _numInstalledOS, _devlistcount;
QNetworkAccessManager *_netaccess;
int _neededMB, _availableMB, _numMetaFilesToDownload, _numIconsToDownload;
uint _neededMB, _availableMB;
int _numMetaFilesToDownload, _numIconsToDownload;
QMessageBox *_displayModeBox;
QTimer _networkStatusPollTimer, _piDrivePollTimer;
QTime _time;
Expand Down
35 changes: 18 additions & 17 deletions recovery/multiimagewritethread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ void MultiImageWriteThread::addImage(const QString &folder, const QString &flavo
void MultiImageWriteThread::run()
{
/* Calculate space requirements, and check special requirements */
int totalnominalsize = 0, totaluncompressedsize = 0, numparts = 0, numexpandparts = 0;
int startSector = getFileContents(sysclassblock(_drive, 5)+"/start").trimmed().toULongLong()
+ getFileContents(sysclassblock(_drive, 5)+"/size").trimmed().toULongLong();
int totalSectors = getFileContents(sysclassblock(_drive)+"/size").trimmed().toULongLong();
int availableMB = (totalSectors-startSector)/2048;
uint totalnominalsize = 0, totaluncompressedsize = 0, numparts = 0, numexpandparts = 0;
uint startSector = getFileContents(sysclassblock(_drive, 5)+"/start").trimmed().toUInt()
+ getFileContents(sysclassblock(_drive, 5)+"/size").trimmed().toUInt();
uint totalSectors = getFileContents(sysclassblock(_drive)+"/size").trimmed().toUInt();
uint availableMB = (totalSectors-startSector)/2048;

/* key: partition number, value: partition information */
QMap<int, PartitionInfo *> partitionMap, bootPartitionMap;
Expand Down Expand Up @@ -146,7 +146,8 @@ void MultiImageWriteThread::run()
}

/* Assign logical partition numbers to partitions that did not reserve a special number */
int pnr, bootpnr, offset = 0;
int pnr, bootpnr;
uint offset = 0;
if (partitionMap.isEmpty())
pnr = 6;
else
Expand All @@ -155,8 +156,8 @@ void MultiImageWriteThread::run()
if (_multiDrives)
{
bootpnr = 6;
offset = getFileContents(sysclassblock(_bootdrive, 5)+"/start").trimmed().toULongLong()
+ getFileContents(sysclassblock(_bootdrive, 5)+"/size").trimmed().toULongLong();
offset = getFileContents(sysclassblock(_bootdrive, 5)+"/start").trimmed().toUInt()
+ getFileContents(sysclassblock(_bootdrive, 5)+"/size").trimmed().toUInt();
}

foreach (OsInfo *image, _images)
Expand All @@ -178,7 +179,7 @@ void MultiImageWriteThread::run()
offset += PARTITION_ALIGNMENT-(offset % PARTITION_ALIGNMENT);
}
partition->setOffset(offset);
int partsizeSectors = partition->partitionSizeNominal() * 2048;
uint partsizeSectors = partition->partitionSizeNominal() * 2048;
partition->setPartitionSizeSectors(partsizeSectors);
offset += partsizeSectors;
}
Expand Down Expand Up @@ -228,15 +229,15 @@ void MultiImageWriteThread::run()
p->setOffset(offset);
}

int partsizeMB = p->partitionSizeNominal();
uint partsizeMB = p->partitionSizeNominal();
if ( p->wantMaximised() )
partsizeMB += _extraSpacePerPartition;
int partsizeSectors = partsizeMB * 2048;
uint partsizeSectors = partsizeMB * 2048;

if (p == log_before_prim.last())
{
/* Let last partition have any remaining space that we couldn't divide evenly */
int spaceleft = totalSectors - offset - partsizeSectors;
uint spaceleft = totalSectors - offset - partsizeSectors;

if (spaceleft > 0 && p->wantMaximised())
{
Expand Down Expand Up @@ -326,13 +327,13 @@ bool MultiImageWriteThread::writePartitionTable(const QString &drive, const QMap
/* Write partition table using sfdisk */

/* Fixed NOOBS partition */
int startP1 = getFileContents(sysclassblock(drive, 1)+"/start").trimmed().toInt();
int sizeP1 = getFileContents(sysclassblock(drive, 1)+"/size").trimmed().toInt();
uint startP1 = getFileContents(sysclassblock(drive, 1)+"/start").trimmed().toUInt();
uint sizeP1 = getFileContents(sysclassblock(drive, 1)+"/size").trimmed().toUInt();
/* Fixed start of extended partition. End is not fixed, as it depends on primary partition 3 & 4 */
int startExtended = startP1+sizeP1;
/* Fixed settings partition */
int startP5 = getFileContents(sysclassblock(drive, SETTINGS_PARTNR)+"/start").trimmed().toInt();
int sizeP5 = getFileContents(sysclassblock(drive, SETTINGS_PARTNR)+"/size").trimmed().toInt();
uint startP5 = getFileContents(sysclassblock(drive, SETTINGS_PARTNR)+"/start").trimmed().toUInt();
uint sizeP5 = getFileContents(sysclassblock(drive, SETTINGS_PARTNR)+"/size").trimmed().toUInt();

if (!startP1 || !sizeP1 || !startP5 || !sizeP5)
{
Expand All @@ -346,7 +347,7 @@ bool MultiImageWriteThread::writePartitionTable(const QString &drive, const QMap
partitionMap.insert(1, new PartitionInfo(1, startP1, sizeP1, "0E", this)); /* FAT boot partition */
partitionMap.insert(5, new PartitionInfo(5, startP5, sizeP5, "L", this)); /* Ext4 settings partition */

int sizeExtended = partitionMap.values().last()->endSector() - startExtended;
uint sizeExtended = partitionMap.values().last()->endSector() - startExtended;
if (!partitionMap.contains(2))
{
partitionMap.insert(2, new PartitionInfo(2, startExtended, sizeExtended, "E", this));
Expand Down
10 changes: 5 additions & 5 deletions recovery/partitioninfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ PartitionInfo::PartitionInfo(const QVariantMap &m, QObject *parent) :
_tarball = m.value("tarball").toString();
_wantMaximised = m.value("want_maximised", false).toBool();
_emptyFS = m.value("empty_fs", false).toBool();
_offset = m.value("offset_in_sectors").toInt();
_partitionSizeNominal = m.value("partition_size_nominal").toInt();
_requiresPartitionNumber = m.value("requires_partition_number").toInt();
_uncompressedTarballSize = m.value("uncompressed_tarball_size").toInt();
_offset = m.value("offset_in_sectors").toUInt();
_partitionSizeNominal = m.value("partition_size_nominal").toUInt();
_requiresPartitionNumber = m.value("requires_partition_number").toUInt();
_uncompressedTarballSize = m.value("uncompressed_tarball_size").toUInt();
_active = m.value("active", false).toBool();

QByteArray defaultPartType;
Expand All @@ -28,7 +28,7 @@ PartitionInfo::PartitionInfo(const QVariantMap &m, QObject *parent) :
_partitionType = m.value("partition_type", defaultPartType).toByteArray();
}

PartitionInfo::PartitionInfo(int partitionNr, int offset, int sectors, const QByteArray &partType, QObject *parent) :
PartitionInfo::PartitionInfo(int partitionNr, uint offset, uint sectors, const QByteArray &partType, QObject *parent) :
QObject(parent), _partitionType(partType), _requiresPartitionNumber(partitionNr), _offset(offset), _partitionSizeSectors(sectors), _active(false)
{
}
19 changes: 10 additions & 9 deletions recovery/partitioninfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PartitionInfo : public QObject
/* Constructor. Gets called from OsInfo with info from json file */
explicit PartitionInfo(const QVariantMap &m, QObject *parent = 0);

explicit PartitionInfo(int partitionNr, int offset, int sectors, const QByteArray &partType, QObject *parent = 0);
explicit PartitionInfo(int partitionNr, uint offset, uint sectors, const QByteArray &partType, QObject *parent = 0);

inline void setPartitionDevice(const QByteArray &partdevice)
{
Expand Down Expand Up @@ -59,7 +59,7 @@ class PartitionInfo : public QObject
return _tarball;
}

inline int partitionSizeNominal()
inline uint partitionSizeNominal()
{
return _partitionSizeNominal;
}
Expand All @@ -74,32 +74,32 @@ class PartitionInfo : public QObject
return _wantMaximised;
}

inline int uncompressedTarballSize()
inline uint uncompressedTarballSize()
{
return _uncompressedTarballSize;
}

inline void setOffset(int offset)
inline void setOffset(uint offset)
{
_offset = offset;
}

inline int offset()
inline uint offset()
{
return _offset;
}

inline void setPartitionSizeSectors(int size)
inline void setPartitionSizeSectors(uint size)
{
_partitionSizeSectors = size;
}

inline int partitionSizeSectors()
inline uint partitionSizeSectors()
{
return _partitionSizeSectors;
}

inline int endSector()
inline uint endSector()
{
return _offset + _partitionSizeSectors;
}
Expand All @@ -122,7 +122,8 @@ class PartitionInfo : public QObject
protected:
QByteArray _fstype, _mkfsOptions, _label, _partitionDevice, _partitionType;
QString _tarball;
int _partitionSizeNominal, _requiresPartitionNumber, _offset, _uncompressedTarballSize, _partitionSizeSectors;
int _requiresPartitionNumber;
uint _partitionSizeNominal, _offset, _uncompressedTarballSize, _partitionSizeSectors;
bool _emptyFS, _wantMaximised, _active;
};

Expand Down
20 changes: 15 additions & 5 deletions recovery/progressslideshowdialog.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "progressslideshowdialog.h"
#include "ui_progressslideshowdialog.h"
#include "util.h"
#include <limits.h>
#include <QDir>
#include <QFile>
#include <QPixmap>
Expand Down Expand Up @@ -132,13 +133,18 @@ void ProgressSlideshowDialog::changeDrive(const QString &drive)

void ProgressSlideshowDialog::setMaximum(qint64 bytes)
{
/* restrict to size of 1TB since the progressbar expects an int32 */
/* to prevent overflow */
if (bytes > 1099511627775LL) /* == 2147483648 * 512 -1*/
bytes = 1099511627775LL;
_maxSectors = bytes/512;
ui->progressBar->setMaximum(_maxSectors);
}

void ProgressSlideshowDialog::updateIOstats()
{
int sectors = sectorsWritten()-_sectorsStart;
uint sectors = sectorsWritten()-_sectorsStart;

double sectorsPerSec = sectors * 1000.0 / _t1.elapsed();
if (_maxSectors)
{
Expand All @@ -154,7 +160,7 @@ void ProgressSlideshowDialog::updateIOstats()
}
}

int ProgressSlideshowDialog::sectorsWritten()
uint ProgressSlideshowDialog::sectorsWritten()
{
/* Poll kernel counters to get number of bytes written
*
Expand All @@ -176,6 +182,8 @@ int ProgressSlideshowDialog::sectorsWritten()
* time_in_queue milliseconds total wait time for all requests
*/

uint numsectors=0;

QFile f(sysclassblock(_drive)+"/stat");
f.open(f.ReadOnly);
QByteArray ioline = f.readAll().simplified();
Expand All @@ -184,7 +192,9 @@ int ProgressSlideshowDialog::sectorsWritten()
QList<QByteArray> stats = ioline.split(' ');

if (stats.count() >= 6)
return stats.at(6).toInt(); /* write sectors */
else
return 0;
numsectors = stats.at(6).toUInt(); /* write sectors */

if (numsectors > INT_MAX)
numsectors = INT_MAX;
return numsectors;
}
5 changes: 3 additions & 2 deletions recovery/progressslideshowdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ public slots:
protected:
QString _drive;
QStringList _slides;
int _pos, _changeInterval, _sectorsStart, _maxSectors, _pausedAt;
int _pos, _changeInterval;
uint _sectorsStart, _maxSectors, _pausedAt;
QTimer _timer, _iotimer;
QTime _t1;

int sectorsWritten();
uint sectorsWritten();


private:
Expand Down
Loading