Timestamp of file modified through mmap are not changed in 2.6

From: Xavier Roche (roche+kml2_at_exalead.com)
Date: 04/08/05

  • Next message: Alexander Nyberg: "Re: 2.6.12-rc2-mm2"
    Date:	Fri, 08 Apr 2005 17:17:00 +0200
    To: linux-kernel@vger.kernel.org
    
    

    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;
    }

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


  • Next message: Alexander Nyberg: "Re: 2.6.12-rc2-mm2"

    Relevant Pages

    • Re: CONFIG_PRINTK_TIME woes
      ... >> these timestamps are exceptionally handy. ... printk tracing into the stack. ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: CONFIG_PRINTK_TIME woes
      ... when I'm debugging TCP events over gigabit ... > these timestamps are exceptionally handy. ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: Fire Engine??
      ... Do the timestamps need to be precise and accurately reflect the ... Or, for TCP timestamps, would it be ... Apart from TCP, precise timestamps are only used for packet capture, ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: Fire Engine??
      ... >> the packet has arrived. ... Or, for TCP timestamps, would it be ... reasonable choice for a configurable option, ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: Fire Engine??
      ... >> of the timestamps are as accurate as they were before. ... do it, we've been burnt. ... Remember nonlocal-bind? ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)