From ad1bc59382e3cda63ce507cd7f56fc2a201c11e9 Mon Sep 17 00:00:00 2001 From: Gediminas Jakutis Date: Tue, 25 Feb 2020 09:57:14 +0200 Subject: implement reading from dev-you-random for datagen. Signed-off-by: Gediminas Jakutis --- src/main.c | 42 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index ee0ad52..ca3b600 100644 --- a/src/main.c +++ b/src/main.c @@ -5,30 +5,17 @@ #include #include "io.h" -enum opmode { - mode_normal, - mode_fetch, - mode_generate -}; - static const unsigned int FLAG_DATA_FORMAT = (1 << 0); static const unsigned int FLAG_DATA_ACCESS = (1 << 1); static char randfile[] = "/dev/urandom"; -static struct settings_s { - size_t ss; - size_t to; - char *filein; - char *fileout; - unsigned int flags; - enum opmode opmode; -} settings = {0}; +static struct settings settings = {0}; -static struct stream file_in = {.last_idx = -1, .fd = -1}; -static struct stream file_out = {.last_idx = -1, .fd = -1, .out = 1}; +static struct stream file_in = {.prev_idx = -1, .fd = -1}; +static struct stream file_out = {.prev_idx = -1, .fd = -1, .out = 1}; -static int parseargs(int argc, char **argv, struct settings_s * settings); +static int parseargs(int argc, char **argv, struct settings * settings); void printhelp(const char * const name); int main(int argc, char **argv) @@ -42,21 +29,19 @@ int main(int argc, char **argv) if (settings.opmode == mode_generate) { file_in.name = randfile; file_in.out = -1; + file_in.n = settings.to; + file_out.n = settings.to; } else { file_in.name = settings.filein; } file_out.name = settings.fileout ? settings.fileout : settings.filein; - file_in.stride = settings.opmode & FLAG_DATA_FORMAT ? sizeof(struct entry_l) : sizeof(struct entry_a); - if ((ret = stream_open(&file_in))) { + if ((ret = stream_open(&file_in, &settings))) { goto out; } - file_out.n = file_in.n; - file_out.stride = file_in.stride; - - if ((ret = stream_open(&file_out))) { + if ((ret = stream_open(&file_out, &settings))) { goto out; } @@ -66,9 +51,9 @@ out: return ret; } -static int parseargs(int argc, char **argv, struct settings_s * settings) +static int parseargs(int argc, char **argv, struct settings * settings) { - struct settings_s s = {0}; + struct settings s = {0}; ssize_t i; int ret = 0; @@ -124,13 +109,16 @@ static int parseargs(int argc, char **argv, struct settings_s * settings) s.fileout = s.filein; } - s.to = s.ss + s.to; - /* we always generate in-memory for speed */ if (s.opmode == mode_generate) { + /* we always generate in-memory for speed */ s.opmode &= ~FLAG_DATA_ACCESS; + } else if (s.opmode == mode_fetch) { + s.to = s.ss + s.to; } + s.stride = s.opmode & FLAG_DATA_FORMAT ? sizeof(struct entry_l) : sizeof(struct entry); + *settings = s; while (0) { -- cgit v1.2.3