From owner-freebsd-current@FreeBSD.ORG Thu Nov 18 13:45:44 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 403C716A4CE for ; Thu, 18 Nov 2004 13:45:44 +0000 (GMT) Received: from av6-1-sn2.hy.skanova.net (av6-1-sn2.hy.skanova.net [81.228.8.106]) by mx1.FreeBSD.org (Postfix) with ESMTP id F18E143D1D for ; Thu, 18 Nov 2004 13:45:42 +0000 (GMT) (envelope-from ertr1013@student.uu.se) Received: by av6-1-sn2.hy.skanova.net (Postfix, from userid 502) id 9A6F437E45; Thu, 18 Nov 2004 14:45:41 +0100 (CET) Received: from smtp2-1-sn2.hy.skanova.net (smtp2-1-sn2.hy.skanova.net [81.228.8.177]) by av6-1-sn2.hy.skanova.net (Postfix) with ESMTP id 84F2C37E43 for ; Thu, 18 Nov 2004 14:45:41 +0100 (CET) Received: from falcon.midgard.homeip.net (h201n1fls24o1048.bredband.comhem.se [212.181.162.201]) by smtp2-1-sn2.hy.skanova.net (Postfix) with SMTP id 3B28E37E43 for ; Thu, 18 Nov 2004 14:45:41 +0100 (CET) Received: (qmail 26645 invoked by uid 1001); 18 Nov 2004 13:45:40 -0000 Date: Thu, 18 Nov 2004 14:45:40 +0100 From: Erik Trulsson To: Mikhail Teterin Message-ID: <20041118134539.GA26538@falcon.midgard.homeip.net> Mail-Followup-To: Mikhail Teterin , freebsd-current@freebsd.org References: <200411171407.11793.Mikhail.Teterin@murex.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200411171407.11793.Mikhail.Teterin@murex.com> User-Agent: Mutt/1.5.6i cc: freebsd-current@freebsd.org Subject: Re: open(), mmap(), sendfile() vs. the file's access time X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Nov 2004 13:45:44 -0000 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(). -- Erik Trulsson ertr1013@student.uu.se