It is assumed that mmap() can create a mapping only for writing the open file O_WRONLY ?
I ask because after a crash on a Linux 4.0.4 x86-64 system ( strace log):
mkdir("test", 0700) = 0 open("test/foo", O_WRONLY|O_CREAT, 0666) = 3 ftruncate(3, 11) = 0 mmap(NULL, 11, PROT_WRITE, MAP_SHARED, 3, 0) = -1 EACCES (Permission denied)
errno equals EACCESS .
Replacing the open flag O_WRONLY with O_RDWR gives a successful match.
The Linux mmap manual page documents errno as:
EACCES A file descriptor refers to a non-regular file. Or a file map‐ ping was requested, but fd is not open for reading. Or MAP_SHARED was requested and PROT_WRITE is set, but fd is not open in read/write (O_RDWR) mode. Or PROT_WRITE is set, but the file is append-only.
Thus, this behavior is documented with a second sentence.
But what is the reason for this?
Is POSIX allowed?
Is this the core or the library? (In short, I could not find anything obvious in Linux/mm/mmap.c )
source share