Is write(2) "atomic" ?
Chris Torek
chris at mimsy.UUCP
Fri Jul 15 01:11:47 AEST 1988
In article <11410006 at eecs.nwu.edu> naim at eecs.nwu.edu (Naim Abdullah) writes:
>Chris Torek pointed out that the fact that concurrent writes may
>result in loss of data, is due to a bug in 4.2BSD. The bug persists
>in 4.3BSD (at least in Mt. Xinu's 4.3+NFS).
Sure enough, it does. (I should have checked my own RCS files...) I
copied the fix for this in January. Here it is:
[/sys/sys/sys_inode.c]
*** /tmp/,RCSt1015268 Thu Jul 14 11:08:14 1988
--- /tmp/,RCSt2015268 Thu Jul 14 11:08:16 1988
***************
*** 36,49 ****
{
register struct inode *ip = (struct inode *)fp->f_data;
! int error;
! if ((ip->i_mode&IFMT) == IFREG) {
ILOCK(ip);
! if (fp->f_flag&FAPPEND && rw == UIO_WRITE)
! uio->uio_offset = fp->f_offset = ip->i_size;
! error = rwip(ip, uio, rw);
IUNLOCK(ip);
- } else
- error = rwip(ip, uio, rw);
return (error);
}
--- 36,53 ----
{
register struct inode *ip = (struct inode *)fp->f_data;
! int count, error;
! if ((ip->i_mode&IFMT) != IFCHR)
ILOCK(ip);
! if ((ip->i_mode&IFMT) == IFREG &&
! (fp->f_flag&FAPPEND) &&
! rw == UIO_WRITE)
! fp->f_offset = ip->i_size;
! uio->uio_offset = fp->f_offset;
! count = uio->uio_resid;
! error = rwip(ip, uio, rw);
! fp->f_offset += count - uio->uio_resid;
! if ((ip->i_mode&IFMT) != IFCHR)
IUNLOCK(ip);
return (error);
}
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain: chris at mimsy.umd.edu Path: uunet!mimsy!chris
More information about the Comp.unix.wizards
mailing list