Fabcoin Core  0.16.2
P2P Digital Currency
io.h
Go to the documentation of this file.
1 /*
2  This file is part of ethash.
3 
4  ethash is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  ethash is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with ethash. If not, see <http://www.gnu.org/licenses/>.
16 */
21 #pragma once
22 #include <stdlib.h>
23 #include <stdint.h>
24 #include <stdbool.h>
25 #include <stdio.h>
26 #ifdef __cplusplus
27 #define __STDC_FORMAT_MACROS 1
28 #endif
29 #include <inttypes.h>
30 #include "endian.h"
31 #include "ethash.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 // Maximum size for mutable part of DAG file name
37 // 6 is for "full-R", the suffix of the filename
38 // 10 is for maximum number of digits of a uint32_t (for REVISION)
39 // 1 is for - and 16 is for the first 16 hex digits for first 8 bytes of
40 // the seedhash and last 1 is for the null terminating character
41 // Reference: https://github.com/ethereum/wiki/wiki/Ethash-DAG
42 #define DAG_MUTABLE_NAME_MAX_SIZE (6 + 10 + 1 + 16 + 1)
43 enum ethash_io_rc {
49 };
50 
51 // small hack for windows. I don't feel I should use va_args and forward just
52 // to have this one function properly cross-platform abstracted
53 #if defined(_WIN32) && !defined(__GNUC__)
54 #define snprintf(...) sprintf_s(__VA_ARGS__)
55 #endif
56 
62 #ifdef ETHASH_PRINT_CRITICAL_OUTPUT
63 #define ETHASH_CRITICAL(...) \
64  do \
65  { \
66  printf("ETHASH CRITICAL ERROR: "__VA_ARGS__); \
67  printf("\n"); \
68  fflush(stdout); \
69  } while (0)
70 #else
71 #define ETHASH_CRITICAL(...)
72 #endif
73 
95  char const* dirname,
96  ethash_h256_t const seedhash,
97  FILE** output_file,
98  uint64_t file_size,
99  bool force_create
100 );
101 
114 FILE* ethash_fopen(char const* file_name, char const* mode);
115 
132 char* ethash_strncat(char* dest, size_t dest_size, char const* src, size_t count);
133 
141 bool ethash_mkdir(char const* dirname);
142 
150 bool ethash_file_size(FILE* f, size_t* ret_size);
151 
158 int ethash_fileno(FILE* f);
159 
170  char const* dirname,
171  char const* filename,
172  size_t filename_length
173 );
174 
185 bool ethash_get_default_dirname(char* strbuf, size_t buffsize);
186 
187 static inline bool ethash_io_mutable_name(
188  uint32_t revision,
189  ethash_h256_t const* seed_hash,
190  char* output
191 )
192 {
193  uint64_t hash = *((uint64_t*)seed_hash);
194 #if LITTLE_ENDIAN == BYTE_ORDER
195  hash = ethash_swap_u64(hash);
196 #endif
197  return snprintf(output, DAG_MUTABLE_NAME_MAX_SIZE, "full-R%u-%016" PRIx64, revision, hash) >= 0;
198 }
199 
200 #ifdef __cplusplus
201 }
202 #endif
ethash_io_rc
Possible return values of.
Definition: io.h:44
#define ethash_swap_u64(input_)
Definition: endian.h:41
DAG with revision/hash match, but file size was wrong.
Definition: io.h:46
char * ethash_io_create_filename(char const *dirname, char const *filename, size_t filename_length)
Create the filename for the DAG.
Definition: io_posix.c:53
size_t count
Definition: ExecStats.cpp:37
evm_mode mode
Definition: SmartVM.cpp:47
bool ethash_file_size(FILE *f, size_t *ret_size)
Get a file&#39;s size.
Definition: io_posix.c:78
char * ethash_strncat(char *dest, size_t dest_size, char const *src, size_t count)
An strncat wrapper for no-warnings crossplatform strncat.
Definition: io_posix.c:37
FILE * ethash_fopen(char const *file_name, char const *mode)
An fopen wrapper for no-warnings crossplatform fopen.
Definition: io_posix.c:32
DAG file existed and revision/hash matched. No need to do anything.
Definition: io.h:48
int ethash_fileno(FILE *f)
Get a file descriptor number from a FILE stream.
Definition: io_posix.c:48
enum ethash_io_rc ethash_io_prepare(char const *dirname, ethash_h256_t const seedhash, FILE **output_file, uint64_t file_size, bool force_create)
Prepares io for ethash.
Definition: io.c:26
Type of a seedhash/blockhash e.t.c.
Definition: ethash.h:48
#define f(x)
Definition: gost.cpp:57
The DAG file did not exist or there was revision/hash mismatch.
Definition: io.h:47
#define DAG_MUTABLE_NAME_MAX_SIZE
Definition: io.h:42
bool ethash_mkdir(char const *dirname)
A cross-platform mkdir wrapper to create a directory or assert it&#39;s there.
Definition: io_posix.c:42
bool ethash_get_default_dirname(char *strbuf, size_t buffsize)
Gets the default directory name for the DAG depending on the system.
Definition: io_posix.c:89
There has been an IO failure.
Definition: io.h:45