system/corennnnn
修訂 | d63e6757fa22fcb58653233fce035deed8036a1b (tree) |
---|---|
時間 | 2016-07-24 12:24:07 |
作者 | Steve Kondik <steve@cyng...> |
Commiter | Steve Kondik |
sdcard: Add support for sdcardfs!
Change-Id: I3e394a99e0a4b5beacaeddc0d4dd4855ff0cf082
@@ -41,6 +41,7 @@ | ||
41 | 41 | #include <cutils/hashmap.h> |
42 | 42 | #include <cutils/log.h> |
43 | 43 | #include <cutils/multiuser.h> |
44 | +#include <cutils/properties.h> | |
44 | 45 | |
45 | 46 | #include <private/android_filesystem_config.h> |
46 | 47 |
@@ -1776,24 +1777,39 @@ static int usage() { | ||
1776 | 1777 | return 1; |
1777 | 1778 | } |
1778 | 1779 | |
1779 | -static int fuse_setup(struct fuse* fuse, gid_t gid, mode_t mask) { | |
1780 | +static int fuse_setup(struct fuse* fuse, gid_t gid, mode_t mask, bool use_sdcardfs) { | |
1780 | 1781 | char opts[256]; |
1781 | 1782 | |
1782 | - fuse->fd = open("/dev/fuse", O_RDWR); | |
1783 | - if (fuse->fd == -1) { | |
1784 | - ERROR("failed to open fuse device: %s\n", strerror(errno)); | |
1785 | - return -1; | |
1783 | + if (use_sdcardfs) { | |
1784 | + fuse->fd = open("/dev/fuse", O_RDWR); | |
1785 | + if (fuse->fd == -1) { | |
1786 | + ERROR("failed to open fuse device: %s\n", strerror(errno)); | |
1787 | + return -1; | |
1788 | + } | |
1786 | 1789 | } |
1787 | 1790 | |
1788 | 1791 | umount2(fuse->dest_path, MNT_DETACH); |
1789 | 1792 | |
1790 | - snprintf(opts, sizeof(opts), | |
1791 | - "fd=%i,rootmode=40000,default_permissions,allow_other,user_id=%d,group_id=%d", | |
1792 | - fuse->fd, fuse->global->uid, fuse->global->gid); | |
1793 | - if (mount("/dev/fuse", fuse->dest_path, "fuse", MS_NOSUID | MS_NODEV | MS_NOEXEC | | |
1794 | - MS_NOATIME, opts) != 0) { | |
1795 | - ERROR("failed to mount fuse filesystem: %s\n", strerror(errno)); | |
1796 | - return -1; | |
1793 | + if (use_sdcardfs) { | |
1794 | + snprintf(opts, sizeof(opts), | |
1795 | + "%sfsuid=%d,fsgid=%d,userid=%d,gid=%d,mask=%04o,reserved_mb=20", | |
1796 | + (fuse->global->multi_user ? "multiuser," : ""), | |
1797 | + fuse->global->uid, fuse->global->gid, | |
1798 | + fuse->global->root.userid, gid, mask); | |
1799 | + if (mount(fuse->global->source_path, fuse->dest_path, "sdcardfs", | |
1800 | + MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_NOATIME, opts) != 0) { | |
1801 | + ERROR("failed to mount sdcardfs filesystem: %s\n", strerror(errno)); | |
1802 | + return -1; | |
1803 | + } | |
1804 | + } else { | |
1805 | + snprintf(opts, sizeof(opts), | |
1806 | + "fd=%i,rootmode=40000,default_permissions,allow_other,user_id=%d,group_id=%d", | |
1807 | + fuse->fd, fuse->global->uid, fuse->global->gid); | |
1808 | + if (mount("/dev/fuse", fuse->dest_path, "fuse", MS_NOSUID | MS_NODEV | MS_NOEXEC | | |
1809 | + MS_NOATIME, opts) != 0) { | |
1810 | + ERROR("failed to mount fuse filesystem: %s\n", strerror(errno)); | |
1811 | + return -1; | |
1812 | + } | |
1797 | 1813 | } |
1798 | 1814 | |
1799 | 1815 | fuse->gid = gid; |
@@ -1803,7 +1819,7 @@ static int fuse_setup(struct fuse* fuse, gid_t gid, mode_t mask) { | ||
1803 | 1819 | } |
1804 | 1820 | |
1805 | 1821 | static void run(const char* source_path, const char* label, uid_t uid, |
1806 | - gid_t gid, userid_t userid, bool multi_user, bool full_write) { | |
1822 | + gid_t gid, userid_t userid, bool multi_user, bool full_write, bool use_sdcardfs) { | |
1807 | 1823 | struct fuse_global global; |
1808 | 1824 | struct fuse fuse_default; |
1809 | 1825 | struct fuse fuse_read; |
@@ -1875,9 +1891,9 @@ static void run(const char* source_path, const char* label, uid_t uid, | ||
1875 | 1891 | if (multi_user) { |
1876 | 1892 | /* Multi-user storage is fully isolated per user, so "other" |
1877 | 1893 | * permissions are completely masked off. */ |
1878 | - if (fuse_setup(&fuse_default, AID_SDCARD_RW, 0006) | |
1879 | - || fuse_setup(&fuse_read, AID_EVERYBODY, 0027) | |
1880 | - || fuse_setup(&fuse_write, AID_EVERYBODY, full_write ? 0007 : 0027)) { | |
1894 | + if (fuse_setup(&fuse_default, AID_SDCARD_RW, 0006, use_sdcardfs) | |
1895 | + || fuse_setup(&fuse_read, AID_EVERYBODY, 0027, use_sdcardfs) | |
1896 | + || fuse_setup(&fuse_write, AID_EVERYBODY, full_write ? 0007 : 0027, use_sdcardfs)) { | |
1881 | 1897 | ERROR("failed to fuse_setup\n"); |
1882 | 1898 | exit(1); |
1883 | 1899 | } |
@@ -1885,14 +1901,19 @@ static void run(const char* source_path, const char* label, uid_t uid, | ||
1885 | 1901 | /* Physical storage is readable by all users on device, but |
1886 | 1902 | * the Android directories are masked off to a single user |
1887 | 1903 | * deep inside attr_from_stat(). */ |
1888 | - if (fuse_setup(&fuse_default, AID_SDCARD_RW, 0006) | |
1889 | - || fuse_setup(&fuse_read, AID_EVERYBODY, full_write ? 0027 : 0022) | |
1890 | - || fuse_setup(&fuse_write, AID_EVERYBODY, full_write ? 0007 : 0022)) { | |
1904 | + if (fuse_setup(&fuse_default, AID_SDCARD_RW, 0006, use_sdcardfs) | |
1905 | + || fuse_setup(&fuse_read, AID_EVERYBODY, full_write ? 0027 : 0022, use_sdcardfs) | |
1906 | + || fuse_setup(&fuse_write, AID_EVERYBODY, full_write ? 0007 : 0022, use_sdcardfs)) { | |
1891 | 1907 | ERROR("failed to fuse_setup\n"); |
1892 | 1908 | exit(1); |
1893 | 1909 | } |
1894 | 1910 | } |
1895 | 1911 | |
1912 | + // Nothing else for us to do if sdcardfs is in use! | |
1913 | + if (use_sdcardfs) { | |
1914 | + exit(0); | |
1915 | + } | |
1916 | + | |
1896 | 1917 | /* Drop privs */ |
1897 | 1918 | if (setgroups(sizeof(kGroups) / sizeof(kGroups[0]), kGroups) < 0) { |
1898 | 1919 | ERROR("cannot setgroups: %s\n", strerror(errno)); |
@@ -1995,6 +2016,8 @@ int sdcard_main(int argc, char **argv) { | ||
1995 | 2016 | sleep(1); |
1996 | 2017 | } |
1997 | 2018 | |
1998 | - run(source_path, label, uid, gid, userid, multi_user, full_write); | |
2019 | + bool use_sdcardfs = property_get_bool("ro.sdcardfs.enable", false); | |
2020 | + | |
2021 | + run(source_path, label, uid, gid, userid, multi_user, full_write, use_sdcardfs); | |
1999 | 2022 | return 1; |
2000 | 2023 | } |