7

I am just wondering is there a way to bind an internal /sdcard folder to another internal /sdcard folder and normal apps can write into it for Android versions since 4.4?

I have a folder named ./MyPics in the internal /sdcard. I want to bind it to ./DCIM/Camera, ./Pictures/Screenshots, ./Movies/Screencasts. The SD card is mounted in /mnt/shell/emulated/0 as sdcardfs, and it is symlinked to /storage/emulated/legacy. Moreover, there is a directory /storage/emulated/0, which is neither a mount point nor a symlink. It is a very weird directory.

  1. I tried follows:

    mount -o bind,dmask=0000,fmask=0000 /mnt/shell/emulated/0/MyPics /mnt/shell/emulated/0/DCIM/Camera  
    mount -o bind,dmask=0000,fmask=0000 /mnt/shell/emulated/0/MyPics /mnt/shell/emulated/0/Pictures/Screenshots  
    mount -o bind,dmask=0000,fmask=0000 /mnt/shell/emulated/0/MyPics /mnt/shell/emulated/0/Movies/Screencasts  
    

    but it has no use: Apps like Camera failed to write into /DCIM/Camera

  2. I tried follows:

    mount -o bind,dmask=0000,fmask=0000 /storage/emulated/legacy/MyPics /mnt/shell/emulated/0/...
    ....
    

    but it has no use either

  3. I tried follows:

    mount -o bind,dmask=0000,fmask=0000 /data/media/0/MyPics /data/media/0/...
    ....
    

    If there is a file named a.jpg in /MyPics, it appears in /data/media/0/DCIM/Camera, but it doesn't appear in /storage/emulated/legacy/DCIM/Camera

  4. I tried to use Apps like LuckPatcher to do the job, but it failed again

  • Have you tried using ln -s? ln -s /sdcard/MyPics /sdcard/DCIM/Camera. You'll need to move the Camera folder first. – keepcalm May 15 '15 at 6:36
1

Unfortunately, since Android 4.2 it is no longer possible on most device to mount a folder and make it available to other apps as well. The details on how this works and why this was changed can be found here: Fix for empty app-mounted directories (CifsManager, etc.) in Android 4.2.

The page mentioned above says this:

Originally Posted by Zygote patch commit message

Zygote: Restrict slave mountspace so Dalvik apps can mount system-wide volumes Android 4.2 implements multi-user storage using per-process mount namespaces. Originally, everything under "/" (the entire filesystem hierarchy) is marked as a recursive-slave mountspace for all zygote instances. This is done so that user-storage sandbox mounts under /storage/emulated are hidden from other apps and users. Unfortunately this means that any Dalvik app (actually, any program whose clone/fork ancestry includes a Dalvik zygote, which is everything except services spawned directly from init) cannot mount system-wide volumes. Thus, apps like CifsManager are effectively broken in Android 4.2, since its cifs mounts are only visible to the CifsManager app itself. All other apps see empty mountpoints instead of the mounted volume. Furthermore, Linux provides no provision for a process to "escape" a recursive-slave mountspace in versions prior to Linux 3.8 (setns syscall).

Here, we restrict the slave mountspace to /storage (and, due to a possible kernel bug, /mnt/shell/emulated) so that Dalvik apps can mount system-wide volumes elsewhere (with appropriate permission, as in earlier versions of Android), while retaining full multi-user storage compatibility. This change requires that a tmpfs volume is mounted as /storage in init.rc. If this volume is unavailable, then Zygote falls back to the previous behavior of marking the entire filesystem hierarchy as slave. It also implicitly requires that EMULATED_STORAGE_TARGET is path-prefixed by (part of the subhierarchy of) ANDROID_STORAGE, which is the typical case.

What it comes down to is that if apps mount a directory or block device, the mounted directory should only be visible for the apps that did the mount unless the app has special permissions, which are not generally available to non-system apps. And even if you manage to mount the directory globally, the Linux permissions will still get in your way.

Therefore, mounting is probably not the easiest solution to your problem, but if you really want to use mounts you should be able to add the commands to /system/bin/debuggerd and then (as root) enter start debuggerd to execute your own script with system privileges.

There is an easier way to work around the read only problems though, either by installing this app or by manually adding the media_rw group to the WRITE_EXTERNAL_STORAGE in the permissions file. This allow apps that have permission to write to the emulated SD card to also write to the 'external' SD card.

After making your external storage writeable, you should be able to use symlinks (ln -s /sdcard/MyPics /sdcard/DCIM/Camera) to allow quick access to these directories.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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