Date: Sun, 28 Mar 2004 17:56:31 -0800 (PST) From: Kevin Lo <kevlo@FreeBSD.org> To: freebsd-gnats-submit@FreeBSD.org Subject: kern/64875: Add a system call: fdatasync() Message-ID: <200403290156.i2T1uV7f075023@www.freebsd.org> Resent-Message-ID: <200403290200.i2T20aMw046336@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 64875 >Category: kern >Synopsis: Add a system call: fdatasync() >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sun Mar 28 18:00:36 PST 2004 >Closed-Date: >Last-Modified: >Originator: Kevin Lo >Release: 5.2.1 >Organization: Indivisual >Environment: FreeBSD 5.2.1-RELEASE >Description: fdatasync()is part of realtime extensions in POSIX 1003.1. DESCRIPTION The fdatasync() function forces all currently queued I/O operations associated with the file indicated by file descriptor fildes to the synchronized I/O completion state. >How-To-Repeat: diff -ruN sys.orig/compat/freebsd32/syscalls.master sys/compat/freebsd32/syscalls.master --- sys.orig/compat/freebsd32/syscalls.master Fri Mar 26 11:18:23 2004 +++ sys/compat/freebsd32/syscalls.master Fri Mar 26 11:36:30 2004 @@ -604,3 +604,4 @@ 439 UNIMPL extattr_list_link 440 UNIMPL kse_switchin 441 UNIMPL ksem_timedwait +442 UNIMPL fdatasync diff -ruN sys.orig/kern/syscalls.master sys/kern/syscalls.master --- sys.orig/kern/syscalls.master Fri Mar 26 11:18:59 2004 +++ sys/kern/syscalls.master Fri Mar 26 11:36:49 2004 @@ -629,5 +629,6 @@ 440 MSTD { int kse_switchin(const struct __mcontext *mcp, \ long val, long *loc); } 441 MNOSTD { int ksem_timedwait(semid_t id, struct timespec *abstime); } +442 STD { int fdatasync(int fd); } ; Please copy any additions and changes to the following compatability tables: ; sys/compat/freebsd32/syscalls.master diff -ruN sys.orig/kern/vfs_syscalls.c sys/kern/vfs_syscalls.c --- sys.orig/kern/vfs_syscalls.c Fri Mar 26 11:19:00 2004 +++ sys/kern/vfs_syscalls.c Fri Mar 26 14:00:14 2004 @@ -3122,6 +3122,48 @@ } /* + * Sync the data of an open file. + */ +#ifndef _SYS_SYSPROTO_H_ +struct fdatasync_args { + int fd; +}; +#endif +/* ARGSUSED */ +int +fdatasync(td, uap) + struct thread *td; + struct fsync_args /* { + int fd; + } */ *uap; +{ + struct vnode *vp; + struct file *fp; + vm_object_t obj; + int error; + + GIANT_REQUIRED; + + if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0) + return (error); + if ((fp->f_flag & FWRITE) == 0) { + fdrop(fp, td); + return (EBADF); + } + vp = fp->f_vnode; + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td); + if (VOP_GETVOBJECT(vp, &obj) == 0) { + VM_OBJECT_LOCK(obj); + vm_object_page_clean(obj, 0, 0, 0); + VM_OBJECT_UNLOCK(obj); + } + error = VOP_FSYNC(vp, fp->f_cred, MNT_WAIT, td); + VOP_UNLOCK(vp, 0, td); + fdrop(fp, td); + return (error); +} + +/* * Rename files. Source and destination must either both be directories, * or both not be directories. If target is a directory, it must be empty. */ --- /dev/null Mon Mar 29 09:44:00 2004 +++ lib/libc/sys/fdatasync.2 Mon Mar 29 09:47:49 2004 @@ -0,0 +1,86 @@ +.\" Copyright (c) 2004 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd March 27, 2004 +.Dt FDATASYNC 2 +.Os +.Sh NAME +.Nm fdatasync +.Nd "synchronize the data of a file" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In unistd.h +.Ft int +.Fn fdatasync "int fd" +.Sh DESCRIPTION +The +.Fn fdatasync +system call +shall force all currently queued I/O operations associated +with the file indicated by file descriptor +.Fa fd +to the synchronized I/O completion state. +.Pp +The +functionality shall be equivalent to +.Fn fsync +with the exception that all I/O operations shall be completed as +defined for synchronized I/O data integrity completion. +.Sh RETURN VALUES +.Rv -std fdatasync +.Sh ERRORS +The +.Fn fdatasync +fails if: +.Bl -tag -width Er +.It Bq Er EBADF +The +.Fa fd +argument +is not a valid descriptor. +.It Bq Er EINVAL +The +.Fa fd +argument +refers to a socket, not to a file. +.It Bq Er EIO +An I/O error occurred while reading from or writing to the file system. +.El +.Sh SEE ALSO +.Xr fsync 2 +.Sh HISTORY +The +.Fn fdatasync +system call appeared in +.Fx 5.2 . >Fix: >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200403290156.i2T1uV7f075023>