From owner-freebsd-fs@FreeBSD.ORG Thu Sep 23 18:03:25 2010 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 81DF01065673 for ; Thu, 23 Sep 2010 18:03:25 +0000 (UTC) (envelope-from cal@linu.gs) Received: from mail.adm.hostpoint.ch (mail.adm.hostpoint.ch [217.26.48.124]) by mx1.freebsd.org (Postfix) with ESMTP id 47B148FC13 for ; Thu, 23 Sep 2010 18:03:25 +0000 (UTC) Received: from [77.109.131.203] (port=38577 helo=aare.localnet) by mail.adm.hostpoint.ch with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.69 (FreeBSD)) (envelope-from ) id 1OypkI-000M0p-0y for freebsd-fs@freebsd.org; Thu, 23 Sep 2010 19:38:10 +0200 From: Michael Naef To: "freebsd-fs" Date: Thu, 23 Sep 2010 19:38:00 +0200 User-Agent: KMail/1.13.5 (Linux/2.6.34-gentoo-r1; KDE/4.4.5; i686; ; ) MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-Id: <201009231938.09548.cal@linu.gs> Subject: Strange behaviour with sappend flag set on ZFS X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Sep 2010 18:03:25 -0000 Hi fs people Background: When moving from pre-8.0 to FreeBSD 8.1 on ZFS I realised that the bash history is no longer beeing written if the file has the sappend flag set. Other programs like script (1) however are surprisingly still able to write to such files. So it seemed that they handle file IO differently. (Looking at the source code of both I learned that bash uses write (2) while script uses fwrite (3)... After some more testing and investigation,) it seems that zfs behaves differently to ufs in one point. If I open (2) a file with O_APPEND the fd position pointer is set to the start of the file. When I then write to an fd on a ufs FS in FB6.4, it is automatically moved to the end and the bytes are appended. No problems appear with write to the sappend-flages file. However if I do the same on FB8.1/ZFS, the write fails as "not permitted". When I manually move the position pointer to the end of the file, it works as axpected: FreeBSD 6.4/UFS: root@fb64 [~/michi]# touch gaga root@fb64 [~/michi]# chflags sappend gaga root@fb64 [~/michi]# ./write fd: 3 pos: 0 bytes written: 6 pos: 50 bytes written: 6 FreeBSD 8.1/ZFS: root@server52 [~/michi]# chflags sappend gaga root@fb81 [~/michi]# touch gaga root@fb81 [~/michi]# chflags sappend gaga root@fb81 [~/michi]# ./write fd: 3 pos: 0 ERROR: Operation not permitted pos: 147 bytes written: 6 The source code is: #include #include #include #include #include int main(void){ int file= open("gaga",O_WRONLY|O_APPEND|O_CREAT,0666); int bytes_written= 0; printf("fd: %i\n",file); printf("pos: %i\n",lseek(file,0,SEEK_CUR)); if ((bytes_written= write(file,"write\n",6)) == -1){ printf("ERROR: %s\n",strerror(errno)); }else{ printf("bytes written: %i\n",bytes_written); } lseek(file,0,SEEK_END); printf("pos: %i\n",lseek(file,0,SEEK_CUR)); if ((bytes_written= write(file,"write\n",6)) == -1){ printf("ERROR: %s\n",strerror(errno)); }else{ printf("bytes written: %i\n",bytes_written); } close(file); } Am I missing something or is this a bug (or feature or watsoever ;-) in ZFS? thanks a lot you (z)fs guys and cheers, Michi