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