Am 09.10.24 um 22:18 schrieb Jeremy Allison via samba-technical:
On Wed, Oct 09, 2024 at 10:00:01PM +0200, Ralph Boehme via samba-technical wrote:
Hm, interesting find
But I guess this won't help as with POSIX you can open() a file with O_APPEND but then still call pread/pwrite on the resulting fd.
Is that true ?
The open(2) man page only says:
O_APPEND
The file is opened in append mode. Before each write(2), the file offset is positioned at the end of
the file, as if with lseek(2). The modification of the file offset and the write operation are per‐
formed as a single atomic step.
Aha ! It's not true (at least on Linux :-).
The pwrite(2) man page says:
BUGS
POSIX requires that opening a file with the O_APPEND flag should have no effect on the location at which
pwrite() writes data. However, on Linux, if a file is opened with O_APPEND, pwrite() appends data to the
end of the file, regardless of the value of offset.
So FILE_APPEND_DATA|SYNCHRONIZE == O_APPEND, on Linux at least.
MS-FSA 2.1.5.4 Server Requests a Write has this:
If ByteOffset equals -2, then set ByteOffset to Open.CurrentByteOffset.
So I think if a file is opened with O_APPEND (on the client), a write() syscall without explicit
offset (so no pwrite), could be mapped to an SMB2 write with offset -2.
But I fear the linux vfs layer already replaces offset before cifs_file_write_iter() and friends
are called... But I guess the per operation IOCB_APPEND flag can be used in order to decide
if offset -2 should be used. On the server we could map that to pwritev2(RWF_APPEND).
So O_APPEND could be a client only thing...
metze