xref: /netbsd/lib/libc/sys/msync.2 (revision bf9ec67e)
1.\"	$NetBSD: msync.2,v 1.17 2002/02/08 01:28:19 ross Exp $
2.\"
3.\" Copyright (c) 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software
15.\"    must display the following acknowledgement:
16.\"	This product includes software developed by the University of
17.\"	California, Berkeley and its contributors.
18.\" 4. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.\"	@(#)msync.2	8.2 (Berkeley) 6/21/94
35.\"
36.Dd October 10, 1997
37.Dt MSYNC 2
38.Os
39.Sh NAME
40.Nm msync
41.Nd synchronize a mapped region
42.Sh LIBRARY
43.Lb libc
44.Sh SYNOPSIS
45.Fd #include \*[Lt]sys/mman.h\*[Gt]
46.Ft int
47.Fn msync "void *addr" "size_t len" "int flags"
48.Sh DESCRIPTION
49The
50.Fn msync
51system call writes all pages with shared modifications
52in the specified
53region of the process's address space back to permanent
54storage, and, if requested, invalidates cached data mapped
55in the region.
56If
57.Fa len
58is 0, all modified pages within the region containing
59.Fa addr
60will be flushed;
61if
62.Fa len
63is non-zero, only modified pages containing
64.Fa addr
65and
66.Fa len
67succeeding locations will be flushed.
68Any required synchronization of memory caches
69will also take place at this time.
70Filesystem operations on a file that is mapped for shared modifications
71are unpredictable except after an
72.Fn msync .
73.Pp
74The
75.Fa flags
76argument is formed by
77.Em or Ns 'ing
78the following values
79.Pp
80.Bl -column -offset indent -compact MS_INVALIDATE
81.It Dv MS_ASYNC Ta Perform asynchronous writes.
82.It Dv MS_SYNC Ta Perform synchronous writes.
83.It Dv MS_INVALIDATE Ta Invalidate cached data after writing.
84.El
85.Sh ERRORS
86The following errors may be reported:
87.Bl -tag -width Er
88.It Bq Er EBUSY
89The
90.Dv MS_INVALIDATE
91flag was specified and a portion of the specified region
92was locked with
93.Xr mlock 2 .
94.It Bq Er EINVAL
95The specified
96.Fa flags
97argument was invalid.
98.It Bq Er EINVAL
99The
100.Fa addr
101parameter was not page aligned.
102.It Bq Er EINVAL
103The
104.Fa addr
105parameter did not specify an address part of a mapped region.
106.It Bq Er EINVAL
107The
108.Fa len
109parameter was negative.
110.It Bq Er EIO
111An I/O error occurred while writing to the file system.
112.It Bq Er ENOMEM
113Addresses in the specified region are outside the range allowed
114for the address space of the process, or specify one or more pages
115which are unmapped.
116.El
117.Sh SEE ALSO
118.Xr mlock 2 ,
119.Xr mmap 2 ,
120.Xr munlock 2
121.Sh HISTORY
122The
123.Fn msync
124function first appeared in
125.Bx 4.4 .
126It was modified to conform to
127.St -p1003.1b-93
128in
129.Nx 1.3 .
130.Sh BUGS
131Writes are currently done synchronously even if the
132.Dv MS_ASYNC
133flag is specified.
134