lkml.org 
[lkml]   [1998]   [Dec]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Posix and Single Unix -- atime and mtime changes
Trever Adams wrote:
> void markinterest( void ) {
> int f;
>
> if ( !justaftergroup )
> return;
> sprintf( s, "%s/interesting.groups/%s", spooldir, group->name );
> if ( (f=open( s, O_WRONLY|O_CREAT|O_APPEND, 0644)) >= 0 )
> close(f);
> justaftergroup = FALSE;
> }

Instead of utime(), which won't set the correct timestamp on a remote
filesystem with clock skew, you can use `read(f, &ch, 1)'. Even if the
file is empty, atime is updated.

On the other hand, maybe you _want_ a timestamp relative to the local
machine not the server, in which case utime() would make sense.

> Maybe it is the O_APPEND ?

Nope.

Alan Cox wrote:
> That sounds like a bug, unless the file system has been mounted "noatime"
> in which case then yes the atime wont be updated.

This has been Linux behaviour for a long time, and it does _not_ sound
like a bug to me. Single Unix or POSIX may disagree.

Linux updates atime when you do a read: i.e., access the file.
Linux updates mtime when you do a write the file or change the inode.

Why this is right:

- If we updated atime on open, that would defeat open/fstat/fchdir
optimisations & race condition avoidance. Writing modified atimes
is moderately expensive, especially as it is done in an essentially
random disk order.

stat() and chdir() are not considered appropriate atime updaters,
so why should open/fstat or open/fchdir be?

- You can force an atime update by reading a byte, if you really want.
Even from an empty file.

- mtime is used to tell when a file is modified, not when it is opened
which does not, in itself, modify the file.

-- Jamie

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

\
 
 \ /
  Last update: 2005-03-22 13:46    [W:0.027 / U:0.224 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site