+/*
+ * Mark a given offset as used in the map.
+ */
+static void mark_random_map(struct thread_data *td, struct fio_file *f,
+ struct io_u *io_u)
+{
+ unsigned int min_bs = td->rw_min_bs;
+ unsigned long long block;
+ unsigned int blocks;
+ unsigned int nr_blocks;
+
+ block = io_u->offset / (unsigned long long) min_bs;
+ blocks = 0;
+ nr_blocks = (io_u->buflen + min_bs - 1) / min_bs;
+
+ while (blocks < nr_blocks) {
+ unsigned int idx, bit;
+
+ if (!random_map_free(td, f, block))
+ break;
+
+ idx = RAND_MAP_IDX(td, f, block);
+ bit = RAND_MAP_BIT(td, f, block);
+
+ fio_assert(td, idx < f->num_maps);
+
+ f->file_map[idx] |= (1UL << bit);
+ block++;
+ blocks++;
+ }
+
+ if ((blocks * min_bs) < io_u->buflen)
+ io_u->buflen = blocks * min_bs;
+}
+