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

Commit 21cf945

Browse files
procountXECDesign
authored andcommitted
USB Disk Sizes (#418)
* changed int->qint64 for disk space calc
1 parent 0f7ad02 commit 21cf945

31 files changed

+1786
-1772
lines changed

recovery/initdrivethread.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ void InitDriveThread::run()
141141

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

147147
if (!umountSystemPartition())
148148
{
@@ -245,12 +245,12 @@ bool InitDriveThread::method_resizePartitions()
245245
emit statusUpdate(tr("Creating extended partition"));
246246

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

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

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

295-
int InitDriveThread::sizeofSDCardInBlocks()
295+
uint InitDriveThread::sizeofSDCardInBlocks()
296296
{
297297
QFile f(sysclassblock(_drive)+"/size");
298298
f.open(f.ReadOnly);
299-
int blocks = f.readAll().trimmed().toULongLong();
299+
uint blocks = f.readAll().trimmed().toUInt();
300300
f.close();
301301

302302
return blocks;
@@ -408,12 +408,12 @@ bool InitDriveThread::partitionDrive()
408408
* First logical partition has NOOBS persistent settings partition
409409
*/
410410
QByteArray partitionTable;
411-
int sizeOfOurPartition = RESCUE_PARTITION_SIZE*1024*2;
412-
int startOfOurPartition = PARTITION_ALIGNMENT;
413-
int startOfExtended = startOfOurPartition+sizeOfOurPartition;
411+
uint sizeOfOurPartition = RESCUE_PARTITION_SIZE*1024*2;
412+
uint startOfOurPartition = PARTITION_ALIGNMENT;
413+
uint startOfExtended = startOfOurPartition+sizeOfOurPartition;
414414

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

recovery/initdrivethread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class InitDriveThread : public QThread
2626

2727
bool method_resizePartitions();
2828
int sizeofBootFilesInKB();
29-
int sizeofSDCardInBlocks();
29+
uint sizeofSDCardInBlocks();
3030
bool mountSystemPartition();
3131
bool umountSystemPartition();
3232
bool zeroMbr();

recovery/mainwindow.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ void MainWindow::populate()
278278

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

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

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

17701770
qDebug() << "New drive selected:" << devname;
17711771
_drive = "/dev/"+devname;
1772-
_availableMB = (getFileContents(sysclassblock(_drive)+"/size").trimmed().toULongLong()-getFileContents(sysclassblock(_drive, 5)+"/start").trimmed().toULongLong()-getFileContents(sysclassblock(_drive, 5)+"/size").trimmed().toULongLong())/2048;
1772+
_availableMB = (getFileContents(sysclassblock(_drive)+"/size").trimmed().toUInt()-getFileContents(sysclassblock(_drive, 5)+"/start").trimmed().toUInt()-getFileContents(sysclassblock(_drive, 5)+"/size").trimmed().toUInt())/2048;
17731773
filterList();
17741774
updateNeeded();
17751775
}

recovery/mainwindow.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ class MainWindow : public QMainWindow
4949
bool _hasWifi;
5050
int _numInstalledOS, _devlistcount;
5151
QNetworkAccessManager *_netaccess;
52-
int _neededMB, _availableMB, _numMetaFilesToDownload, _numIconsToDownload;
52+
uint _neededMB, _availableMB;
53+
int _numMetaFilesToDownload, _numIconsToDownload;
5354
QMessageBox *_displayModeBox;
5455
QTimer _networkStatusPollTimer, _piDrivePollTimer;
5556
QTime _time;

recovery/multiimagewritethread.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ void MultiImageWriteThread::addImage(const QString &folder, const QString &flavo
3838
void MultiImageWriteThread::run()
3939
{
4040
/* Calculate space requirements, and check special requirements */
41-
int totalnominalsize = 0, totaluncompressedsize = 0, numparts = 0, numexpandparts = 0;
42-
int startSector = getFileContents(sysclassblock(_drive, 5)+"/start").trimmed().toULongLong()
43-
+ getFileContents(sysclassblock(_drive, 5)+"/size").trimmed().toULongLong();
44-
int totalSectors = getFileContents(sysclassblock(_drive)+"/size").trimmed().toULongLong();
45-
int availableMB = (totalSectors-startSector)/2048;
41+
uint totalnominalsize = 0, totaluncompressedsize = 0, numparts = 0, numexpandparts = 0;
42+
uint startSector = getFileContents(sysclassblock(_drive, 5)+"/start").trimmed().toUInt()
43+
+ getFileContents(sysclassblock(_drive, 5)+"/size").trimmed().toUInt();
44+
uint totalSectors = getFileContents(sysclassblock(_drive)+"/size").trimmed().toUInt();
45+
uint availableMB = (totalSectors-startSector)/2048;
4646

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

148148
/* Assign logical partition numbers to partitions that did not reserve a special number */
149-
int pnr, bootpnr, offset = 0;
149+
int pnr, bootpnr;
150+
uint offset = 0;
150151
if (partitionMap.isEmpty())
151152
pnr = 6;
152153
else
@@ -155,8 +156,8 @@ void MultiImageWriteThread::run()
155156
if (_multiDrives)
156157
{
157158
bootpnr = 6;
158-
offset = getFileContents(sysclassblock(_bootdrive, 5)+"/start").trimmed().toULongLong()
159-
+ getFileContents(sysclassblock(_bootdrive, 5)+"/size").trimmed().toULongLong();
159+
offset = getFileContents(sysclassblock(_bootdrive, 5)+"/start").trimmed().toUInt()
160+
+ getFileContents(sysclassblock(_bootdrive, 5)+"/size").trimmed().toUInt();
160161
}
161162

162163
foreach (OsInfo *image, _images)
@@ -178,7 +179,7 @@ void MultiImageWriteThread::run()
178179
offset += PARTITION_ALIGNMENT-(offset % PARTITION_ALIGNMENT);
179180
}
180181
partition->setOffset(offset);
181-
int partsizeSectors = partition->partitionSizeNominal() * 2048;
182+
uint partsizeSectors = partition->partitionSizeNominal() * 2048;
182183
partition->setPartitionSizeSectors(partsizeSectors);
183184
offset += partsizeSectors;
184185
}
@@ -228,15 +229,15 @@ void MultiImageWriteThread::run()
228229
p->setOffset(offset);
229230
}
230231

231-
int partsizeMB = p->partitionSizeNominal();
232+
uint partsizeMB = p->partitionSizeNominal();
232233
if ( p->wantMaximised() )
233234
partsizeMB += _extraSpacePerPartition;
234-
int partsizeSectors = partsizeMB * 2048;
235+
uint partsizeSectors = partsizeMB * 2048;
235236

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

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

328329
/* Fixed NOOBS partition */
329-
int startP1 = getFileContents(sysclassblock(drive, 1)+"/start").trimmed().toInt();
330-
int sizeP1 = getFileContents(sysclassblock(drive, 1)+"/size").trimmed().toInt();
330+
uint startP1 = getFileContents(sysclassblock(drive, 1)+"/start").trimmed().toUInt();
331+
uint sizeP1 = getFileContents(sysclassblock(drive, 1)+"/size").trimmed().toUInt();
331332
/* Fixed start of extended partition. End is not fixed, as it depends on primary partition 3 & 4 */
332333
int startExtended = startP1+sizeP1;
333334
/* Fixed settings partition */
334-
int startP5 = getFileContents(sysclassblock(drive, SETTINGS_PARTNR)+"/start").trimmed().toInt();
335-
int sizeP5 = getFileContents(sysclassblock(drive, SETTINGS_PARTNR)+"/size").trimmed().toInt();
335+
uint startP5 = getFileContents(sysclassblock(drive, SETTINGS_PARTNR)+"/start").trimmed().toUInt();
336+
uint sizeP5 = getFileContents(sysclassblock(drive, SETTINGS_PARTNR)+"/size").trimmed().toUInt();
336337

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

349-
int sizeExtended = partitionMap.values().last()->endSector() - startExtended;
350+
uint sizeExtended = partitionMap.values().last()->endSector() - startExtended;
350351
if (!partitionMap.contains(2))
351352
{
352353
partitionMap.insert(2, new PartitionInfo(2, startExtended, sizeExtended, "E", this));

recovery/partitioninfo.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ PartitionInfo::PartitionInfo(const QVariantMap &m, QObject *parent) :
99
_tarball = m.value("tarball").toString();
1010
_wantMaximised = m.value("want_maximised", false).toBool();
1111
_emptyFS = m.value("empty_fs", false).toBool();
12-
_offset = m.value("offset_in_sectors").toInt();
13-
_partitionSizeNominal = m.value("partition_size_nominal").toInt();
14-
_requiresPartitionNumber = m.value("requires_partition_number").toInt();
15-
_uncompressedTarballSize = m.value("uncompressed_tarball_size").toInt();
12+
_offset = m.value("offset_in_sectors").toUInt();
13+
_partitionSizeNominal = m.value("partition_size_nominal").toUInt();
14+
_requiresPartitionNumber = m.value("requires_partition_number").toUInt();
15+
_uncompressedTarballSize = m.value("uncompressed_tarball_size").toUInt();
1616
_active = m.value("active", false).toBool();
1717

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

31-
PartitionInfo::PartitionInfo(int partitionNr, int offset, int sectors, const QByteArray &partType, QObject *parent) :
31+
PartitionInfo::PartitionInfo(int partitionNr, uint offset, uint sectors, const QByteArray &partType, QObject *parent) :
3232
QObject(parent), _partitionType(partType), _requiresPartitionNumber(partitionNr), _offset(offset), _partitionSizeSectors(sectors), _active(false)
3333
{
3434
}

recovery/partitioninfo.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class PartitionInfo : public QObject
1717
/* Constructor. Gets called from OsInfo with info from json file */
1818
explicit PartitionInfo(const QVariantMap &m, QObject *parent = 0);
1919

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

2222
inline void setPartitionDevice(const QByteArray &partdevice)
2323
{
@@ -59,7 +59,7 @@ class PartitionInfo : public QObject
5959
return _tarball;
6060
}
6161

62-
inline int partitionSizeNominal()
62+
inline uint partitionSizeNominal()
6363
{
6464
return _partitionSizeNominal;
6565
}
@@ -74,32 +74,32 @@ class PartitionInfo : public QObject
7474
return _wantMaximised;
7575
}
7676

77-
inline int uncompressedTarballSize()
77+
inline uint uncompressedTarballSize()
7878
{
7979
return _uncompressedTarballSize;
8080
}
8181

82-
inline void setOffset(int offset)
82+
inline void setOffset(uint offset)
8383
{
8484
_offset = offset;
8585
}
8686

87-
inline int offset()
87+
inline uint offset()
8888
{
8989
return _offset;
9090
}
9191

92-
inline void setPartitionSizeSectors(int size)
92+
inline void setPartitionSizeSectors(uint size)
9393
{
9494
_partitionSizeSectors = size;
9595
}
9696

97-
inline int partitionSizeSectors()
97+
inline uint partitionSizeSectors()
9898
{
9999
return _partitionSizeSectors;
100100
}
101101

102-
inline int endSector()
102+
inline uint endSector()
103103
{
104104
return _offset + _partitionSizeSectors;
105105
}
@@ -122,7 +122,8 @@ class PartitionInfo : public QObject
122122
protected:
123123
QByteArray _fstype, _mkfsOptions, _label, _partitionDevice, _partitionType;
124124
QString _tarball;
125-
int _partitionSizeNominal, _requiresPartitionNumber, _offset, _uncompressedTarballSize, _partitionSizeSectors;
125+
int _requiresPartitionNumber;
126+
uint _partitionSizeNominal, _offset, _uncompressedTarballSize, _partitionSizeSectors;
126127
bool _emptyFS, _wantMaximised, _active;
127128
};
128129

