I was trying to make a AIO practice via kernel AIO API. Here is some 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(&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;
}
/* ... */
But my open()
calling still fail:
open: Invalid argument
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:
$ sudo dumpe2fs /dev/sda1 | grep -i "block size"
I got the block size
is 4096. But why the open() calling still fail?
From the man page:
That would be my first guess.