Simple question about mmap() system call

Dmitry Pryanishnikov dmitry at atlantis.dp.ua
Fri Jun 23 17:05:11 UTC 2006


Hello!

On Fri, 23 Jun 2006, Konstantin Belousov wrote:
>>     if ((diskp=mmap(NULL, 512,
>>         PROT_READ | PROT_WRITE, 0, fd, 0)) == MAP_FAILED)
>>             err(EX_IOERR, "Can't mmap() file");
>>
>> shows actual first byte of my file. But modification doesn't get written
>> back to the disk, file contents are unchanged after execution of my code.
>> I'm sure I'm overlooking something very basic and stupid, but can't find
>> what exactly.
> You forgot MAP_SHARED.

  Thank you! Yes, that's it. I would say that it's description

      MAP_SHARED        Modifications are shared.

is rather terse and doesn't explicitly says that w/o it data will not be
stored back to the mmapped object. One can only deduce this behaviour,
and deduction sometimes fails at the end of working day ;)


Sincerely, Dmitry
-- 
Atlantis ISP, System Administrator
e-mail:  dmitry at atlantis.dp.ua
nic-hdl: LYNX-RIPE


More information about the freebsd-hackers mailing list