Home | History | Annotate | Download | only in fsync
      1 /*
      2  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
      3  *    AUTHOR		: William Roske
      4  *    CO-PILOT		: Dave Fenner
      5  *
      6  * This program is free software; you can redistribute it and/or modify it
      7  * under the terms of version 2 of the GNU General Public License as
      8  * published by the Free Software Foundation.
      9  *
     10  * This program is distributed in the hope that it would be useful, but
     11  * WITHOUT ANY WARRANTY; without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     13  *
     14  * Further, this software is distributed without any warranty that it is
     15  * free of the rightful claim of any third person regarding infringement
     16  * or the like.  Any license provided herein, whether implied or
     17  * otherwise, applies only to this software file.  Patent licenses, if
     18  * any, provided herein do not apply to combinations of this program with
     19  * other software, or any other product whatsoever.
     20  *
     21  * You should have received a copy of the GNU General Public License along
     22  * with this program; if not, write the Free Software Foundation, Inc.,
     23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
     24  *
     25  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
     26  * Mountain View, CA  94043, or:
     27  *
     28  * http://www.sgi.com
     29  *
     30  * For further information regarding this notice, see:
     31  *
     32  * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
     33  *
     34  */
     35 
     36 #include <unistd.h>
     37 #include <errno.h>
     38 #include <stdio.h>
     39 
     40 #include "tst_test.h"
     41 
     42 static char fname[255];
     43 static int fd;
     44 #define BUF "davef"
     45 
     46 static void verify_fsync(void)
     47 {
     48 	unsigned int i;
     49 
     50 	for (i = 0; i < 10; i++) {
     51 		SAFE_WRITE(1, fd, BUF, sizeof(BUF));
     52 
     53 		TEST(fsync(fd));
     54 
     55 		if (TEST_RETURN == -1)
     56 			tst_res(TFAIL | TTERRNO, "fsync failed");
     57 		else
     58 			tst_res(TPASS, "fsync() returned %ld", TEST_RETURN);
     59 	}
     60 }
     61 
     62 static void setup(void)
     63 {
     64 	sprintf(fname, "mntpoint/tfile_%d", getpid());
     65 	fd = SAFE_OPEN(fname, O_RDWR | O_CREAT, 0700);
     66 }
     67 
     68 static void cleanup(void)
     69 {
     70 	if (fd > 0)
     71 		SAFE_CLOSE(fd);
     72 }
     73 
     74 static struct tst_test test = {
     75 	.cleanup = cleanup,
     76 	.setup = setup,
     77 	.test_all = verify_fsync,
     78 	.needs_tmpdir = 1,
     79 	.needs_root = 1,
     80 	.mount_device = 1,
     81 	.mntpoint = "mntpoint",
     82 	.all_filesystems = 1,
     83 };
     84