Multi-user external storage support.

Move FUSE daemon to secure mount point, and relax /storage access
now that sdcard_r is enforced using private bind mounts in zygote.

Bug: 6925012
Change-Id: I18754f60a12b0919583765690ca93996fd61f7ee
diff --git a/init.mako.rc b/init.mako.rc
index 7c7a18a..1de5c72 100644
--- a/init.mako.rc
+++ b/init.mako.rc
@@ -19,13 +19,19 @@
 on early-init
     mount debugfs debugfs /sys/kernel/debug
 
-    # for backwards compatibility
+on init
+    mkdir /mnt/secure/sdcard0 0700 root root
+
     export EXTERNAL_STORAGE /storage/sdcard0
-    mkdir /storage 0050 system sdcard_r
-    mkdir /storage/sdcard0 0000 system system
+    mkdir /storage 0711 root root
+    mkdir /storage/sdcard0 0000 root root
     symlink /storage/sdcard0 /sdcard
     symlink /storage/sdcard0 /mnt/sdcard
 
+    # Save bugreports as owner
+    export BUGREPORT_WRITE_PATH /mnt/secure/sdcard0/0
+    export BUGREPORT_READ_PATH /storage/sdcard0
+
 on init
     # Set permissions for persist partition
     mkdir /persist 0771 system system
@@ -121,9 +127,7 @@
 
 # msm specific files that need to be created on /data
 on post-fs-data
-    # we will remap this as /mnt/sdcard with the sdcard fuse tool
     mkdir /data/media 0775 media_rw media_rw
-    chown media_rw media_rw /data/media
 
     mkdir /data/misc/bluetooth 0770 bluetooth bluetooth
 
@@ -359,10 +363,8 @@
 service charger /charger
     class charger
 
-# create virtual SD card at /storage/sdcard0, based on the /data/media directory
-# daemon will drop to user/group system/media_rw after initializing
-# underlying files in /data/media will be created with user and group media_rw (1023)
-service sdcard /system/bin/sdcard /data/media /storage/sdcard0 1023 1023
+# virtual sdcard daemon running as media_rw (1023)
+service sdcard /system/bin/sdcard /data/media /mnt/secure/sdcard0 1023 1023
     class late_start
 
 # Create ext4 filesystems when the partitions are empty or corrupted.