You did not send your sourcecode, but it seems that you call mmap() to get the data you like to write.
I guess that you mapped a region of a file that grants no read access to you.
In order to verify that the problem is not caused by a side effect with mmap() you should call
dd if=filename of=/dev/null
to check whether the problem exists when you definitely only read from the source file.