On Wed, Oct 16, 2002 at 11:09:48PM +0100, Stephen C. Tweedie wrote:
> Hi,
>
> On Thu, Oct 17, 2002 at 12:01:07AM +0200, Andi Kleen wrote:
>
> > No that's not true. The VFS doesn't know about these flags as far as
> > I know. You have to handle them in fs specific code.
> >
> > Even more interesting looking at the source and testing it at least append
> > only
> > is broken for ext2/ext3 - generic_file_llseek doesn't check for it
> > so while you're required to open such a file O_APPEND lseek still works
> > fine.
>
> lseek is ignored on O_APPEND files --- the write always re-seeks to
> EOF. pwrite goes down that same code path too so it also gets the
> append enforced. In your testing were you testing real writes, or
> just the lseeks?
I was testing a real write. Another hole is pwrite().
% cat tseek.c
#include <sys/fcntl.h>
#include <unistd.h>
main(int ac, char **av)
{
int fd = open(av[1], O_APPEND|O_WRONLY);
if (lseek(fd, 100, SEEK_SET) < 0) perror("expected lseek error");
if (write(fd, "1", 1) < 0) perror("expected write error");
else printf("write succeeded\n");
}
% gcc -o tseek tseek.c
% dd if=/dev/zero of=/tmp/TEST bs=1k count=10
% su
# chattr +a /tmp/TEST
% ./tseek /tmp/TEST
write succeeded
-Andi
|