• Forums
  • >
  • Apps
  • >
  • Motorola Android EINVAL (errno==22) When opening files on SDCard
Reply to Post
Novice Hacker
op84
2 Posts
Member since ‎08.15.2011

Motorola Android EINVAL (errno==22) When opening files on SDCard

We've run into a problem with build 4.5.91 on the Motorola Atrix. Our product uses native code to  open a file on the SD Card.

We need to open the file with the O_DIRECT flag so that the OS does not cache our reads and it writes directly through to the filesystem. The SD card that's mounted is a really smart sdcard and is able to respond back to the commands we're writing. 

 

This has been working perfectly with older build but after upgrading to the 4.5.91 build we're getting EINVAL (errno ==22) when we atempt to open a file. I've tracked this down to the use of the O_DIRECT flag. Once the flag is removed we're able to open the file but we need the ability to write through directly and not have the data cached so our reads get fresh data from the sd card. 

 

Example Code:

int hFile=-1;

hFile = open("/sdcard/external_sd/foo.txt", O_RDWR | O_CREAT |O_SYNC|O_NDELAY|O_DIRECT); // this returns -1 and errno is set to 22 

 

hFile = open("/sdcard/external_sd/foo.txt", O_RDWR | O_CREAT |O_SYNC| O_NDELAY); // this returns  a valid file handle

 

Can someone shed some light on what's happend and how we could work around this change.


Thanks

Awesome Sauce Coder
506 Posts
Member since ‎01.14.2004

Re: Motorola Android EINVAL (errno==22) When opening files on SDCard

Hi op84,

Thanks for your post!

 

Let me check into this.

 

thanks!

Novice Hacker
op84
2 Posts
Member since ‎08.15.2011

Re: Motorola Android EINVAL (errno==22) When opening files on SDCard

Thanks

Awesome Sauce Coder
506 Posts
Member since ‎01.14.2004

Re: Motorola Android EINVAL (errno==22) When opening files on SDCard

Hi op84,

 

I was told after further investigation by our Feature leads that  O_DIRECT does not work in Gingerbread.

 

 

thanks!

  • of 1