9fans archive / 2001 / 03 / 280 /    prev next

From: Alexander Viro <viro@mat...>
Subject: Re: [9fans] 9fs/9auth for FreeBSD
Date: Wed, 28 Mar 2001 17:22:21 -0500 (EST)



On Wed, 28 Mar 2001, Russ Cox wrote:

>     O_APPEND probably isn't needed on BSD kernels, either. That was me
>     being paranoid based on the comment that writes didn't always get
>     treated as appends.
> 
> No, it's needed.  The behavior on FreeBSD really is what
> I said -- if you do a write with a file offset
> that is not the end of the file, the write fails.
> It doesn't pretend the offset really is at the 
> end (as Plan 9 and apparently Linux do).  It fails.

Umm... Actually, I was wrong - what actually happens with append-only
on Linux looks so:
	* if file is marked append-only you can't open it for write without
	  O_APPEND. open() will fail with -EPERM
	* You can't turn O_APPEND off (with fcntl()) if file is append-only
	* For any O_APPEND opened file write() ignores position and goes
	  to the end of file.
In case of FreeBSD you can open append-only files for write without
O_APPEND, but attempt to write not at the EOF will fail.

We could easily switch to Plan9 behaviour - all it takes is
        if (IS_APPEND(inode)) {
-                if  ((flag & FMODE_WRITE) && !(flag & O_APPEND))
-                        goto exit;
@@
        if (IS_APPEND(inode)) {
+                if  (flag & FMODE_WRITE)
+                       flag |= O_APPEND;
 
in open_namei(). I'm not sure that it's the right thing to do, though.
Failing on write() is definitely too late, but silently adding O_APPEND
may be rather confusing. Hell knows... I'll look at it.