- int flags;
-
- if (td_rw(td))
- flags = PROT_READ | PROT_WRITE;
- else if (td_write(td)) {
- flags = PROT_WRITE;
-
- if (td->verify != VERIFY_NONE)
- flags |= PROT_READ;
- } else
- flags = PROT_READ;
-
- f->mmap = mmap(NULL, f->file_size, flags, MAP_SHARED, f->fd, f->file_offset);
- if (f->mmap == MAP_FAILED) {
- f->mmap = NULL;
- td_verror(td, errno, "mmap");
- return 1;
- }
-
- if (td->invalidate_cache && file_invalidate_cache(td, f))
- return 1;
-
- if (!td_random(td)) {
- if (madvise(f->mmap, f->file_size, MADV_SEQUENTIAL) < 0) {
- td_verror(td, errno, "madvise");
- return 1;
- }
- } else {
- if (madvise(f->mmap, f->file_size, MADV_RANDOM) < 0) {
- td_verror(td, errno, "madvise");
- return 1;
- }
- }
-
- return 0;
-}
-
-static int setup_files_mmap(struct thread_data *td)
-{
- struct fio_file *f;
- int i, err = 0;
-
- for_each_file(td, f, i) {
- err = __setup_file_mmap(td, f);
- if (err)
- break;
- }
-
- return err;
-}
-
-static int __setup_file_plain(struct thread_data *td, struct fio_file *f)
-{
- if (td->invalidate_cache && file_invalidate_cache(td, f))
- return 1;
-
- if (!td_random(td)) {
- if (fadvise(f->fd, f->file_offset, f->file_size, POSIX_FADV_SEQUENTIAL) < 0) {
- td_verror(td, errno, "fadvise");
- return 1;
- }
- } else {
- if (fadvise(f->fd, f->file_offset, f->file_size, POSIX_FADV_RANDOM) < 0) {
- td_verror(td, errno, "fadvise");
- return 1;
- }
- }
-
- return 0;
-}
-
-static int setup_files_plain(struct thread_data *td)
-{
- struct fio_file *f;
- int i, err = 0;
-
- for_each_file(td, f, i) {
- err = __setup_file_plain(td, f);
- if (err)
- break;
- }
-
- return err;