xref: /netbsd-src/lib/libc/sys/msync.2 (revision 08c81a9c2dc8c7300e893321eb65c0925d60871c)
1.\"	$NetBSD: msync.2,v 1.18 2002/08/11 14:44:33 yamt 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 August 11, 2002
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 RETURN VALUES
86Upon successful completion,
87a value of 0 is returned.
88Otherwise, a value of -1 is returned and
89.Va errno
90is set to indicate the error.
91.Sh ERRORS
92The following errors may be reported:
93.Bl -tag -width Er
94.It Bq Er EBUSY
95The
96.Dv MS_INVALIDATE
97flag was specified and a portion of the specified region
98was locked with
99.Xr mlock 2 .
100.It Bq Er EINVAL
101The specified
102.Fa flags
103argument was invalid.
104.It Bq Er EINVAL
105The
106.Fa addr
107parameter was not page aligned.
108.It Bq Er EINVAL
109The
110.Fa addr
111parameter did not specify an address part of a mapped region.
112.It Bq Er EINVAL
113The
114.Fa len
115parameter was negative.
116.It Bq Er EIO
117An I/O error occurred while writing to the file system.
118.It Bq Er ENOMEM
119Addresses in the specified region are outside the range allowed
120for the address space of the process, or specify one or more pages
121which are unmapped.
122.El
123.Sh SEE ALSO
124.Xr mlock 2 ,
125.Xr mmap 2 ,
126.Xr munlock 2
127.Sh HISTORY
128The
129.Fn msync
130function first appeared in
131.Bx 4.4 .
132It was modified to conform to
133.St -p1003.1b-93
134in
135.Nx 1.3 .
136.Sh BUGS
137Writes are currently done synchronously even if the
138.Dv MS_ASYNC
139flag is specified.
140