zbd: Declare local functions 'static'
[fio.git] / lib / rand.c
index 12916cf00ddfd2b6d6ec31e82258300836cb3537..69acb06c14410296f959da96f27fe842f57eede1 100644 (file)
@@ -34,9 +34,8 @@
 */
 
 #include <string.h>
-#include <assert.h>
 #include "rand.h"
-#include "lib/pattern.h"
+#include "pattern.h"
 #include "../hash.h"
 
 int arch_random;
@@ -46,7 +45,7 @@ static inline uint64_t __seed(uint64_t x, uint64_t m)
        return (x < m) ? x + m : x;
 }
 
-void __init_rand32(struct taus88_state *state, unsigned int seed)
+static void __init_rand32(struct taus88_state *state, unsigned int seed)
 {
        int cranks = 6;
 
@@ -60,7 +59,7 @@ void __init_rand32(struct taus88_state *state, unsigned int seed)
                __rand32(state);
 }
 
-void __init_rand64(struct taus258_state *state, uint64_t seed)
+static void __init_rand64(struct taus258_state *state, uint64_t seed)
 {
        int cranks = 6;
 
@@ -96,7 +95,7 @@ void init_rand_seed(struct frand_state *state, unsigned int seed, bool use64)
                __init_rand64(&state->state64, seed);
 }
 
-void __fill_random_buf(void *buf, unsigned int len, unsigned long seed)
+void __fill_random_buf(void *buf, unsigned int len, uint64_t seed)
 {
        void *ptr = buf;
 
@@ -123,10 +122,10 @@ void __fill_random_buf(void *buf, unsigned int len, unsigned long seed)
        }
 }
 
-unsigned long fill_random_buf(struct frand_state *fs, void *buf,
-                             unsigned int len)
+uint64_t fill_random_buf(struct frand_state *fs, void *buf,
+                        unsigned int len)
 {
-       unsigned long r = __rand(fs);
+       uint64_t r = __rand(fs);
 
        if (sizeof(int) != sizeof(long *))
                r *= (unsigned long) __rand(fs);
@@ -135,7 +134,7 @@ unsigned long fill_random_buf(struct frand_state *fs, void *buf,
        return r;
 }
 
-void __fill_random_buf_percentage(unsigned long seed, void *buf,
+void __fill_random_buf_percentage(uint64_t seed, void *buf,
                                  unsigned int percentage,
                                  unsigned int segment, unsigned int len,
                                  char *pattern, unsigned int pbytes)
@@ -157,7 +156,7 @@ void __fill_random_buf_percentage(unsigned long seed, void *buf,
                /*
                 * Fill random chunk
                 */
-               this_len = (segment * (100 - percentage)) / 100;
+               this_len = ((unsigned long long)segment * (100 - percentage)) / 100;
                if (this_len > len)
                        this_len = len;
 
@@ -167,6 +166,7 @@ void __fill_random_buf_percentage(unsigned long seed, void *buf,
                if (!len)
                        break;
                buf += this_len;
+               this_len = segment - this_len;
 
                if (this_len > len)
                        this_len = len;
@@ -183,12 +183,12 @@ void __fill_random_buf_percentage(unsigned long seed, void *buf,
        }
 }
 
-unsigned long fill_random_buf_percentage(struct frand_state *fs, void *buf,
-                                        unsigned int percentage,
-                                        unsigned int segment, unsigned int len,
-                                        char *pattern, unsigned int pbytes)
+uint64_t fill_random_buf_percentage(struct frand_state *fs, void *buf,
+                                   unsigned int percentage,
+                                   unsigned int segment, unsigned int len,
+                                   char *pattern, unsigned int pbytes)
 {
-       unsigned long r = __rand(fs);
+       uint64_t r = __rand(fs);
 
        if (sizeof(int) != sizeof(long *))
                r *= (unsigned long) __rand(fs);