Fix signed int/long truncation on 32-bit architectures
[fio.git] / filesetup.c
index 9d42deb02d47dbab2866fcb9d2512409e60aa1b5..1350857ffb04d9f4ed1274298675f9a94adf44a8 100644 (file)
@@ -78,7 +78,7 @@ static int extend_file(struct thread_data *td, struct fio_file *f)
                }
        }
 #endif
-       
+
        if (!new_layout)
                goto done;
 
@@ -208,11 +208,18 @@ static int pre_read_file(struct thread_data *td, struct fio_file *f)
 static unsigned long long get_rand_file_size(struct thread_data *td)
 {
        unsigned long long ret, sized;
-       long r;
+       unsigned long r;
+
+       if (td->o.use_os_rand) {
+               r = os_random_long(&td->file_size_state);
+               sized = td->o.file_size_high - td->o.file_size_low;
+               ret = (unsigned long long) ((double) sized * (r / (OS_RAND_MAX + 1.0)));
+       } else {
+               r = __rand(&td->__file_size_state);
+               sized = td->o.file_size_high - td->o.file_size_low;
+               ret = (unsigned long long) ((double) sized * (r / (FRAND_MAX + 1.0)));
+       }
 
-       r = os_random_long(&td->file_size_state);
-       sized = td->o.file_size_high - td->o.file_size_low;
-       ret = (unsigned long long) ((double) sized * (r / (OS_RAND_MAX + 1.0)));
        ret += td->o.file_size_low;
        ret -= (ret % td->o.rw_min_bs);
        return ret;
@@ -233,7 +240,7 @@ static int file_size(struct thread_data *td, struct fio_file *f)
 
 static int bdev_size(struct thread_data *td, struct fio_file *f)
 {
-       unsigned long long bytes;
+       unsigned long long bytes = 0;
        int r;
 
        if (td->io_ops->open_file(td, f)) {
@@ -265,7 +272,7 @@ err:
 static int char_size(struct thread_data *td, struct fio_file *f)
 {
 #ifdef FIO_HAVE_CHARDEV_SIZE
-       unsigned long long bytes;
+       unsigned long long bytes = 0;
        int r;
 
        if (td->io_ops->open_file(td, f)) {
@@ -812,7 +819,7 @@ int init_random_map(struct thread_data *td)
                                (unsigned long long) td->o.rw_min_bs;
                num_maps = (blocks + BLOCKS_PER_MAP - 1) /
                                (unsigned long long) BLOCKS_PER_MAP;
-               f->file_map = smalloc(num_maps * sizeof(int));
+               f->file_map = smalloc(num_maps * sizeof(unsigned long));
                if (f->file_map) {
                        f->num_maps = num_maps;
                        continue;