Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an embedded device with a flash memory running linux. I want to do raw read writes on the flash part but I also want to avoid any file system cache. How can I do this? Any pointers?

share|improve this question
up vote 2 down vote accepted

If the flash has a filesystem on it and you just want to open a file but bypass the cache for IO to that file, then open it with the O_DIRECT flag. If it has no filesystem on it, then you just open the block device directly.

share|improve this answer

I think you want the O_DIRECT flag to open(). Be aware that it may not work as expected on the filesystem on your flash device. Also, I am assuming you are using a filesystem, and not reading a device file.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.