Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

mmap(2)

sysconf(2)

msync(2)

NAME

msync − synchronize a mapped file

SYNOPSIS

#include <sys/mman.h>

int msync(caddr_t addr,size_t len, int flags);

DESCRIPTION

msync controls the caching operations of a mapped file region.  msync() writes all modified pages in the region to the file’s underlying storage device, and ensures the visibility of modifications made to the region with respect to file system operations. 

addr and len specify the region to be synchronized.  If these are not the address and length of a region created by a previous successful call to mmap(), msync() returns an error.  The behavior of msync() upon a region created with the MAP_ANONYMOUS or MAP_PRIVATE flags is undefined. 

flags is constructed from the bitwise inclusive OR of one or more of the following flags defined in <sys/mman.h>:

MS_SYNC Perform synchronous writes

MS_ASYNC Perform asynchronous writes

MS_INVALIDATE Invalidate cached pages

If MS_SYNC is specified, msync() does not return until the system completes all I/O operations.  If MS_ASYNC is specified, msync() returns after the system schedules all I/O operations.  Either MS_SYNC or MS_ASYNC can be set in flags, but not both. 

If MS_INVALIDATE is specified, msync() invalidates all cached copies of the pages.  Subsequent references to the mapped data is obtained from the file’s permanent storage locations.  If either MS_SYNC or MS_ASYNC is also specified, a page is invalidated after it has been written to the file. 

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

After a successful call to msync() with only MS_INVALIDATE specified, all previous modifications to the file using write() are visible to the mapped region.  Previous direct modifications to the mapped region may be lost. 

RETURN VALUE

msync() returns 0 upon success; otherwise, it returns −1 and sets errno to indicate the error. 

ERRORS

msync() fails if any of the following conditions are encountered.:

[EIO] An I/O error occurred while reading from or writing to the file system. 

[ENOMEM] The range specified by [addr, addr+len)  (from, and including, addr to, but not including, addr+len) is invalid for a process’ address space, or the range specifies one or more unmapped pages.

[EINVAL] addr is not a multiple of the page size as returned by sysconf(_SC_PAGE_SIZE). 

[EINVAL] The address range specified by addr and len was not created by a successful call to mmap(). 

AUTHOR

msync() was developed by HP, AT&T, and OSF. 

SEE ALSO

mmap(2), sysconf(2). 

STANDARDS CONFORMANCE

msync(): AES

Hewlett-Packard Company  —  HP-UX Release 9.0: August 1992

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