title: open: Invalid argument in direct I/O
body: <p>I was trying to make a <a href="http://en.wikipedia.org/wiki/Asynchronous_I/O" rel="nofollow">AIO</a> practice via <a href="http://lse.sourceforge.net/io/aio.html" rel="nofollow">kernel AIO API</a>. Here is some code:</p>
  
  <pre><code>#define _GNU_SOURCE /* syscall() not POSIX */
  #define ALIGN_SIZE 4096
  #define RD_WR_SIZE 1024
  
  /* ... */
  
  /* Make the alignment according to page size to validate open() */
  posix_memalign(&amp;buf, ALIGN_SIZE, RD_WR_SIZE);
  fd = open("aio_test_file", O_RDWR | O_CREAT | O_DIRECT, 0644);
  if (fd == -1) {
      perror("open");
      return -1;
  }
  /* ... */
  </code></pre>
  
  <p>But my <code>open()</code> calling still fail:</p>
  
  <pre><code>open: Invalid argument
  </code></pre>
  
  <p>I have searched that error. Some of them says that you must make the alignment in the case of direct I/O. By using the command:</p>
  
  <pre><code>$ sudo dumpe2fs /dev/sda1 | grep -i "block size"
  </code></pre>
  
  <p>I got the <code>block size</code> is 4096. But why the open() calling still fail?</p>