1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
4*49cdfc7eSAndroid Build Coastguard Worker * AUTHOR : William Roske
5*49cdfc7eSAndroid Build Coastguard Worker * CO-PILOT : Dave Fenner
6*49cdfc7eSAndroid Build Coastguard Worker */
7*49cdfc7eSAndroid Build Coastguard Worker
8*49cdfc7eSAndroid Build Coastguard Worker #include <unistd.h>
9*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
10*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
11*49cdfc7eSAndroid Build Coastguard Worker
12*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
13*49cdfc7eSAndroid Build Coastguard Worker
14*49cdfc7eSAndroid Build Coastguard Worker static char fname[255];
15*49cdfc7eSAndroid Build Coastguard Worker static int fd;
16*49cdfc7eSAndroid Build Coastguard Worker #define BUF "davef"
17*49cdfc7eSAndroid Build Coastguard Worker
verify_fsync(void)18*49cdfc7eSAndroid Build Coastguard Worker static void verify_fsync(void)
19*49cdfc7eSAndroid Build Coastguard Worker {
20*49cdfc7eSAndroid Build Coastguard Worker unsigned int i;
21*49cdfc7eSAndroid Build Coastguard Worker
22*49cdfc7eSAndroid Build Coastguard Worker for (i = 0; i < 10; i++) {
23*49cdfc7eSAndroid Build Coastguard Worker SAFE_WRITE(SAFE_WRITE_ALL, fd, BUF, sizeof(BUF));
24*49cdfc7eSAndroid Build Coastguard Worker
25*49cdfc7eSAndroid Build Coastguard Worker TEST(fsync(fd));
26*49cdfc7eSAndroid Build Coastguard Worker
27*49cdfc7eSAndroid Build Coastguard Worker if (TST_RET == -1)
28*49cdfc7eSAndroid Build Coastguard Worker tst_res(TFAIL | TTERRNO, "fsync failed");
29*49cdfc7eSAndroid Build Coastguard Worker else
30*49cdfc7eSAndroid Build Coastguard Worker tst_res(TPASS, "fsync() returned %ld", TST_RET);
31*49cdfc7eSAndroid Build Coastguard Worker }
32*49cdfc7eSAndroid Build Coastguard Worker }
33*49cdfc7eSAndroid Build Coastguard Worker
setup(void)34*49cdfc7eSAndroid Build Coastguard Worker static void setup(void)
35*49cdfc7eSAndroid Build Coastguard Worker {
36*49cdfc7eSAndroid Build Coastguard Worker sprintf(fname, "mntpoint/tfile_%d", getpid());
37*49cdfc7eSAndroid Build Coastguard Worker fd = SAFE_OPEN(fname, O_RDWR | O_CREAT, 0700);
38*49cdfc7eSAndroid Build Coastguard Worker }
39*49cdfc7eSAndroid Build Coastguard Worker
cleanup(void)40*49cdfc7eSAndroid Build Coastguard Worker static void cleanup(void)
41*49cdfc7eSAndroid Build Coastguard Worker {
42*49cdfc7eSAndroid Build Coastguard Worker if (fd > 0)
43*49cdfc7eSAndroid Build Coastguard Worker SAFE_CLOSE(fd);
44*49cdfc7eSAndroid Build Coastguard Worker }
45*49cdfc7eSAndroid Build Coastguard Worker
46*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
47*49cdfc7eSAndroid Build Coastguard Worker .cleanup = cleanup,
48*49cdfc7eSAndroid Build Coastguard Worker .setup = setup,
49*49cdfc7eSAndroid Build Coastguard Worker .test_all = verify_fsync,
50*49cdfc7eSAndroid Build Coastguard Worker .needs_root = 1,
51*49cdfc7eSAndroid Build Coastguard Worker .mount_device = 1,
52*49cdfc7eSAndroid Build Coastguard Worker .mntpoint = "mntpoint",
53*49cdfc7eSAndroid Build Coastguard Worker .all_filesystems = 1,
54*49cdfc7eSAndroid Build Coastguard Worker };
55