erlang/otp — pull request #137 by vinoski (2013-11-12 22:36:03+00:00)
Title: Add o_sync option to file:open/2

The o_sync option adds the POSIX O_SYNC flag to the open system call on
platforms that support the flag or its equivalent, e.g.,
FILE_FLAG_WRITE_THROUGH on Windows. For platforms that don't support it,
file:open/2 returns {error, enotsup} if the o_sync option is passed in.

The semantics of O_SYNC are platform-specific. For example, not all
platforms guarantee that all file metadata are written to the disk along
with the file data when the flag is in effect. This issue is noted in the
documentation this commit adds for the o_sync option.

Add a test for o_sync. Note however that the underlying OS semantics for
O_SYNC can't be tested automatically in any practical way, so the test
assumes the OS does the right thing with the flag when present. For manual
verification, dtruss on OS X and strace on Linux were both run against beam
processes to watch calls to open(), and file:open/2 was called in Erlang
shells to open files for writing, both with and without the o_sync
option. Both the dtruss output and the strace output showed that the O_SYNC
flag was present in the open() calls when o_sync was specified and was
clear when o_sync was not specified.