简体   繁体   中英

Reading / writing directly to SD Card with Android

In my pure C++ native process (that I run from the terminal with adb) I'm trying to read a block directly from the SD Card in Android 2.3 SGS2. My code is running with root permissions so it shouldn't matter.

I know that the SD Card memory mapped to /sys/block/mmcblk1 so I open it:

int fd = open("/sys/block/mmcblk1", O_RDONLY);

which succeeds. Now, when I'm trying to read from it:

bytes_read = read(fd, buffer, 4096);

I get an error: "Is a directory"

Well, I know that this is a directory but it's still supposed to work, maybe with some other flags in the open?

How can I do this?

Haha! My mistake was indeed that I tried to read from a directory /sys/block/mmcblk1 . But I should have try to read from /dev/block/mmcblk1 !

Which works perfectly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM