1. 15
  1. 2

    Note to author: you should add stat.st_dev to the set of identifying fields for completeness, treating it more or less like an extension of the inode number. This avoids the rare possibility that since the tool last checked, the file could’ve been replaced by a file that has all the other attributes the same (including inode and size!), but differs in contents and happens to reside on a different filesystem (because mounted filesystems, or your view of them, changed since you last ran).

    Ref: http://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/stat.h.html :

    The st_ino and st_dev fields taken together uniquely identify the file within the system

    1. 1

      Huh, WSL updates it differently than actual Linux. I wonder what Linux ABI compatibility layers in FreeBSD and illumos do…

      1. 1
        $ file mmap_test mmap_test-linux 
        mmap_test:       ELF 64-bit LSB executable, x86-64, version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 11.2, FreeBSD-style, not stripped
        mmap_test-linux: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=027b8396f9f29be58be7518245c820658b2ebd24, not stripped
        $ ./mmap_test
           -0.000037000 * after start
            0.011238000 * after write
            0.011238000   after mmap (should be unchanged)
            0.011238000   after close (should be unchanged)
            0.011238000   after dirty (changes on Linux, not on FreeBSD)
            0.011238000   after continue to dirty (probably does not change)
            0.068946000 * after msync (should change if previous ones didn't)
            0.068946000   after redirty (changes on Linux, not on FreeBSD)
            0.103212000 * after msync (should change if previous ones didn't)
            0.103212000   after redirty (changes on Linux, not on FreeBSD)
            0.135933000 * after munmap (should change if previous one didn't)
        $ ./mmap_test-linux 
           -0.000038000 * after start
            0.011819000 * after write
            0.011819000   after mmap (should be unchanged)
            0.011819000   after close (should be unchanged)
            0.011819000   after dirty (changes on Linux, not on FreeBSD)
            0.011819000   after continue to dirty (probably does not change)
            0.069531000 * after msync (should change if previous ones didn't)
            0.069531000   after redirty (changes on Linux, not on FreeBSD)
            0.130535000 * after msync (should change if previous ones didn't)
            0.130535000   after redirty (changes on Linux, not on FreeBSD)
            0.160540000 * after munmap (should change if previous one didn't)
        
        1. 1

          Oh, the source code of the test is linked in the article. I was scrolling too fast there, haha.