All of lore.kernel.org
 help / color / mirror / Atom feed
* Timestamp of file modified through mmap are not changed in 2.6
@ 2005-04-08 15:17 Xavier Roche
  2005-04-08 15:46 ` Alexander Nyberg
  0 siblings, 1 reply; 2+ messages in thread
From: Xavier Roche @ 2005-04-08 15:17 UTC (permalink / raw)
  To: linux-kernel

Timestamp of file modified through mmap are not changed in 2.6 (even 
after msync()). Observations on 2.4 and 2.6 kernels:
- on 2.4, timestamps are altered a few seconds after the program exits.
- on 2.6, timestamps are never altered.

Is this behaviour a normal behaviour ?

Program example to reproduce the bug (you need to create a "test" file 
in the current directory first):

#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

int main(void) {
   int fd = open("test", O_RDWR);
   struct stat st;
   char* file;
   if (fd == -1) {
     printf("error opening file\n");
     return 1;
   }
   if (fstat(fd, &st) != 0) {
     printf("error fstating file\n");
     return 1;
   }

   if (st.st_size == 0) {
     printf("error empty file\n");
     return 1;
   }

   printf("Modified date before change: %u\n", st.st_mtime);

   file = mmap(NULL, st.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);

   if (file == NULL) {
     printf("error mmaping file");
     return 1;
   }

   file[0] = file[0] + 1;

   if (msync((void*) file, st.st_size, MS_SYNC) != 0) {
     printf("error syncing file");
     return 1;
   }

   if (munmap(file, st.st_size) != 0) {
     printf("error closing file");
     return 1;
   }

   if (fstat(fd, &st) != 0) {
     printf("error fstating file\n");
     return 1;
   }

   printf("Modified date after change: %u\n", st.st_mtime);

   return 0;
}


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Timestamp of file modified through mmap are not changed in 2.6
  2005-04-08 15:17 Timestamp of file modified through mmap are not changed in 2.6 Xavier Roche
@ 2005-04-08 15:46 ` Alexander Nyberg
  0 siblings, 0 replies; 2+ messages in thread
From: Alexander Nyberg @ 2005-04-08 15:46 UTC (permalink / raw)
  To: Xavier Roche; +Cc: linux-kernel

> Timestamp of file modified through mmap are not changed in 2.6 (even 
> after msync()). Observations on 2.4 and 2.6 kernels:
> - on 2.4, timestamps are altered a few seconds after the program exits.
> - on 2.6, timestamps are never altered.
> 
> Is this behaviour a normal behaviour ?
> 
> Program example to reproduce the bug (you need to create a "test" file 
> in the current directory first):

Yeah there's been at least one bug on bugzilla open for this, and I
recall the posix specification saying the times on files shall be
updated on mmap file changes (which makes sense too).

Doing it at msync is easy, keeping track of memory mapped data etc. is
more cumbersome. I sent a patch doing this a while ago (doesn't work now
due to msync rework, think it was the 4-level changes) that worked well
for me but nobody seemed to be be overwhelmed by it :-)

http://lkml.org/lkml/diff/2004/12/5/95/1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-04-08 15:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-08 15:17 Timestamp of file modified through mmap are not changed in 2.6 Xavier Roche
2005-04-08 15:46 ` Alexander Nyberg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.