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