Refactor #includes and headers
[fio.git] / engines / ftruncate.c
CommitLineData
a467027e
DM
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 */
a467027e 9#include <errno.h>
3d2d14bc 10#include <unistd.h>
a467027e
DM
11
12#include "../fio.h"
a467027e
DM
13
14static int fio_ftruncate_queue(struct thread_data *td, struct io_u *io_u)
15{
16 struct fio_file *f = io_u->file;
17 int ret;
18 fio_ro_check(td, io_u);
19
20 if (io_u->ddir != DDIR_WRITE) {
21 io_u->error = EINVAL;
22 return FIO_Q_COMPLETED;
23 }
24 ret = ftruncate(f->fd, io_u->offset);
25
26 if (ret)
27 io_u->error = errno;
28
29 return FIO_Q_COMPLETED;
30}
31
32static struct ioengine_ops ioengine = {
33 .name = "ftruncate",
34 .version = FIO_IOOPS_VERSION,
35 .queue = fio_ftruncate_queue,
36 .open_file = generic_open_file,
37 .close_file = generic_close_file,
38 .get_file_size = generic_get_file_size,
39 .flags = FIO_SYNCIO | FIO_FAKEIO
40};
41
42static void fio_init fio_syncio_register(void)
43{
44 register_ioengine(&ioengine);
45}
46
47static void fio_exit fio_syncio_unregister(void)
48{
49 unregister_ioengine(&ioengine);
50}