summaryrefslogtreecommitdiff
path: root/arch/powerpc64/bits/ipc.h
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2024-03-13 10:47:42 -0400
committerRich Felker <dalias@aerifal.cx>2024-03-14 10:04:28 -0400
commit5370070fded61b569196764673a4fc8440aac79e (patch)
tree02c2fccd6c60c08d9e1b4fd2331bed6f7ad906a4 /arch/powerpc64/bits/ipc.h
parentbdc9a9ff6f95e5d527e1660e44ebd059e6ca8acf (diff)
downloadmusl-5370070fded61b569196764673a4fc8440aac79e.tar.gz
fix pwrite/pwritev handling of O_APPEND files
POSIX requires pwrite to honor the explicit file offset where the write should take place even if the file was opened as O_APPEND. however, linux historically defined the pwrite syscall family as honoring O_APPEND. this cannot be changed on the kernel side due to stability policy, but the addition of the pwritev2 syscall with a flags argument opened the door to fixing it, and linux commit 73fa7547c70b32cc69685f79be31135797734eb6 adds the RWF_NOAPPEND flag that lets us request a write honoring the file offset argument. this patch changes the pwrite function to first attempt using the pwritev2 syscall with RWF_NOAPPEND, falling back to using the old pwrite syscall only after checking that O_APPEND is not set for the open file. if O_APPEND is set, the operation fails with EOPNOTSUPP, reflecting that the kernel does not support the correct behavior. this is an extended error case needed to avoid the wrong behavior that happened before (writing the data at the wrong location), and is aligned with the spirit of the POSIX requirement that "An attempt to perform a pwrite() on a file that is incapable of seeking shall result in an error." since the pwritev2 syscall interprets the offset of -1 as a request to write at the current file offset, it is mapped to a different negative value that will produce the expected error. pwritev, though not governed by POSIX at this time, is adjusted to match pwrite in honoring the offset.
Diffstat (limited to 'arch/powerpc64/bits/ipc.h')
0 files changed, 0 insertions, 0 deletions