xref: /titanic_50/usr/src/uts/common/syscall/fdsync.c (revision ee5416c9d7e449233197d5d20bc6b81e4ff091b2)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1998 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 /*
31  * Portions of this source code were derived from Berkeley 4.3 BSD
32  * under license from the Regents of the University of California.
33  */
34 
35 #ident	"%Z%%M%	%I%	%E% SMI"
36 
37 #include <sys/param.h>
38 #include <sys/isa_defs.h>
39 #include <sys/types.h>
40 #include <sys/sysmacros.h>
41 #include <sys/cred.h>
42 #include <sys/systm.h>
43 #include <sys/errno.h>
44 #include <sys/vnode.h>
45 #include <sys/file.h>
46 #include <sys/mode.h>
47 #include <sys/debug.h>
48 
49 /*
50  * Flush output pending for file.
51  */
52 int
53 fdsync(int fd, int flag)
54 {
55 	file_t *fp;
56 	register int error;
57 	int syncflag;
58 
59 	if ((fp = getf(fd)) != NULL) {
60 		/*
61 		 * This flag will determine the file sync
62 		 * or data sync.
63 		 * FSYNC : file sync
64 		 * FDSYNC : data sync
65 		 */
66 		syncflag = flag & (FSYNC|FDSYNC);
67 
68 		if (error = VOP_FSYNC(fp->f_vnode, syncflag, fp->f_cred))
69 			(void) set_errno(error);
70 		releasef(fd);
71 	} else
72 		error = set_errno(EBADF);
73 	return (error);
74 }
75