title: How are the O_SYNC and O_DIRECT flags in open(2) different/alike?
body: <p>The use and effects of the O_SYNC and O_DIRECT flags is very confusing and appears to vary somewhat among platforms.  From the Linux man page (see an example <a href="http://linux.die.net/man/2/open" rel="noreferrer">here</a>), O_DIRECT provides synchronous I/O, minimizes cache effects and requires you to handle block size alignment yourself.  O_SYNC just guarantees synchronous I/O.  Although both guarantee that data is written into the hard disk's cache, I believe that direct I/O operations are supposed to be faster than plain synchronous I/O since they bypass the page cache (Though FreeBSD's man page for open(2) states that the cache is bypassed when O_SYNC is used.  See <a href="http://www.freebsd.org/cgi/man.cgi?query=open&amp;apropos=0&amp;sektion=0&amp;manpath=FreeBSD%208.2-RELEASE&amp;format=html" rel="noreferrer">here</a>).</p>
  
  <p>What exactly are the differences between the O_DIRECT and O_SYNC flags?  Some implementations suggest using O_SYNC | O_DIRECT.  Why?  </p>