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