10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*5331Samw * Common Development and Distribution License (the "License").
6*5331Samw * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*5331Samw * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
270Sstevel@tonic-gate /* All Rights Reserved */
280Sstevel@tonic-gate
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate * Portions of this source code were derived from Berkeley 4.3 BSD
310Sstevel@tonic-gate * under license from the Regents of the University of California.
320Sstevel@tonic-gate */
330Sstevel@tonic-gate
34*5331Samw #pragma ident "%Z%%M% %I% %E% SMI"
350Sstevel@tonic-gate
360Sstevel@tonic-gate #include <sys/param.h>
370Sstevel@tonic-gate #include <sys/isa_defs.h>
380Sstevel@tonic-gate #include <sys/types.h>
390Sstevel@tonic-gate #include <sys/sysmacros.h>
400Sstevel@tonic-gate #include <sys/cred.h>
410Sstevel@tonic-gate #include <sys/systm.h>
420Sstevel@tonic-gate #include <sys/errno.h>
430Sstevel@tonic-gate #include <sys/vnode.h>
440Sstevel@tonic-gate #include <sys/file.h>
450Sstevel@tonic-gate #include <sys/mode.h>
460Sstevel@tonic-gate #include <sys/debug.h>
470Sstevel@tonic-gate
480Sstevel@tonic-gate /*
490Sstevel@tonic-gate * Flush output pending for file.
500Sstevel@tonic-gate */
510Sstevel@tonic-gate int
fdsync(int fd,int flag)520Sstevel@tonic-gate fdsync(int fd, int flag)
530Sstevel@tonic-gate {
540Sstevel@tonic-gate file_t *fp;
550Sstevel@tonic-gate register int error;
560Sstevel@tonic-gate int syncflag;
570Sstevel@tonic-gate
580Sstevel@tonic-gate if ((fp = getf(fd)) != NULL) {
590Sstevel@tonic-gate /*
600Sstevel@tonic-gate * This flag will determine the file sync
610Sstevel@tonic-gate * or data sync.
620Sstevel@tonic-gate * FSYNC : file sync
630Sstevel@tonic-gate * FDSYNC : data sync
640Sstevel@tonic-gate */
650Sstevel@tonic-gate syncflag = flag & (FSYNC|FDSYNC);
660Sstevel@tonic-gate
67*5331Samw if (error = VOP_FSYNC(fp->f_vnode, syncflag, fp->f_cred, NULL))
680Sstevel@tonic-gate (void) set_errno(error);
690Sstevel@tonic-gate releasef(fd);
700Sstevel@tonic-gate } else
710Sstevel@tonic-gate error = set_errno(EBADF);
720Sstevel@tonic-gate return (error);
730Sstevel@tonic-gate }
74