Synchronizes a mapped file.
Format
#include <mman.h>
int msync (void *addr, size_t len, int
flags);
Arguments
- addr
- The address of the region that you want to synchronize.
- len
- The length in bytes of the region that you want to synchronize.
- flags
- One of the following symbolic constants defined in the <mman.h>
header file:
MS_SYNC | Synchronous cache flush |
MS_ASYNC | Asynchronous cache
flush |
MS_INVALIDATE |
Invalidate cashed pages |
Description
This function controls the caching operations of a mapped file
region. Use msync to:
- Ensure that modified pages in the region transfer to the
underlying storage device of the file.
- Control the visibility of modifications with respect to
file system operations.
The addr and len arguments specify the region to
be synchronized. The len argument must be a multiple of
the page size as returned by sysconf(_SC_PAGE_SIZE); otherwise, the
length of the region is rounded up to the next multiple of the page
size.
If the flags argument is set to:
flags Argument | Then the msync
Function... |
MS_SYNC | Does
not return until the system completes all I/O operations. |
MS_ASYNC | Returns after the system
schedules all I/O operations. |
MS_
INVALIDATE | Invalidates all cached copies of the
pages. The operating system must obtain new copies of the pages
from the file system the next time the application references
them. |
After a successful call to the msync function with the flags
argument set to:
- MS_SYNC - All previous modifications to the mapped region
are visible to processes using the read argument. Previous
modifications to the file using the write function are lost.
- MS_INVALIDATE - All previous modifications to the file
using the write function are visible to the mapped region.
Previous direct modifications to the mapped region are lost.
See also read, write, and sysconf in this section.
Return Values
0 | Indicates success. |
-1 | Indicates an error; errno is set to one
of the following values:
- EIO - An I/O error occurred while reading from or writing
to the file system.
- ENOMEM - The range specified by
[addr, addr + len] is invalid for a process' address
space, or the range specifies one or more unmapped pages.
- EINVAL - The addr argument is not a multiple of
the page size as returned by sysconf(_SC_PAGE_SIZE).
- EFAULT - The range [addr, addr + len] includes an
invalid address.
|
Previous Page | Next Page | Table of Contents | Index