Windows: always open files in binary mode
authorBruce Cran <bcran@fusionio.com>
Mon, 28 Apr 2014 21:54:43 +0000 (15:54 -0600)
committerJens Axboe <axboe@fb.com>
Tue, 29 Apr 2014 00:10:43 +0000 (18:10 -0600)
On Windows, open() defaults to text mode, causing control characters
to be interpreted. Avoid this by passing the _O_BINARY flag.

Signed-off-by: Jens Axboe <axboe@fb.com>
filesetup.c

index b6cf2e7df1e9e8b47681917a1d43741168d9e2bd..ad7fb8551da7b87889e3e0ec5d087089e918b5fd 100644 (file)
@@ -69,6 +69,10 @@ static int extend_file(struct thread_data *td, struct fio_file *f)
        if (new_layout)
                flags |= O_TRUNC;
 
        if (new_layout)
                flags |= O_TRUNC;
 
+#ifdef WIN32
+       flags |= _O_BINARY;
+#endif
+
        dprint(FD_FILE, "open file %s, flags %x\n", f->file_name, flags);
        f->fd = open(f->file_name, flags, 0644);
        if (f->fd < 0) {
        dprint(FD_FILE, "open file %s, flags %x\n", f->file_name, flags);
        f->fd = open(f->file_name, flags, 0644);
        if (f->fd < 0) {
@@ -481,6 +485,10 @@ int file_lookup_open(struct fio_file *f, int flags)
                from_hash = 0;
        }
 
                from_hash = 0;
        }
 
+#ifdef WIN32
+       flags |= _O_BINARY;
+#endif
+
        f->fd = open(f->file_name, flags, 0600);
        return from_hash;
 }
        f->fd = open(f->file_name, flags, 0600);
        return from_hash;
 }
@@ -1040,7 +1048,7 @@ int init_random_map(struct thread_data *td)
                        unsigned long seed;
 
                        seed = td->rand_seeds[FIO_RAND_BLOCK_OFF];
                        unsigned long seed;
 
                        seed = td->rand_seeds[FIO_RAND_BLOCK_OFF];
-                       
+
                        if (!lfsr_init(&f->lfsr, blocks, seed, 0))
                                continue;
                } else if (!td->o.norandommap) {
                        if (!lfsr_init(&f->lfsr, blocks, seed, 0))
                                continue;
                } else if (!td->o.norandommap) {