Migrate sdcard0 to shell-accessible location.

Also remove mount() from adb, since it can come online long before
data partition is ready.  Set EXTERNAL_STORAGE environment variable
to point to owner for backwards compatibility.

Bug: 7005701
Change-Id: I63444f6636624eb7ad89f053daa289663424639e
diff --git a/adb/adb.c b/adb/adb.c
index a13a7c9..95d3921 100644
--- a/adb/adb.c
+++ b/adb/adb.c
@@ -990,26 +990,6 @@
 }
 #endif /* !ADB_HOST */
 
-#if !ADB_HOST
-/* Give ourselves access to external storage, which is otherwise protected. */
-static void mount_external_storage(void) {
-    // Create private mount namespace for our process
-    if (unshare(CLONE_NEWNS) == -1) {
-        fatal_errno("Failed to unshare()");
-    }
-
-    // Mark rootfs as being a slave in our process so that changes
-    // from parent namespace flow into our process.
-    if (mount("rootfs", "/", NULL, (MS_SLAVE | MS_REC), NULL) == -1) {
-        fatal_errno("Failed to mount() rootfs as MS_SLAVE");
-    }
-
-    if (mount(EXTERNAL_STORAGE_SYSTEM, EXTERNAL_STORAGE_APP, "none", MS_BIND, NULL) == -1) {
-        fatal_errno("Failed to mount() from %s", EXTERNAL_STORAGE_SYSTEM);
-    }
-}
-#endif /* !ADB_HOST */
-
 int adb_main(int is_daemon, int server_port)
 {
 #if !ADB_HOST
@@ -1042,7 +1022,9 @@
     }
 #else
 
-    mount_external_storage();
+    // Our external storage path may be different than apps, since
+    // we aren't able to bind mount after dropping root.
+    setenv("EXTERNAL_STORAGE", getenv("ADB_EXTERNAL_STORAGE"), 1);
 
     /* don't listen on a port (default 5037) if running in secure mode */
     /* don't run as root if we are running in secure mode */
diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h
index 012c2ae..db9efbb 100644
--- a/include/private/android_filesystem_config.h
+++ b/include/private/android_filesystem_config.h
@@ -229,7 +229,7 @@
     { 00644, AID_ROOT,      AID_ROOT,       0 },
 };
 
-#define EXTERNAL_STORAGE_SYSTEM "/mnt/secure/sdcard0"
+#define EXTERNAL_STORAGE_SYSTEM "/mnt/shell/sdcard0"
 #define EXTERNAL_STORAGE_APP "/storage/sdcard0"
 
 static inline void fs_config(const char *path, int dir,
diff --git a/rootdir/init.rc b/rootdir/init.rc
index 5a31a8e..1ed1323 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -56,6 +56,9 @@
     mkdir /cache 0770 system cache
     mkdir /config 0500 root root
 
+    # Directory for shell-visible mount points, like external storage
+    mkdir /mnt/shell 0700 shell shell
+
     # Directory for putting things only root should see.
     mkdir /mnt/secure 0700 root root