I have a file, which is opened by open
:
fd = open("ABC", O_RDWR | O_NOATIME);
The file is memory-mapped by mmap
:
ptr = (uint8_t*)mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
Everything works OK. Then at some point I call sendfile
to copy another file to the fd
descriptor:
bytesCopied = sendfile(fd, fd_src, nullptr, size);
(I'm simplifying a little here - I have a loop, error checks etc.)
It looks like the file content, which is accessible via the fd
descriptor, is not what is in the another file - it's messed up.
My question is - how am I supposed to say Linux to update its memory buffers to sync with external file changes? The msync
isn't suitable here, I need to sync in opposite direction.