recovery/progressslideshowdialog.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "progressslideshowdialog.h"
22
#include "ui_progressslideshowdialog.h"
33
#include "util.h"
4+
#include <limits.h>
45
#include <QDir>
56
#include <QFile>
67
#include <QPixmap>
@@ -132,13 +133,18 @@ void ProgressSlideshowDialog::changeDrive(const QString &drive)
132133

133134
void ProgressSlideshowDialog::setMaximum(qint64 bytes)
134135
{
136+
/* restrict to size of 1TB since the progressbar expects an int32 */
137+
/* to prevent overflow */
138+
if (bytes > 1099511627775LL) /* == 2147483648 * 512 -1*/
139+
bytes = 1099511627775LL;
135140
_maxSectors = bytes/512;
136141
ui->progressBar->setMaximum(_maxSectors);
137142
}
138143

139144
void ProgressSlideshowDialog::updateIOstats()
140145
{
141-
int sectors = sectorsWritten()-_sectorsStart;
146+
uint sectors = sectorsWritten()-_sectorsStart;
147+
142148
double sectorsPerSec = sectors * 1000.0 / _t1.elapsed();
143149
if (_maxSectors)
144150
{
@@ -154,7 +160,7 @@ void ProgressSlideshowDialog::updateIOstats()
154160
}
155161
}
156162

