Skip to content
This repository was archived by the owner on Oct 21, 2019. It is now read-only.

Commit 74af5dc

Browse files
committed
Fix failing to create DAG file larger than 2 Gb
1 parent a388e2e commit 74af5dc

5 files changed

Lines changed: 42 additions & 1 deletion

File tree

ethminer/MinerAux.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,20 @@ class MinerCLI
436436
{
437437
m_minerType = MinerType::Mixed;
438438
}
439+
else if ((arg == "-D" || arg == "--create-dag") && i + 1 < argc)
440+
{
441+
string m = boost::to_lower_copy(string(argv[++i]));
442+
mode = OperationMode::DAGInit;
443+
try
444+
{
445+
m_initDAG = stol(m);
446+
}
447+
catch (...)
448+
{
449+
cerr << "Bad " << arg << " option: " << m << endl;
450+
BOOST_THROW_EXCEPTION(BadArgument());
451+
}
452+
}
439453
/*
440454
else if (arg == "--current-block" && i + 1 < argc)
441455
m_currentBlock = stol(argv[++i]);
@@ -551,6 +565,10 @@ class MinerCLI
551565

552566
void execute()
553567
{
568+
if (mode == OperationMode::DAGInit) {
569+
doInitDAG(m_initDAG);
570+
}
571+
554572
if (m_shouldListDevices)
555573
{
556574
#if ETH_ETHASHCL || !ETH_TRUE
@@ -1210,6 +1228,8 @@ class MinerCLI
12101228
}
12111229
}
12121230
#endif
1231+
/// DAG initialisation param.
1232+
unsigned m_initDAG = 0;
12131233

12141234
/// Operating mode.
12151235
OperationMode mode;

libethash/io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ enum ethash_io_rc ethash_io_prepare(
9191
goto free_memo;
9292
}
9393
// make sure it's of the proper size
94-
if (fseek(f, (long int)(file_size + ETHASH_DAG_MAGIC_NUM_SIZE - 1), SEEK_SET) != 0) {
94+
if (ethash_fseek(f, file_size + ETHASH_DAG_MAGIC_NUM_SIZE - 1, SEEK_SET) != 0) {
9595
fclose(f);
9696
ETHASH_CRITICAL("Could not seek to the end of DAG file: \"%s\". Insufficient space?", tmpfile);
9797
goto free_memo;

libethash/io.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ enum ethash_io_rc ethash_io_prepare(
113113
*/
114114
FILE* ethash_fopen(char const* file_name, char const* mode);
115115

116+
/**
117+
* An fseek wrapper for crossplatform 64-bit seek.
118+
*
119+
* @param f The file stream whose fd to get
120+
* @param offset Number of bytes from @a origin
121+
* @param origin Initial position
122+
* @return Current offset or -1 to indicate an error
123+
*/
124+
int ethash_fseek(FILE* f, size_t offset, int origin);
125+
116126
/**
117127
* An strncat wrapper for no-warnings crossplatform strncat.
118128
*

libethash/io_posix.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ FILE* ethash_fopen(char const* file_name, char const* mode)
3434
return fopen(file_name, mode);
3535
}
3636

37+
int ethash_fseek(FILE* f, size_t offset, int origin)
38+
{
39+
return fseeko(f, offset, origin);
40+
}
41+
3742
char* ethash_strncat(char* dest, size_t dest_size, char const* src, size_t count)
3843
{
3944
return strlen(dest) + count + 1 <= dest_size ? strncat(dest, src, count) : NULL;

libethash/io_win32.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,19 @@
2626
#include <sys/stat.h>
2727
#include <sys/types.h>
2828
#include <shlobj.h>
29+
#include <io.h>
2930

3031
FILE* ethash_fopen(char const* file_name, char const* mode)
3132
{
3233
FILE* f;
3334
return fopen_s(&f, file_name, mode) == 0 ? f : NULL;
3435
}
3536

37+
int ethash_fseek(FILE* f, size_t offset, int origin)
38+
{
39+
return _fseeki64(f, offset, origin);
40+
}
41+
3642
char* ethash_strncat(char* dest, size_t dest_size, char const* src, size_t count)
3743
{
3844
return strncat_s(dest, dest_size, src, count) == 0 ? dest : NULL;

0 commit comments

Comments
 (0)