stat(2) man entry & kernel inconsistent

Howard Gayle howard at erix.UUCP
Thu Feb 4 17:37:06 AEST 1988


The manual entry for stat(2) has this to say about the st_atime
field: "Time when file data was last read or modified.  Changed
by the following system calls: mknod(2), utimes(2), read(2), and
write(2)."

In fact, write does not change the access time.  For example,
here's a fragment from rwip() [lines 195-210 of sys_inode.c]:

   if (rw == UIO_READ) {
         if (n + on == bsize || uio->uio_offset == ip->i_size)
                 bp->b_flags |= B_AGE;
         brelse(bp);
   } else {
         if ((ip->i_mode&IFMT) == IFDIR)
                 bwrite(bp);
         else if (n + on == bsize) {
                 bp->b_flags |= B_AGE;
                 bawrite(bp);
         } else
                 bdwrite(bp);
         ip->i_flag |= IUPD|ICHG; <<<<<<<<
         if (u.u_ruid != 0)
                 ip->i_mode &= ~(ISUID|ISGID);
   }

The marked line shows where the modification (IUPD) and change
(ICHG) flags, but not the access flag (IACC), are set by a
write.

Is the bug in the documentation or the kernel?  I use access
times to search for files that I haven't used in a long time and
that are thus candidates for compression, archiving, or
removal.  I imagine this is the typical use for access times.
But what about a file that is frequently written but never read,
such as a log file?  Does the log file contain vital information
in case something goes wrong, or is it just useless statistics?

My colleagues and I believe that the kernel does the right thing
and that the documentation should be changed.  The access time
now tells the last time the file was read; this potentially
useful information would be lost if the kernel behaved the way
the documentation says.  When looking for unused files it is
always possible to use the maximum of the access and modification
times, if that is what is desired.

TN/ETX/TX/UMG Howard Gayle        Email: howard at erix.ericsson.se.UUCP
Telefonaktiebolaget L M Ericsson  Phone: +46 8 719 55 65
Ericsson Telecom     	      	  Telex: 14910 ERIC S
S-126 25 Stockholm                FAX  : +46 8 719 95 98
Sweden



More information about the Comp.bugs.4bsd.ucb-fixes mailing list