BSD vi/view resets inode ctime: why?
Chris Torek
chris at mimsy.UUCP
Tue Mar 10 03:23:14 AEST 1987
In article <4801 at brl-adm.ARPA> rex at erebus (Rex Sanders) writes:
>Why does 4.2/4.3 BSD vi/view, exited without changing the file, update the
>inode change time?
(If you saw an earlier answer from me, ignore it. I was suffering from
brain rot at the time. I think I cancelled it before it got far. This
version is right. I think.)
In /usr/src/ucb/ex_io.c, one finds a routine called iostats(). This
routine is called just after reading or writing any file. It does this:
(void) fsync(io);
close(io);
In /sys/sys/ufs_syscalls.c, we find fsync():
fp = getinode(uap->fd);
if (fp == NULL)
return;
ip = (struct inode *)fp->f_data;
ILOCK(ip);
syncip(ip);
IUNLOCK(ip);
Note that there is no verification that the file is open for writing.
(Perhaps this is by design.) In /sys/sys/ufs_inode.c, at the end of
syncip(), there is this code:
ip->i_flag |= ICHG;
iupdat(ip, &time, &time, 1);
which sets to `now' the inode change time (and, if the inode has
been previously marked, the access and update times). One might
argue that this is unnecessary: but I am uncertain. Again, this
may be by design.
By far the easiest fix is to change vi. In ex_io.c, find the two
calls to iostats(), and add a `dosync' parameter, or move the
fsync() call to just before the call from the file-writing code.
Another possible fix, if it is deemed correct, would be to ensure
that (fp->f_flag & FWRITE) != 0. Then vi's fsync() in the read
case would silently fail.
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
UUCP: seismo!mimsy!chris ARPA/CSNet: chris at mimsy.umd.edu
More information about the Comp.unix.wizards
mailing list