2

I'm using the Terminal Emulator app on a non-rooted Android 5.0.2 phone.

When moving files from a folder of the external SD card to another with:

mv /storage/extSdCard/DCIM/Camera/* /storage/extSdCard/phone/

I get:

mv: rename /storage/extSdCard/DCIM/Camera/20170519_161315.jpg to 
     /storage/extSdCard/phone/20170519_161315.jpg: Permission denied

Is there a solution for this (without rooting the phone)?


Note: ls -la in /storage/extSdCard gives:

drwxrwx--x root     sdcard_r          2016-08-10 02:18 Android
drwxrwx--- root     sdcard_r          2016-11-20 09:45 DCIM
...
drwxrwx--- root     sdcard_r          2017-05-19 15:46 phone
0

1 Answer 1

4

Filesystem level write access to physically external SD card without rooting phone is not possible since pre-KK days. However apps can always (with or without Storage permission) read and write to their private directories on shared storages. So you can move files to /storage/extSdCard/Android/data/.


On Android 6+ external SD card is visible at /storage/[UUID] where UUID is that of filesystem. This filesystem path is only available for reading (to apps with READ|WRITE_EXTERNAL_STORAGE permission granted) and traversal (for all apps). Latter case is to let apps read/write to their private directories. Like internal emulated filesystem, permission control is implemented through mount namespace and everybody (9997) GID. SD card is mounted with three distinct VIEWS of different permissions:

enter image description here

vold creates an isolated mount namespace for every app and depending upon app's status of Storage permission, bind-mounts a VIEW to /storage/[UUID]. For detail see What is /storage/emulated/0/? and What is the “u#_everybody” UID?


Since none of the three VIEWS has write permission, apps don't have filesystem level write access to public directories on external SD cards. However apps - like mostly file explorers - which make use of Storage Access Framework (SAF) (or Scoped Directory Access on Android 7+ or Scoped External Storage Access on Android 10+) are able to create and delete files on whole SD card.


USB OTG is treated almost in similar fashion, but with one prominent difference:

"MOUNT_FLAG_VISIBLE means the volume is visible to third-party apps for direct filesystem access.
...
transient volumes like USB OTG devices should not be marked as visible; their contents should be surfaced to apps through the Storage Access Framework."

So USBs aren't exposed as VIEWS, instead apps see /storage/[UUID] (which is not an actual) filesystem path through SAF for both reading and writing. That's why contents of removable media aren't available through MediaStore too. Neither available to apps through APIs:

"The returned paths do not include transient devices, such as USB flash drives connected to handheld devices."

Multiple external storage devices:

"External storage devices surfaced through these APIs must be a semi-permanent part of the device (such as an SD card slot in a battery compartment). Developers expect data stored in these locations to be available over long periods of time. For this reason, transient storage devices (such as USB mass storage drives) should not be surfaced through these APIs."

However Adoptable Storage is always visible to apps, whether SD card or USB.


RELATED:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .