From 59d9e9c08404f41a4ea18c8492cbce926c172e27 Mon Sep 17 00:00:00 2001 From: chris t Date: Sun, 11 Oct 2020 18:59:23 -0700 Subject: [PATCH] more readme, some renaming --- README | 23 +++++++++++++++++++++++ fuse.c | 10 ++++++---- mersenne.c | 12 ++++++------ pcg.c | 2 +- 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/README b/README index 5e8c43d..97322bb 100644 --- a/README +++ b/README @@ -1 +1,24 @@ noisebox -- a FUSE filesystem that contains predictable PRNG output. + + +Requirements +--- + +Pretty light. Tested to compile on Fedora and Ubuntu. Requires a +compiler and associated toolchain. + +Required packages: + + * libfuse-devel + +Required non-packages (as of this writing): + + * pcg-c [https://github.com/imneme/pcg-c] + + + TODO + --- + + * Add some unit tests. + * Fix mersenne output. + * Profile memory usage. I suspect there are leaks. diff --git a/fuse.c b/fuse.c index 456087a..2d61a3f 100644 --- a/fuse.c +++ b/fuse.c @@ -196,10 +196,12 @@ static int do_open(const char* path, struct fuse_file_info* fi) { } // check if file is already opened. - get_file_state(path, fi); - if(fi->fh) { - return 0; - } + // never mind, we want to support multiple concurrent reads from + // the same file. + // get_file_state(path, fi); + // if(fi->fh) { + // return 0; + // } if(n->do_open) { ret = n->do_open(path, fi); diff --git a/mersenne.c b/mersenne.c index 75bc776..ee3d200 100644 --- a/mersenne.c +++ b/mersenne.c @@ -34,17 +34,17 @@ enum { // state for single generator. -struct mt_state { +typedef struct mt_random_t { uint32_t mt[N]; int index; off_t begin; size_t consumed; char overflow[4]; int overflow_len; -}; +} mt_random_t; -static void twist(struct mt_state *state) { +static void twist(mt_random_t *state) { uint32_t i, x, xA; uint32_t *mt = state->mt; @@ -60,7 +60,7 @@ static void twist(struct mt_state *state) { state->index = 0; } -static void mt_init(struct mt_state *state, const uint32_t seed) { +static void mt_init(mt_random_t *state, const uint32_t seed) { uint32_t i; uint32_t *mt = state->mt; mt[0] = seed; @@ -72,7 +72,7 @@ static void mt_init(struct mt_state *state, const uint32_t seed) { twist(state); } -static uint32_t extract_u32(struct mt_state *state) { +static uint32_t extract_u32(mt_random_t *state) { uint32_t y; if(state->index >= N) { @@ -111,7 +111,7 @@ static int get_noise(size_t n, off_t offset, char* buf, printf("getting random bits: %i@%i (%i)\n", n, offset, n*sizeof(char)); // FIXME this is wrong. - struct mt_state *state = (struct mt_state *)(fi->fh); + mt_random_t *state = (mt_random_t *)(fi->fh); float buf_ratio = (float)sizeof(char)/(float)sizeof(uint32_t); if(offset != state->consumed * buf_ratio) { printf("wrong offset, discarding state\n"); diff --git a/pcg.c b/pcg.c index 2cac454..68d1342 100644 --- a/pcg.c +++ b/pcg.c @@ -39,7 +39,7 @@ static int do_open(const char *path, struct fuse_file_info *fi) { } static int do_release(const char *path, struct fuse_file_info *fi) { - free((void *)fi->fh); + free((void *)(fi->fh)); return 0; }