vfs: add RWF_NOAPPEND flag for pwritev2
authorRich Felker <dalias@libc.org>
Mon, 31 Aug 2020 15:32:08 +0000 (11:32 -0400)
committerChristian Brauner <brauner@kernel.org>
Mon, 22 Jan 2024 14:33:37 +0000 (15:33 +0100)
commit73fa7547c70b32cc69685f79be31135797734eb6
tree61eca04ae3dafb7132f40baa1e73b27dd9f3f949
parent9e3f1c59367515e7e40675fe83645a131c05039d
vfs: add RWF_NOAPPEND flag for pwritev2

The pwrite function, originally defined by POSIX (thus the "p"), is
defined to ignore O_APPEND and write at the offset passed as its
argument. However, historically Linux honored O_APPEND if set and
ignored the offset. This cannot be changed due to stability policy,
but is documented in the man page as a bug.

Now that there's a pwritev2 syscall providing a superset of the pwrite
functionality that has a flags argument, the conforming behavior can
be offered to userspace via a new flag. Since pwritev2 checks flag
validity (in kiocb_set_rw_flags) and reports unknown ones with
EOPNOTSUPP, callers will not get wrong behavior on old kernels that
don't support the new flag; the error is reported and the caller can
decide how to handle it.

Signed-off-by: Rich Felker <dalias@libc.org>
Link: https://lore.kernel.org/r/20200831153207.GO3265@brightrain.aerifal.cx
Reviewed-by: Jann Horn <jannh@google.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
include/linux/fs.h
include/uapi/linux/fs.h