Skip to content

Commit

Permalink
Make emulated storage available via su.
Browse files Browse the repository at this point in the history
Apps (e.g. file managers) expect that they get the same view of files in
su and non-su mode.

Change-Id: I613d021dddb7b90c34bd6d7cf6d2234448404731
  • Loading branch information
maniac103 committed Sep 17, 2013
1 parent 0c02064 commit af18f5a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Superuser/jni/su/daemon.c
Expand Up @@ -29,6 +29,7 @@
#include <getopt.h>
#include <stdint.h>
#include <pwd.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <stdarg.h>
#include <sys/types.h>
Expand Down Expand Up @@ -348,6 +349,19 @@ int run_daemon() {
unlink(sun.sun_path);
unlink(REQUESTOR_DAEMON_PATH);

/*
* Mount emulated storage, if present. Normally that's done by zygote,
* but as we're started via init, we have to do it ourselves.
*/
const char *emulated_source = getenv("EMULATED_STORAGE_SOURCE");
const char *emulated_target = getenv("EMULATED_STORAGE_TARGET");
if (emulated_source && *emulated_source && emulated_target && *emulated_target) {
if (mount(emulated_source, emulated_target, NULL,
MS_BIND | MS_NOEXEC | MS_NOSUID, NULL) < 0) {
PLOGE("mount emulated storage");
}
}

int previous_umask = umask(027);
mkdir(REQUESTOR_DAEMON_PATH, 0777);

Expand Down

2 comments on commit af18f5a

@nuclearmistake
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bind mounts /mnt/shell/emulated to /storage/emulated, which seems wrong?... /storage/emulated should be a folder containing symlinks to folders from /mnt/shell/emulated, and in the case that something creates a legacy folder in /mnt/shell/emulated, breaks symlinking /mnt/shell/emulated/0 to /storage/emulated/legacy (as it's supposed to be), and consequently makes /sdcard/ and /storage/sdcard0/ point to the wrong directory.

On my ROM, "adb shell ls /sdcard/" is empty with this commit applied. Without this commit, the contents of my sdcard are correctly shown.

A large percentage of my rom's source is CM, so I can't say for sure that this commit causes the same issue on CM, but I've illustrated causation between this commit and what appears to be improperly initialized emulated storage.

@rmcc
Copy link
Member

@rmcc rmcc commented on af18f5a Sep 20, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit makes apps under su have the same visibility as apps running under zygote (i.e., normal apps), as per https://github.com/CyanogenMod/android_dalvik/blob/cm-10.2/vm/native/dalvik_system_Zygote.cpp#L266

The mountloop applied is explicitly the same, in order to keep a consistent view.

Please sign in to comment.