Path: utzoo!attcan!uunet!lll-winken!lll-lcc!lll-tis!ames!umd5!mimsy!chris
From: chris@mimsy.UUCP (Chris Torek)
Newsgroups: comp.unix.wizards
Subject: Re: Is write(2) "atomic" ?
Message-ID: <12471@mimsy.UUCP>
Date: 14 Jul 88 15:11:47 GMT
References: <11410005@eecs.nwu.edu> <11410006@eecs.nwu.edu>
Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742
Lines: 48

In article <11410006@eecs.nwu.edu> naim@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@mimsy.umd.edu	Path:	uunet!mimsy!chris