1 /* 2 * ftruncate: ioengine for git://git.kernel.dk/fio.git 3 * 4 * IO engine that does regular truncates to simulate data transfer 5 * as fio ioengine. 6 * DDIR_WRITE does ftruncate 7 * 8 */ 9 #include <stdio.h> 10 #include <stdlib.h> 11 #include <unistd.h> 12 #include <sys/uio.h> 13 #include <errno.h> 14 #include <assert.h> 15 #include <fcntl.h> 16 17 #include "../fio.h" 18 #include "../filehash.h" 19 20 static int fio_ftruncate_queue(struct thread_data *td, struct io_u *io_u) 21 { 22 struct fio_file *f = io_u->file; 23 int ret; 24 fio_ro_check(td, io_u); 25 26 if (io_u->ddir != DDIR_WRITE) { 27 io_u->error = EINVAL; 28 return FIO_Q_COMPLETED; 29 } 30 ret = ftruncate(f->fd, io_u->offset); 31 32 if (ret) 33 io_u->error = errno; 34 35 return FIO_Q_COMPLETED; 36 } 37 38 static struct ioengine_ops ioengine = { 39 .name = "ftruncate", 40 .version = FIO_IOOPS_VERSION, 41 .queue = fio_ftruncate_queue, 42 .open_file = generic_open_file, 43 .close_file = generic_close_file, 44 .get_file_size = generic_get_file_size, 45 .flags = FIO_SYNCIO | FIO_FAKEIO 46 }; 47 48 static void fio_init fio_syncio_register(void) 49 { 50 register_ioengine(&ioengine); 51 } 52 53 static void fio_exit fio_syncio_unregister(void) 54 { 55 unregister_ioengine(&ioengine); 56 } 57