it is very important to me to write to a file with the O_DIRECT
flag.
This is how I open the file:
//Open the file
int fd;
if((fd = open(inFilepath, O_WRONLY | O_CREAT |O_SYNC |O_DIRECT,S_IRUSR|S_IWUSR))<0) {
//Error handling
return;
}
I know about O_DIRECT's alignment restrictions. This is why I initialize my buffer with calloc:
char *buff = (char *) calloc((size_t) 1,sizeof(char));
if(write(fd,buff,(size_t)1)<1) {
//Error logging
free(buff);
return -1;
}
And I get the write: Invalid argument
error.
I even tried to use more extreme measures such as memalign and posix_memalign, but had issues with them (memalign got stuck, and posix_memalign is missing for the ARM processor).
When I comment out the O_DIRECT
flag, everything works as it should (but I/O is not direct, which is what I need).
Anyone has any insight as to why this is happening? If O_DIRECT
was not implemented in Android, then it should've failed at open()
, not at write()
; so I must be doing something wrong!
Thanks -LD