[TAG] Question about file mtime on linux
Benjamin A. Okopnik
ben at linuxgazette.net
Thu Apr 14 06:13:10 MSD 2005
On Wed, Apr 13, 2005 at 09:55:02PM -0400, Jay R. Ashworth wrote:
> On Wed, Apr 13, 2005 at 12:29:15PM -0700, Suramya Tomar wrote:
> > I have a question for you about file mtime(modify
> > time) on linux. Does the mtime stamp of a file change
> > as soon as a process starts modifying the file or does
> > it change it after the change is done?
> Ok, everyone else's treating this as a real question, so I retract my
> snarky remark about school projects. :-)
Hey, Suramya's got cred - he's written for us, hangs out here, and
answers questions himself when they come up. Ya gotta pay more
attention, Jay. :)
> It seems to me that the kernel should update the mtime in the inode (as
> the inode is transparently cached in RAM) *everytime a write(1) call is
> made to the file*.
> So, at this point, your question expands to "if someone makes a write
> call which takes a finite amount of realtime to execute (like, writing
> 1MB from a RAM buffer to a file), at which end of the execution of that
> write call will the inode get updated?"
Hm. I don't think it was _meant_ to expand to anything that complex,
but it's possible.
> IANAKH, but I *believe* the pertinent code is in kernel/fs/$FILESYS/file.c
Sounds like a Hebrew title to me. Not quite as good as rabbi, but almost
equivalent to a doctor...
> and specifically the function ext2_file_write() (for ext2).
> Short version:
> 1) ext2 updates the inode *after* it writes the actual data,
> 2) since it's buffered, the order in which the actual bytes hit the
> disk is indeterminate, and
> 3) it's filesystem specific, since the answer to the question lives in
> a filesystem specific location in the source.
> The specific answer lies in the relative positions of ll_rw_block() and
> the assignment to inode->i_mtime in the function.
> Do I have that right, Ben? :-)
An Ianakh like yourself would know better than humble little me. :) You
lost me right after "The specific answer"; I got through the next five
words via simple inertia, but then my brain seized up and had to be
resupplied with copious amounts of good food. Unfortunately, I'm still
waiting for the delivery boy (yum, /bulgogi/ with /gochujang/ and an
armada of little side dishes, kimchi on the side. Woohoo!)
* Ben Okopnik * Editor-in-Chief, Linux Gazette * http://linuxgazette.net *
More information about the TAG