filesetup: fix size percentage calculations when using offset
[fio.git] / filesetup.c
index cd486eaa41186ec3668e22b687ec868962b2a571..8a0968d66debfe329e816ee0f5f92abc749f018e 100644 (file)
@@ -239,6 +239,9 @@ static int pre_read_file(struct thread_data *td, struct fio_file *f)
            td_ioengine_flagged(td, FIO_NOIO))
                return 0;
 
+       if (f->filetype == FIO_TYPE_CHAR)
+               return 0;
+
        if (!fio_file_open(f)) {
                if (td->io_ops->open_file(td, f)) {
                        log_err("fio: cannot pre-read, failed to open file\n");
@@ -983,7 +986,14 @@ int setup_files(struct thread_data *td)
                        total_size = -1ULL;
                else {
                         if (o->size_percent) {
-                               f->io_size = (f->io_size * o->size_percent) / 100;
+                               uint64_t file_size;
+
+                               file_size = f->io_size + f->file_offset;
+                               f->io_size = (file_size *
+                                             o->size_percent) / 100;
+                               if (f->io_size > (file_size - f->file_offset))
+                                       f->io_size = file_size - f->file_offset;
+
                                f->io_size -= (f->io_size % td_min_bs(td));
                        }
                        total_size += f->io_size;