Setting the access/modify time on a file

Mike Thompson yohn at tumult.sgi.com
Thu Mar 15 09:00:46 AEST 1990


In article <1413 at watserv1.waterloo.edu>, tom at mims-iris.waterloo.edu (Tom Haapanen) writes:
> I wish to update a file (with an advisory lock), and then to close it,
> setting the access and modify times to (almost) the same time.  Here
> is what I'm attempting:
> 
> 	FILE *fp;
> 	long times;
> 
> 	fp = fopen("filename", "w");
> 	flock(fileno(fp), LOCK_EX);
> 
> 	... much i/o to the file ...
> 
> 	fflush(fp);
> 	times[1] = time(&times[0]) - (long)2;
> 	utime(mailfile, times);
> 
> 	flock(fileno(fp), LOCK_UN);
> 	fclose(fp);
> 
> Now, at what point does the modify time get set?  the utime() call appears
> to set the access time, but the modify time appears to be set AGAIN after
> the access time.  Where SHOULD it get set?  And what should I do to make
> sure that my access time > modify time?
> 
> The OS is IRIX 3.2 -- aka System V.3.  Thanks for any and all replies!

This is a bug in 3.2 -- the Extent File System routine which is deallocating
preallocated file blocks on close is (mistakenly) forcing the modify time
to be set (to the close time).  It has been fixed for the upcoming release.

For now, reopen the file after the fclose, and *then* call utime and
reclose the file.  The deallocation routine will not be called (actually,
will return without doing anything) since there had been no file activity
since the open.

Michael Thompson



More information about the Comp.unix.wizards mailing list