Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 Dec 2000 22:52:00 +0000
From:      Ian Dowse <iedowse@maths.tcd.ie>
To:        julian@freebsd.org, mckusick@mckusick.com
Cc:        freebsd-fs@freebsd.org, iedowse@maths.tcd.ie
Subject:   creat(2) not setting mtime on existing 0-length file
Message-ID:   <200012172252.aa18426@salmon.maths.tcd.ie>

next in thread | raw e-mail | index | archive | help

I was trying to figure out why a very old piece of code we use here
had not been working as expected for ages. The code stores the time
of certain events in zero-length timestamp files using something like:

	close(creat(filename, 0666));

This is supposed to set the last-modified time on the file to the
current time, but I noticed that it has not been doing so for over
a year. This works as expected on FreeBSD 2.2.7, and on other
systems I tried, but FreeBSD 3.0 or later does not modify the mtime
if the file already exists and has zero size.

I traced the problem back to r1.36 of src/sys/ufs/ffs/ffs_inode.c,
which includes the following changes to ffs_truncate():

@@ -171,6 +176,8 @@
	off_t osize;
 
	oip = VTOI(ovp);
+	if (oip->i_size == length)
+		return (0);
	fs = oip->i_fs;
	if (length < 0)
		return (EINVAL);
@@ -197,6 +204,31 @@

A few lines down from this point is the fragment

	if (oip->i_size == length) {
		oip->i_flag |= IN_CHANGE | IN_UPDATE;
		return (UFS_UPDATE(ovp, 0));
	}

so I think it is obvious that the code is not working as expected
since the condition here will never be true. The commit log message
gives no hints except that the patches were obtained from the
Whistle development tree.

So Julian or Kirk, do you have any ideas as to why this change
might have been made in r1.36, or if this behaviour is desirable
or correct? A quick glance suggests that the problem can be resolved
by simply removing the offending lines as in the patch below.

Ian

Index: ffs_inode.c
===================================================================
RCS file: /FreeBSD/FreeBSD-CVS/src/sys/ufs/ffs/ffs_inode.c,v
retrieving revision 1.66
diff -u -r1.66 ffs_inode.c
--- ffs_inode.c	2000/12/13 08:30:30	1.66
+++ ffs_inode.c	2000/12/17 22:33:59
@@ -151,8 +151,6 @@
 	off_t osize;
 
 	oip = VTOI(ovp);
-	if (oip->i_size == length)
-		return (0);
 	fs = oip->i_fs;
 	if (length < 0)
 		return (EINVAL);




To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-fs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi? <200012172252.aa18426>