Re: open(), mmap(), sendfile() vs. the file's access time

From: Erik Trulsson <ertr1013_at_student.uu.se>
Date: Thu, 18 Nov 2004 14:45:40 +0100
On Wed, Nov 17, 2004 at 02:07:11PM -0500, Mikhail Teterin wrote:
> Hello!
> 
> It appears, only read() modifies a file's atime. Otherwise, a file can be 
> open()-ed and subsequently _accessed_ through mmap or sendfile()-ed away 
> without atime being changed. Does not seem right...
> 
> Should open() update atime? My first reaction would be yes, but  on Linux and 
> Solaris the behaviour is the same (try attached program).
> 
> Should sendfile()? What about mmap() -- there are some hairy usages?..

I don't know if the current behaviour is "right", but it is certainly
consistent with the documentation. From the manpage for stat(2):


  The time-related fields of struct stat are as follows:

  st_atime     Time when file data last accessed.  Changed by the
               mknod(2), utimes(2) and read(2) system calls.

  st_mtime     Time when file data last modified.  Changed by the
               mknod(2), utimes(2) and write(2) system calls.

  st_ctime     Time when file status was last changed (inode data
               modification).  Changed by the chmod(2), chown(2),
               link(2), mknod(2), rename(2), unlink(2), utimes(2) and
               write(2) system calls.


The Solaris stat(2) manpage says:

  st_atime
        Time when file data was last accessed. Changed by  the
        following   functions:   creat(),   mknod(),   pipe(),
        utime(2), and read(2).

  st_mtime
        Time when data was last modified. Changed by the  fol-
        lowing  functions:  creat(), mknod(), pipe(), utime(),
        and write(2).

  st_ctime
        Time when file status was last changed. Changed by the
        following   functions:   chmod(),   chown(),  creat(),
        link(2),  mknod(),  pipe(),  unlink(2),  utime(),  and
        write().


And on Linux stat(2) says:

   The field st_atime is changed by file accesses,  e.g.  by execve(2),
   mknod(2), pipe(2), utime(2) and read(2) (of more than zero bytes).
   Other routines, like mmap(2), may or may not update st_atime.

   The  field  st_mtime  is  changed  by  file  modifications, e.g. by
   mknod(2), truncate(2), utime(2) and write(2) (of more than zero
   bytes).  Moreover, st_mtime of a directory is changed by the
   creation or deletion of files in that directory.  The st_mtime field
   is not changed for changes in owner, group, hard link count, or
   mode.

   The field st_ctime is changed by writing or by setting inode
   information (i.e., owner, group, link count, mode, etc.).



It seems that one should definitely not depend on atime being changed
by mmap() or sendfile().



-- 
<Insert your favourite quote here.>
Erik Trulsson
ertr1013_at_student.uu.se
Received on Thu Nov 18 2004 - 12:45:44 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:22 UTC