OSDN Git Service

2e0e720330e9feadf8288f0996f35dd2a828df17
[linuxjm/LDP_man-pages.git] / original / man2 / msync.2
1 .\" Copyright (C) 1996 Andries Brouwer (aeb@cwi.nl)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH MSYNC 2 2008-04-22 "Linux" "Linux Programmer's Manual"
26 .SH NAME
27 msync \- synchronize a file with a memory map
28 .SH SYNOPSIS
29 .B #include <sys/mman.h>
30 .sp
31 .BI "int msync(void *" addr ", size_t " length ", int " flags );
32 .SH DESCRIPTION
33 .BR msync ()
34 flushes changes made to the in-core copy of a file that was mapped
35 into memory using
36 .BR mmap (2)
37 back to disk.
38 Without use of this call
39 there is no guarantee that changes are written back before
40 .BR munmap (2)
41 is called.
42 To be more precise, the part of the file that
43 corresponds to the memory area starting at
44 .I addr
45 and having length
46 .I length
47 is updated.
48
49 The
50 .I flags
51 argument may have the bits
52 .BR MS_ASYNC ,
53 .BR MS_SYNC ,
54 and
55 .B MS_INVALIDATE
56 set, but not both
57 .B MS_ASYNC
58 and
59 .BR MS_SYNC .
60 .B MS_ASYNC
61 specifies that an update be scheduled, but the call
62 returns immediately.
63 .B MS_SYNC
64 asks for an update and waits for it to complete.
65 .B MS_INVALIDATE
66 asks to invalidate other mappings of the same file
67 (so that they can be updated with the fresh values just written).
68 .SH RETURN VALUE
69 On success, zero is returned.
70 On error, \-1 is returned, and
71 .I errno
72 is set appropriately.
73 .SH ERRORS
74 .TP
75 .B EBUSY
76 .B MS_INVALIDATE
77 was specified in
78 .IR flags ,
79 and a memory lock exists for the specified address range.
80 .TP
81 .B EINVAL
82 .I addr
83 is not a multiple of PAGESIZE; or any bit other than
84 .BR MS_ASYNC " | " MS_INVALIDATE " | " MS_SYNC
85 is set in
86 .IR flags ;
87 or both
88 .B MS_SYNC
89 and
90 .B MS_ASYNC
91 are set in
92 .IR flags .
93 .TP
94 .B ENOMEM
95 The indicated memory (or part of it) was not mapped.
96 .SH CONFORMING TO
97 POSIX.1-2001.
98
99 This call was introduced in Linux 1.3.21, and then used
100 .B EFAULT
101 instead of
102 .BR ENOMEM .
103 In Linux 2.4.19 this was changed to the POSIX value
104 .BR ENOMEM .
105 .SH AVAILABILITY
106 On POSIX systems on which
107 .BR msync ()
108 is available, both
109 .B _POSIX_MAPPED_FILES
110 and
111 .B _POSIX_SYNCHRONIZED_IO
112 are defined in
113 .I <unistd.h>
114 to a value greater than 0.
115 (See also
116 .BR sysconf (3).)
117 .\" POSIX.1-2001: It shall be defined to -1 or 0 or 200112L.
118 .\" -1: unavailable, 0: ask using sysconf().
119 .\" glibc defines them to 1.
120 .SH SEE ALSO
121 .BR mmap (2)
122
123 B.O. Gallmeister, POSIX.4, O'Reilly, pp. 128-129 and 389-391.
124 .SH COLOPHON
125 This page is part of release 3.64 of the Linux
126 .I man-pages
127 project.
128 A description of the project,
129 and information about reporting bugs,
130 can be found at
131 \%http://www.kernel.org/doc/man\-pages/.