简体   繁体   中英

Internal Storage and SD Card sector Read/Write for MTP connected android device in C/C++

I want to Read/Write sector (not in File System) from Android device internal storage and SD card.

The android device is connected via MTP.

Normally, we can use CreateFile/ReadFile/WriteFile API functions for Read/Write sector from DISK in Windows. Also, can use fopen/fread/fwrite functions in Linux.

But about the android device which is connected via MTP, I have no experience.

If it is possible, please tell me a method.

I want to do it using C/C++ in Windows or Linux.

Thank you.

What you are asking for is not possible.

The whole point of MTP is to abstract away the mass storage aspect and even the file system. You are communicating over a protocol that is based on commands like "copy this file", "what folders are there", etc., and it's up to the device to interpret these commands. Some devices (not Android, but some older handhelds) would even have a layer of file conversion for Office documents while transferring them.

This way, the device can keep using its storage while allowing you to access it as well. In the "mass storage device" mode that older Android versions supported, the storage medium had to be unmounted while it was made accessible to the PC. With MTP that does not happen. So, it wouldn't be logical to have a way to modify individual sectors over MTP, as that would clash with the device's file system drivers' authority over the storage medium, and also it would bypass security mechanisms.

(Technically, a phone manufacturer could implement a vendor-specific custom command over MTP for accessing sectors, but why would anyone do that?)

If you want to know how to access individual files though (using MTP as intended), the keyword you need is Windows Portable Devices . (Not sure about Linux.)

The only other way to gain low-level access would be over ADB shell, but that would require a rooted device, otherwise you wouldn't be able to access the storage devices directly from within Android.

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