Fabcoin Core  0.16.2
P2P Digital Currency
Macros | Enumerations | Functions
io.h File Reference
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <inttypes.h>
#include "endian.h"
#include "ethash.h"
Include dependency graph for io.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DAG_MUTABLE_NAME_MAX_SIZE   (6 + 10 + 1 + 16 + 1)
 
#define ETHASH_CRITICAL(...)
 Logs a critical error in important parts of ethash. More...
 

Enumerations

enum  ethash_io_rc { ETHASH_IO_FAIL = 0, ETHASH_IO_MEMO_SIZE_MISMATCH, ETHASH_IO_MEMO_MISMATCH, ETHASH_IO_MEMO_MATCH }
 Possible return values of. More...
 

Functions

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. More...
 
FILE * ethash_fopen (char const *file_name, char const *mode)
 An fopen wrapper for no-warnings crossplatform fopen. More...
 
char * ethash_strncat (char *dest, size_t dest_size, char const *src, size_t count)
 An strncat wrapper for no-warnings crossplatform strncat. More...
 
bool ethash_mkdir (char const *dirname)
 A cross-platform mkdir wrapper to create a directory or assert it's there. More...
 
bool ethash_file_size (FILE *f, size_t *ret_size)
 Get a file's size. More...
 
int ethash_fileno (FILE *f)
 Get a file descriptor number from a FILE stream. More...
 
char * ethash_io_create_filename (char const *dirname, char const *filename, size_t filename_length)
 Create the filename for the DAG. More...
 
bool ethash_get_default_dirname (char *strbuf, size_t buffsize)
 Gets the default directory name for the DAG depending on the system. More...
 

Detailed Description

Author
Lefteris Karapetsas lefte.nosp@m.ris@.nosp@m.ethde.nosp@m.v.co.nosp@m.m
Date
2015

Definition in file io.h.

Macro Definition Documentation

#define DAG_MUTABLE_NAME_MAX_SIZE   (6 + 10 + 1 + 16 + 1)

Definition at line 42 of file io.h.

#define ETHASH_CRITICAL (   ...)

Logs a critical error in important parts of ethash.

Should mostly help figure out what kind of problem (I/O, memory e.t.c.) causes a NULL ethash_full_t

Definition at line 71 of file io.h.

Enumeration Type Documentation

Possible return values of.

See also
ethash_io_prepare
Enumerator
ETHASH_IO_FAIL 

There has been an IO failure.

ETHASH_IO_MEMO_SIZE_MISMATCH 

DAG with revision/hash match, but file size was wrong.

ETHASH_IO_MEMO_MISMATCH 

The DAG file did not exist or there was revision/hash mismatch.

ETHASH_IO_MEMO_MATCH 

DAG file existed and revision/hash matched. No need to do anything.

Definition at line 44 of file io.h.

Function Documentation

bool ethash_file_size ( FILE *  f,
size_t *  ret_size 
)

Get a file's size.

Parameters
[in]fThe open file stream whose size to get
[out]sizePass a size_t by reference to contain the file size
Returns
true in success and false if there was a failure

Definition at line 78 of file io_posix.c.

Here is the caller graph for this function:

int ethash_fileno ( FILE *  f)

Get a file descriptor number from a FILE stream.

Parameters
fThe file stream whose fd to get
Returns
Platform specific fd handler

Definition at line 48 of file io_posix.c.

Here is the caller graph for this function:

FILE* ethash_fopen ( char const *  file_name,
char const *  mode 
)

An fopen wrapper for no-warnings crossplatform fopen.

Msvc compiler considers fopen to be insecure and suggests to use their alternative. This is a wrapper for this alternative. Another way is to #define _CRT_SECURE_NO_WARNINGS, but disabling all security warnings does not sound like a good idea.

Parameters
file_nameThe path to the file to open
modeOpening mode. Check fopen()
Returns
The FILE* or NULL in failure

Definition at line 32 of file io_posix.c.

Here is the call graph for this function:

Here is the caller graph for this function:

bool ethash_get_default_dirname ( char *  strbuf,
size_t  buffsize 
)

Gets the default directory name for the DAG depending on the system.

The spec defining this directory is here: https://github.com/ethereum/wiki/wiki/Ethash-DAG

Parameters
[out]strbufA string buffer of sufficient size to keep the null termninated string of the directory name
[in]buffsizeSize of strbuf in bytes
Returns
true for success and false otherwise

Definition at line 89 of file io_posix.c.

Here is the call graph for this function:

Here is the caller graph for this function:

char* ethash_io_create_filename ( char const *  dirname,
char const *  filename,
size_t  filename_length 
)

Create the filename for the DAG.

Parameters
dirnameThe directory name in which the DAG file should reside If it does not end with a directory separator it is appended.
filenameThe actual name of the file
filename_lengthThe length of the filename in bytes
Returns
A char* containing the full name. User must deallocate.

Definition at line 53 of file io_posix.c.

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Create the DAG directory and the DAG file if they don't exist.

Parameters
[in]dirnameA null terminated c-string of the path of the ethash data directory. If it does not exist it's created.
[in]seedhashThe seedhash of the current block number, used in the naming of the file as can be seen from the spec at: https://github.com/ethereum/wiki/wiki/Ethash-DAG
[out]output_fileIf there was no failure then this will point to an open file descriptor. User is responsible for closing it. In the case of memo match then the file is open on read mode, while on the case of mismatch a new file is created on write mode
[in]file_sizeThe size that the DAG file should have on disk
[out]force_createIf true then there is no check to see if the file already exists
Returns
For possible return values
See also
enum ethash_io_rc

Definition at line 26 of file io.c.

Here is the call graph for this function:

Here is the caller graph for this function:

bool ethash_mkdir ( char const *  dirname)

A cross-platform mkdir wrapper to create a directory or assert it's there.

Parameters
dirnameThe full path of the directory to create
Returns
true if the directory was created or if it already existed

Definition at line 42 of file io_posix.c.

Here is the caller graph for this function:

char* ethash_strncat ( char *  dest,
size_t  dest_size,
char const *  src,
size_t  count 
)

An strncat wrapper for no-warnings crossplatform strncat.

Msvc compiler considers strncat to be insecure and suggests to use their alternative. This is a wrapper for this alternative. Another way is to #define _CRT_SECURE_NO_WARNINGS, but disabling all security warnings does not sound like a good idea.

Parameters
desDestination buffer
dest_sizeMaximum size of the destination buffer. This is the extra argument for the MSVC secure strncat
srcSouce buffer
countNumber of bytes to copy from source
Returns
If all is well returns the dest buffer. If there is an error returns NULL

Definition at line 37 of file io_posix.c.

Here is the caller graph for this function: