Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

fsync(2)

mmap(2)

read(2)

sysconf(3)

write(2)

msync(2)  —  System Calls

OSF

NAME

msync − Synchronizes a mapped file

SYNOPSIS

#include <sys/types.h> #include <sys/mman.h> int msync (
caddr_t addr,
size_t len,
int flags );

PARAMETERS

addrSpecifies the address of the region to be synchronized. 

lenSpecifies the length in bytes of the region to be synchronized. 

flagsSpecifies one of the following symbolic constants defined in the sys/mman.h file:

MS_SYNCSynchronous cache flush

MS_ASYNCAsynchronous cache flush

MS_INVALIDATE
Invalidate cached pages

DESCRIPTION

The msync() function controls the caching operations of a mapped file region.  The msync() function can be used to ensure that modified pages in the region are transferred to the file’s underlying storage device, or to control the visibility of modifications with respect to file system operations. 

The addr and len parameters specify the region to be synchronized.  The len parameter must be a multiple of the page size as returned by sysconf(_SC_PAGE_SIZE).  If len is not a multiple of the page size as returned by sysconf(_SC_PAGE_SIZE), the length of the region will be rounded up to the next multiple of the page size. 

If the flags parameter is set to MS_SYNC, the msync() function does not return until the system completes all I/O operations.  If the flags parameter is set to MS_ASYNC, the msync() function returns after the system schedules all I/O operations.  If the flags parameter is set to MS_INVALIDATE, the msync() function invalidates all cached copies of the pages.  New copies of the pages then must be obtained from the file system the next time they are referenced. 

After a successful call to the msync() function with the flags parameter set to MS_SYNC, all previous modifications to the mapped region are visible to processes using the read() parameter.  Previous modifications to the file using the write() function may be lost. 

After a successful call to the msync() function with the flags parameter set to 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 may be lost. 

NOTES

AES Support Level:
Trial use

RETURN VALUES

Upon successful completion, the msync() function returns 0 (zero).  Otherwise, the msync() function returns -1 and sets errno to indicate the error. 

ERRORS

If the msync() function fails, errno may be 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 parameter is not a multiple of the page size as returned by sysconf(_SC_PAGE_SIZE), or the flags parameter is MS_SYNC or MS_ASYNC and the region was mapped with MAP_PRIVATE. 

[EFAULT]The range [addr, addr + len) includes an invalid address. 

RELATED INFORMATION

Functions: fsync(2), mmap(2), read(2), sysconf(3), write(2)

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026