modification time not set correctly after mmap updates

From: Sean Estabrooks
Date: Sun Oct 26 2003 - 14:30:25 EST



mtime is not being updated after changes to files via mmap, at least not
on 2.6.0-test7. Problem shows up on both ext3 and reiserfs.

Below is an ugly little program which updates a test file without
affecting its modification time.

I tried this on 2.4.23 and got the same behavior so perhaps i'm
misinterpreting this passage from the mmap man page:

The st_ctime and st_mtime field for a file mapped with PROT_WRITE
and MAP_SHARED will be updated after a write to the mapped region,
and before a subsequent msync() with the MS_SYNC or MS_ASYNC
flag, if one occurs.

Cheers,
Sean



#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
/* You'll need a file "test.txt" with a few bytes in it */
/* After running this proggy: file is changed but its mtime isn't */
#define SIZE 20
int main()
{
int fd;
char *mbuf;

fd = open("test.txt", O_RDWR);
mbuf = mmap(0, SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
mbuf[1]='x';
msync(mbuf, SIZE, MS_SYNC);
munmap(mbuf, SIZE);
fsync(fd);
close(fd);

return 0;
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/