xref: /dragonfly/share/man/man9/VOP_FSYNC.9 (revision 851dc90d)
1.\" -*- nroff -*-
2.\"
3.\" Copyright (c) 1996 Doug Rabson
4.\"
5.\" All rights reserved.
6.\"
7.\" This program is free software.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
19.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
22.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28.\"
29.\" $FreeBSD: src/share/man/man9/VOP_FSYNC.9,v 1.6.2.2 2001/12/17 11:30:18 ru Exp $
30.\" $DragonFly: src/share/man/man9/VOP_FSYNC.9,v 1.3 2003/08/01 17:46:25 dillon Exp $
31.\"
32.Dd July 24, 1996
33.Os
34.Dt VOP_FSYNC 9
35.Sh NAME
36.Nm VOP_FSYNC
37.Nd flush filesystem buffers for a file
38.Sh SYNOPSIS
39.In sys/param.h
40.In sys/vnode.h
41.Ft int
42.Fn VOP_FSYNC "struct vnode *vp" "struct ucred *cred" "int waitfor" "struct proc *p"
43.Sh DESCRIPTION
44This call flushes any dirty filesystem buffers for the file.
45It is used to implement the
46.Xr sync 2
47and
48.Xr fsync 2
49system calls.
50.Pp
51Its arguments are:
52.Bl -tag -width waitfor
53.It Ar vp
54the vnode of the file
55.It Ar cred
56the caller's credentials
57.It Ar waitfor
58whether the function should wait for I/O to complete
59.It Ar p
60the calling process
61.El
62.Pp
63The argument
64.Fa waitfor
65is either
66.Dv MNT_WAIT
67or
68.Dv MNT_NOWAIT
69and specifies whether or not the function should wait for the writes
70to finish before returning.
71.Sh LOCKS
72The file should be locked on entry.
73.Sh RETURN VALUES
74Zero is returned if the call is successful, otherwise an appropriate
75error code is returned.
76.Sh PSEUDOCODE
77.Bd -literal
78int
79vop_fsync(struct vnode *vp, struct ucred *cred, int waitfor, struct proc *p)
80{
81    struct buf *bp;
82    struct buf *nbp;
83    struct timeval tv;
84    int s;
85
86loop:
87    s = splbio();
88    for (bp = vp->v_dirtyblkhd.lh_first; bp; bp = nbp) {
89	nbp = bp->b_vnbufs.le_next;
90
91	/*
92	 * Ignore buffers which are already being written.
93	 */
94	if (bp->b_flags & B_BUSY)
95	    continue;
96
97	/*
98	 * Make sure the buffer is dirty.
99	 */
100	if ((bp->b_flags & B_DELWRI) == 0)
101	    panic("vop_fsync: not dirty");
102
103	vfs_bio_awrite(bp);
104	splx(s);
105	goto loop;
106    }
107    splx(s);
108
109    if (waitfor == MNT_WAIT) {
110	s = splbio();
111	while (vp->v_numoutput) {
112	    vp->v_flag |= VBWAIT;
113	    tsleep((caddr_t)&vp->v_numoutput, 0, "vopfsn");
114	}
115	splx(s);
116#ifdef DIAGNOSTIC
117	if (vp->v_dirtyblkhd.lh_first) {
118	    vprint("vop_fsync: dirty", vp);
119	    goto loop;
120	}
121#endif
122    }
123
124    /*
125     * Write out the on-disc version of the vnode.
126     */
127    tv = time;
128    return VOP_UPDATE(vp, &tv, &tv, waitfor == MNT_WAIT);
129}
130.Ed
131.Sh ERRORS
132.Bl -tag -width Er
133.It Bq Er ENOSPC
134The filesystem is full.
135.It Bq Er EDQUOT
136Quota exceeded.
137.El
138.Sh SEE ALSO
139.Xr vnode 9
140.Sh AUTHORS
141This man page was written by
142.An Doug Rabson .
143