summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--rootdir/init.rc1
-rw-r--r--sdcard/sdcard.c29
2 files changed, 17 insertions, 13 deletions
diff --git a/rootdir/init.rc b/rootdir/init.rc
index 8150a73f1..86e124f15 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -61,6 +61,7 @@ loglevel 3
61 61
62 # See storage config details at http://source.android.com/tech/storage/ 62 # See storage config details at http://source.android.com/tech/storage/
63 mkdir /mnt/shell 0700 shell shell 63 mkdir /mnt/shell 0700 shell shell
64 mkdir /mnt/media_rw 0700 media_rw media_rw
64 mkdir /storage 0751 root sdcard_r 65 mkdir /storage 0751 root sdcard_r
65 66
66 # Directory for putting things only root should see. 67 # Directory for putting things only root should see.
diff --git a/sdcard/sdcard.c b/sdcard/sdcard.c
index 3f1e268e6..05fbfbad3 100644
--- a/sdcard/sdcard.c
+++ b/sdcard/sdcard.c
@@ -215,6 +215,7 @@ struct fuse {
215 int fd; 215 int fd;
216 derive_t derive; 216 derive_t derive;
217 bool split_perms; 217 bool split_perms;
218 gid_t write_gid;
218 struct node root; 219 struct node root;
219 char obbpath[PATH_MAX]; 220 char obbpath[PATH_MAX];
220 221
@@ -681,13 +682,14 @@ static struct node* acquire_or_create_child_locked(
681} 682}
682 683
683static void fuse_init(struct fuse *fuse, int fd, const char *source_path, 684static void fuse_init(struct fuse *fuse, int fd, const char *source_path,
684 gid_t fs_gid, derive_t derive, bool split_perms) { 685 gid_t write_gid, derive_t derive, bool split_perms) {
685 pthread_mutex_init(&fuse->lock, NULL); 686 pthread_mutex_init(&fuse->lock, NULL);
686 687
687 fuse->fd = fd; 688 fuse->fd = fd;
688 fuse->next_generation = 0; 689 fuse->next_generation = 0;
689 fuse->derive = derive; 690 fuse->derive = derive;
690 fuse->split_perms = split_perms; 691 fuse->split_perms = split_perms;
692 fuse->write_gid = write_gid;
691 693
692 memset(&fuse->root, 0, sizeof(fuse->root)); 694 memset(&fuse->root, 0, sizeof(fuse->root));
693 fuse->root.nid = FUSE_ROOT_ID; /* 1 */ 695 fuse->root.nid = FUSE_ROOT_ID; /* 1 */
@@ -712,7 +714,7 @@ static void fuse_init(struct fuse *fuse, int fd, const char *source_path,
712 * just below that. Shared OBB path is also at top level. */ 714 * just below that. Shared OBB path is also at top level. */
713 fuse->root.perm = PERM_LEGACY_PRE_ROOT; 715 fuse->root.perm = PERM_LEGACY_PRE_ROOT;
714 fuse->root.mode = 0771; 716 fuse->root.mode = 0771;
715 fuse->root.gid = fs_gid; 717 fuse->root.gid = AID_SDCARD_R;
716 fuse->package_to_appid = hashmapCreate(256, str_hash, str_icase_equals); 718 fuse->package_to_appid = hashmapCreate(256, str_hash, str_icase_equals);
717 fuse->appid_with_rw = hashmapCreate(128, int_hash, int_equals); 719 fuse->appid_with_rw = hashmapCreate(128, int_hash, int_equals);
718 snprintf(fuse->obbpath, sizeof(fuse->obbpath), "%s/obb", source_path); 720 snprintf(fuse->obbpath, sizeof(fuse->obbpath), "%s/obb", source_path);
@@ -723,7 +725,7 @@ static void fuse_init(struct fuse *fuse, int fd, const char *source_path,
723 * /Android/user and shared OBB path under /Android/obb. */ 725 * /Android/user and shared OBB path under /Android/obb. */
724 fuse->root.perm = PERM_ROOT; 726 fuse->root.perm = PERM_ROOT;
725 fuse->root.mode = 0771; 727 fuse->root.mode = 0771;
726 fuse->root.gid = fs_gid; 728 fuse->root.gid = AID_SDCARD_R;
727 fuse->package_to_appid = hashmapCreate(256, str_hash, str_icase_equals); 729 fuse->package_to_appid = hashmapCreate(256, str_hash, str_icase_equals);
728 fuse->appid_with_rw = hashmapCreate(128, int_hash, int_equals); 730 fuse->appid_with_rw = hashmapCreate(128, int_hash, int_equals);
729 snprintf(fuse->obbpath, sizeof(fuse->obbpath), "%s/Android/obb", source_path); 731 snprintf(fuse->obbpath, sizeof(fuse->obbpath), "%s/Android/obb", source_path);
@@ -1623,7 +1625,7 @@ static int read_package_list(struct fuse *fuse) {
1623 1625
1624 char* token = strtok(gids, ","); 1626 char* token = strtok(gids, ",");
1625 while (token != NULL) { 1627 while (token != NULL) {
1626 if (strtoul(token, NULL, 10) == AID_SDCARD_RW) { 1628 if (strtoul(token, NULL, 10) == fuse->write_gid) {
1627 hashmapPut(fuse->appid_with_rw, (void*) appid, (void*) 1); 1629 hashmapPut(fuse->appid_with_rw, (void*) appid, (void*) 1);
1628 break; 1630 break;
1629 } 1631 }
@@ -1632,7 +1634,7 @@ static int read_package_list(struct fuse *fuse) {
1632 } 1634 }
1633 } 1635 }
1634 1636
1635 TRACE("read_package_list: found %d packages, %d with sdcard_rw\n", 1637 TRACE("read_package_list: found %d packages, %d with write_gid\n",
1636 hashmapSize(fuse->package_to_appid), 1638 hashmapSize(fuse->package_to_appid),
1637 hashmapSize(fuse->appid_with_rw)); 1639 hashmapSize(fuse->appid_with_rw));
1638 fclose(file); 1640 fclose(file);
@@ -1749,7 +1751,7 @@ static int usage()
1749 ERROR("usage: sdcard [OPTIONS] <source_path> <dest_path>\n" 1751 ERROR("usage: sdcard [OPTIONS] <source_path> <dest_path>\n"
1750 " -u: specify UID to run as\n" 1752 " -u: specify UID to run as\n"
1751 " -g: specify GID to run as\n" 1753 " -g: specify GID to run as\n"
1752 " -G: specify default GID for files (default sdcard_r, requires -d or -l)\n" 1754 " -w: specify GID required to write (default sdcard_rw, requires -d or -l)\n"
1753 " -t: specify number of threads to use (default %d)\n" 1755 " -t: specify number of threads to use (default %d)\n"
1754 " -d: derive file permissions based on path\n" 1756 " -d: derive file permissions based on path\n"
1755 " -l: derive file permissions based on legacy internal layout\n" 1757 " -l: derive file permissions based on legacy internal layout\n"
@@ -1759,7 +1761,8 @@ static int usage()
1759} 1761}
1760 1762
1761static int run(const char* source_path, const char* dest_path, uid_t uid, 1763static int run(const char* source_path, const char* dest_path, uid_t uid,
1762 gid_t gid, gid_t fs_gid, int num_threads, derive_t derive, bool split_perms) { 1764 gid_t gid, gid_t write_gid, int num_threads, derive_t derive,
1765 bool split_perms) {
1763 int fd; 1766 int fd;
1764 char opts[256]; 1767 char opts[256];
1765 int res; 1768 int res;
@@ -1802,7 +1805,7 @@ static int run(const char* source_path, const char* dest_path, uid_t uid,
1802 goto error; 1805 goto error;
1803 } 1806 }
1804 1807
1805 fuse_init(&fuse, fd, source_path, fs_gid, derive, split_perms); 1808 fuse_init(&fuse, fd, source_path, write_gid, derive, split_perms);
1806 1809
1807 umask(0); 1810 umask(0);
1808 res = ignite_fuse(&fuse, num_threads); 1811 res = ignite_fuse(&fuse, num_threads);
@@ -1822,7 +1825,7 @@ int main(int argc, char **argv)
1822 const char *dest_path = NULL; 1825 const char *dest_path = NULL;
1823 uid_t uid = 0; 1826 uid_t uid = 0;
1824 gid_t gid = 0; 1827 gid_t gid = 0;
1825 gid_t fs_gid = AID_SDCARD_R; 1828 gid_t write_gid = AID_SDCARD_RW;
1826 int num_threads = DEFAULT_NUM_THREADS; 1829 int num_threads = DEFAULT_NUM_THREADS;
1827 derive_t derive = DERIVE_NONE; 1830 derive_t derive = DERIVE_NONE;
1828 bool split_perms = false; 1831 bool split_perms = false;
@@ -1830,7 +1833,7 @@ int main(int argc, char **argv)
1830 struct rlimit rlim; 1833 struct rlimit rlim;
1831 1834
1832 int opt; 1835 int opt;
1833 while ((opt = getopt(argc, argv, "u:g:G:t:dls")) != -1) { 1836 while ((opt = getopt(argc, argv, "u:g:w:t:dls")) != -1) {
1834 switch (opt) { 1837 switch (opt) {
1835 case 'u': 1838 case 'u':
1836 uid = strtoul(optarg, NULL, 10); 1839 uid = strtoul(optarg, NULL, 10);
@@ -1838,8 +1841,8 @@ int main(int argc, char **argv)
1838 case 'g': 1841 case 'g':
1839 gid = strtoul(optarg, NULL, 10); 1842 gid = strtoul(optarg, NULL, 10);
1840 break; 1843 break;
1841 case 'G': 1844 case 'w':
1842 fs_gid = strtoul(optarg, NULL, 10); 1845 write_gid = strtoul(optarg, NULL, 10);
1843 break; 1846 break;
1844 case 't': 1847 case 't':
1845 num_threads = strtoul(optarg, NULL, 10); 1848 num_threads = strtoul(optarg, NULL, 10);
@@ -1902,6 +1905,6 @@ int main(int argc, char **argv)
1902 ERROR("Error setting RLIMIT_NOFILE, errno = %d\n", errno); 1905 ERROR("Error setting RLIMIT_NOFILE, errno = %d\n", errno);
1903 } 1906 }
1904 1907
1905 res = run(source_path, dest_path, uid, gid, fs_gid, num_threads, derive, split_perms); 1908 res = run(source_path, dest_path, uid, gid, write_gid, num_threads, derive, split_perms);
1906 return res < 0 ? 1 : 0; 1909 return res < 0 ? 1 : 0;
1907} 1910}