Fixed support for large files (up to 2^32 - 1 bytes)

The Loke protocol supports 32-bit unsigned for the size of files being
flashed. However, POSIX file commands only support 32-bit (signed). As
such we now have platform specific support for larger files.
Esse commit está contido em:
Benjamin Dobell
2014-06-01 14:09:56 +10:00
commit 082fb091f1
7 arquivos alterados com 49 adições e 36 exclusões
+1 -1
Ver Arquivo
@@ -1,8 +1,8 @@
AUTOMAKE_OPTIONS = subdir-objects
ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS}
AM_CPPFLAGS = $(DEPS_CFLAGS) -std=c++0x -I../libpit/Source
AC_SYS_LARGEFILE
STATIC_LIBS = ../libpit/libpit-1.4.a
bin_PROGRAMS = heimdall
heimdall_SOURCES = source/Arguments.cpp \
source/BridgeManager.cpp \
+5 -5
Ver Arquivo
@@ -1002,9 +1002,9 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int
return (false);
}
fseek(file, 0, SEEK_END);
long fileSize = ftell(file);
rewind(file);
FileSeek(file, 0, SEEK_END);
unsigned int fileSize = (unsigned int)FileTell(file);
FileRewind(file);
ResponsePacket *fileTransferResponse = new ResponsePacket(ResponsePacket::kResponseTypeFileTransfer);
success = ReceivePacket(fileTransferResponse);
@@ -1031,7 +1031,7 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int
lastSequenceSize++;
}
long bytesTransferred = 0;
unsigned int bytesTransferred = 0;
unsigned int currentPercent;
unsigned int previousPercent = 0;
Interface::Print("0%%");
@@ -1144,7 +1144,7 @@ bool BridgeManager::SendFile(FILE *file, unsigned int destination, unsigned int
if (bytesTransferred > fileSize)
bytesTransferred = fileSize;
currentPercent = (int)(100.0f * ((float)bytesTransferred / (float)fileSize));
currentPercent = (unsigned int)(100.0 * ((double)bytesTransferred / (double)fileSize));
if (currentPercent != previousPercent)
{
+3 -3
Ver Arquivo
@@ -120,7 +120,7 @@ int DownloadPitAction::Execute(int argc, char **argv)
// Open output file
const char *outputFilename = outputArgument->GetValue().c_str();
FILE *outputPitFile = fopen(outputFilename, "wb");
FILE *outputPitFile = FileOpen(outputFilename, "wb");
if (!outputPitFile)
{
@@ -135,7 +135,7 @@ int DownloadPitAction::Execute(int argc, char **argv)
if (bridgeManager->Initialise(resume) != BridgeManager::kInitialiseSucceeded || !bridgeManager->BeginSession())
{
fclose(outputPitFile);
FileClose(outputPitFile);
delete bridgeManager;
return (1);
@@ -164,7 +164,7 @@ int DownloadPitAction::Execute(int argc, char **argv)
delete bridgeManager;
fclose(outputPitFile);
FileClose(outputPitFile);
delete [] pitBuffer;
return (success ? 0 : 1);
+18 -18
Ver Arquivo
@@ -87,7 +87,7 @@ static bool openFiles(Arguments& arguments, vector<PartitionFile>& partitionFile
if (pitArgument)
{
pitFile = fopen(pitArgument->GetValue().c_str(), "rb");
pitFile = FileOpen(pitArgument->GetValue().c_str(), "rb");
if (!pitFile)
{
@@ -109,7 +109,7 @@ static bool openFiles(Arguments& arguments, vector<PartitionFile>& partitionFile
if (arguments.GetArgumentTypes().find(argumentName) == arguments.GetArgumentTypes().end())
{
const StringArgument *stringArgument = static_cast<const StringArgument *>(*it);
FILE *file = fopen(stringArgument->GetValue().c_str(), "rb");
FILE *file = FileOpen(stringArgument->GetValue().c_str(), "rb");
if (!file)
{
@@ -130,34 +130,34 @@ static void closeFiles(vector<PartitionFile>& partitionFiles, FILE *& pitFile)
if (pitFile)
{
fclose(pitFile);
FileClose(pitFile);
pitFile = nullptr;
}
// Close partition files
for (vector<PartitionFile>::const_iterator it = partitionFiles.begin(); it != partitionFiles.end(); it++)
fclose(it->file);
FileClose(it->file);
partitionFiles.clear();
}
static bool sendTotalTransferSize(BridgeManager *bridgeManager, const vector<PartitionFile>& partitionFiles, FILE *pitFile, bool repartition)
{
int totalBytes = 0;
unsigned int totalBytes = 0;
for (vector<PartitionFile>::const_iterator it = partitionFiles.begin(); it != partitionFiles.end(); it++)
{
fseek(it->file, 0, SEEK_END);
totalBytes += ftell(it->file);
rewind(it->file);
FileSeek(it->file, 0, SEEK_END);
totalBytes += (unsigned int)FileTell(it->file);
FileRewind(it->file);
}
if (repartition)
{
fseek(pitFile, 0, SEEK_END);
totalBytes += ftell(pitFile);
rewind(pitFile);
FileSeek(pitFile, 0, SEEK_END);
totalBytes += (unsigned int)FileTell(pitFile);
FileRewind(pitFile);
}
bool success;
@@ -168,7 +168,7 @@ static bool sendTotalTransferSize(BridgeManager *bridgeManager, const vector<Par
if (!success)
{
Interface::PrintError("Failed to send total bytes device info packet!\n");
Interface::PrintError("Failed to send total bytes packet!\n");
return (false);
}
@@ -179,13 +179,13 @@ static bool sendTotalTransferSize(BridgeManager *bridgeManager, const vector<Par
if (!success)
{
Interface::PrintError("Failed to receive device info response!\n");
Interface::PrintError("Failed to receive session total bytes response!\n");
return (false);
}
if (totalBytesResult != 0)
{
Interface::PrintError("Unexpected device info response!\nExpected: 0\nReceived:%d\n", totalBytesResponse);
Interface::PrintError("Unexpected session total bytes response!\nExpected: 0\nReceived:%d\n", totalBytesResponse);
return (false);
}
@@ -316,9 +316,9 @@ static PitData *getPitData(BridgeManager *bridgeManager, FILE *pitFile, bool rep
{
// Load the local pit file into memory.
fseek(pitFile, 0, SEEK_END);
long localPitFileSize = ftell(pitFile);
rewind(pitFile);
FileSeek(pitFile, 0, SEEK_END);
unsigned int localPitFileSize = (unsigned int)FileTell(pitFile);
FileRewind(pitFile);
unsigned char *pitFileBuffer = new unsigned char[localPitFileSize];
memset(pitFileBuffer, 0, localPitFileSize);
@@ -327,7 +327,7 @@ static PitData *getPitData(BridgeManager *bridgeManager, FILE *pitFile, bool rep
if (dataRead > 0)
{
rewind(pitFile);
FileRewind(pitFile);
localPitData = new PitData();
localPitData->Unpack(pitFileBuffer);
+13
Ver Arquivo
@@ -30,6 +30,12 @@
#define va_copy(d, s) ((d) = (s))
#endif
#define FileOpen(FILE, MODE) fopen(FILE, MODE)
#define FileClose(FILE) fclose(FILE)
#define FileSeek(FILE, OFFSET, ORIGIN) _fseeki64(FILE, OFFSET, ORIGIN)
#define FileTell(FILE) _ftelli64(FILE)
#define FileRewind(FILE) rewind(FILE)
#else
#include "../config.h"
@@ -37,6 +43,13 @@
#if defined(OS_DARWIN) || defined(OS_LINUX)
#include <unistd.h>
#define Sleep(t) usleep(1000*t)
#define FileOpen(FILE, MODE) fopen(FILE, MODE)
#define FileClose(FILE) fclose(FILE)
#define FileSeek(FILE, OFFSET, ORIGIN) fseeko(FILE, OFFSET, ORIGIN)
#define FileTell(FILE) ftello(FILE)
#define FileRewind(FILE) rewind(FILE)
#else
#error operating system not supported
#endif
+5 -5
Ver Arquivo
@@ -115,7 +115,7 @@ int PrintPitAction::Execute(int argc, char **argv)
{
const char *filename = fileArgument->GetValue().c_str();
localPitFile = fopen(filename, "rb");
localPitFile = FileOpen(filename, "rb");
if (!localPitFile)
{
@@ -133,14 +133,14 @@ int PrintPitAction::Execute(int argc, char **argv)
{
// Print PIT from file; there's no need for a BridgeManager.
fseek(localPitFile, 0, SEEK_END);
long localPitFileSize = ftell(localPitFile);
rewind(localPitFile);
FileSeek(localPitFile, 0, SEEK_END);
unsigned int localPitFileSize = (unsigned int)FileTell(localPitFile);
FileRewind(localPitFile);
// Load the local pit file into memory.
unsigned char *pitFileBuffer = new unsigned char[localPitFileSize];
size_t dataRead = fread(pitFileBuffer, 1, localPitFileSize, localPitFile); // dataRead is discarded, it's here to remove warnings.
fclose(localPitFile);
FileClose(localPitFile);
PitData *pitData = new PitData();
pitData->Unpack(pitFileBuffer);
+4 -4
Ver Arquivo
@@ -38,11 +38,11 @@ namespace Heimdall
{
memset(data, 0, size);
long position = ftell(file);
unsigned int position = (unsigned int)FileTell(file);
fseek(file, 0, SEEK_END);
long fileSize = ftell(file);
fseek(file, position, SEEK_SET);
FileSeek(file, 0, SEEK_END);
unsigned int fileSize = (unsigned int)FileTell(file);
FileSeek(file, position, SEEK_SET);
// min(fileSize, size)
unsigned int bytesToRead = (fileSize < size) ? fileSize - position : size;