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