157-
int ProgressSlideshowDialog::sectorsWritten()
163+
uint ProgressSlideshowDialog::sectorsWritten()
158164
{
159165
/* Poll kernel counters to get number of bytes written
160166
*
@@ -176,6 +182,8 @@ int ProgressSlideshowDialog::sectorsWritten()
176182
* time_in_queue milliseconds total wait time for all requests
177183
*/
178184

185+
uint numsectors=0;
186+
179187
QFile f(sysclassblock(_drive)+"/stat");
180188
f.open(f.ReadOnly);
181189
QByteArray ioline = f.readAll().simplified();
@@ -184,7 +192,9 @@ int ProgressSlideshowDialog::sectorsWritten()
184192
QList<QByteArray> stats = ioline.split(' ');
185193

186194
if (stats.count() >= 6)
187-
return stats.at(6).toInt(); /* write sectors */
188-
else
189-
return 0;
195+
numsectors = stats.at(6).toUInt(); /* write sectors */
196+
197+
if (numsectors > INT_MAX)
198+
numsectors = INT_MAX;
199+
return numsectors;
190200
}

recovery/progressslideshowdialog.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ public slots:
4040
protected:
4141
QString _drive;
4242
QStringList _slides;
43-
int _pos, _changeInterval, _sectorsStart, _maxSectors, _pausedAt;
43+
int _pos, _changeInterval;
44+
uint _sectorsStart, _maxSectors, _pausedAt;
4445
QTimer _timer, _iotimer;
4546
QTime _t1;
4647

47-
int sectorsWritten();
48+
uint sectorsWritten();
4849

4950

5051
private:

0 commit comments

Comments
 (0)