Skip to contentSkip to conversation

Not POSIX conform: open(..., O_CREAT | O_RDWR, ...) returns -1 although a file was created

DISCUSSION Stefan Behrens 1 participant 1 message Jul 29, 2011 VFS

lore
Share & tools
lore
#0 lore raw

IEEE 1003.1-2004 says that open() must not have created or modified a file if -1 is returned.
But this happens with the released Linux kernel 3.0.0, x86_64.

This issue happens when you run test 079 from xfstests on an ext2, ext3, ext4 or btrfs filesystem. This test 079 makes use of the append-only flag. It is set on the directory and inherited to the created file. The test 079 creates the situation that during a call to open(..., O_CREAT | O_RDWR, ...) the creation of the file is allowed but the opening for writing is not allowed.

The expected behaviour would be that open() returns -1 and that the file _is_ _not_ created.
The recognized behaviour is that -1 is returned but the file _is_ created.

mkdir("/mnt3/foo/append-only.d", 0777) = 0 open("/mnt3/foo/append-only.d", O_RDONLY) = 3
ioctl(3, FS_IOC32_SETFLAGS or FS_IOC_SETFLAGS, 0x7fffaf60b07c) = 0 (this ioctl enables FS_APPEND_FL for the directory) close(3)
open("/mnt3/foo/append-only.d/newfile-0", O_RDWR|O_CREAT, 0666) = -1 EPERM (Operation not permitted)
But you can see that an empty file was created although -1 was returned.