问题
I work for a company that makes an SD memory card that includes a hardware encryption engine. We interact with the encryption module by writing/reading to a special file.
Starting with KitKat, the O_DIRECT
flag does not seem to be supported on the external SD card. Without O_DIRECT or O_SYNC
support, the OS will returned cached data when we read the encryption engine's response from the SD card (via our special file).
Is there a procedure to open a file on the eternal SD card, read/write, with either O_DIRECT or O_SYNC
?
回答1:
If you have root-access to your phone you can write a 1 to /proc/sys/vm/drop_caches to clear the page cache (see http://linux-mm.org/Drop_Caches). After that command the next read on the sdcard will return the non-cached data.
For stock-devices (where you have no permission to /proc/sys/vm/drop_caches) there is a issue in the AOSP (you may star it): https://code.google.com/p/android/issues/detail?id=67406
来源:https://stackoverflow.com/questions/21873726/how-can-i-use-o-direct-or-o-sync-on-an-external-sd-card-with-android-kitkat