ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset); The pwrite() system call (and also pwritev()) writes bytes at the given 'offset', leaving the file offset unchanged. But, on Linux, if a file is opened with O_APPEND, pwrite() wrongly appends data to the end of the file. It should instead honor the offset. This was the intention in the in the original POSIX.1-2001 specification [1], and wording was added to POSIX.1-2008 to make this more explicit. Tested on 3.0 and 3.2, but appears to be still current in 3.4. [1] http://www.opengroup.org/sophocles2/show_mail.tpl?CALLER=show_archive.tpl&source=L&listname=austin-group-l&id=9455 [2] http://www.opengroup.org/austin/docs/austin_325.txt
Timo Sirainen also noted this issue: http://thread.gmane.org/gmane.linux.kernel/513390
Created attachment 73123 [details] Test program Test program and example that demonstrates the issue: $ cat > a aaaaaaa bbbbbbb ccccccc ddddddd $ ./t_pwrite_O_APPEND a 5 XXXXX y $ cat a aaaaaaa bbbbbbb ccccccc ddddddd XXXXX$ In the above, the XXXXX string should have been placed at offset 5 of the file 'a'.
Not clear what the fix is however.. we can't just ignore it because of the appendonly attribute.