• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


Commit MetaInfo

修訂d63e6757fa22fcb58653233fce035deed8036a1b (tree)
時間2016-07-24 12:24:07
作者Steve Kondik <steve@cyng...>
CommiterSteve Kondik

Log Message

sdcard: Add support for sdcardfs!

  • sdcardfs is a kernel filesystem developed by Samsung and recently
    seen in AOSP's common kernel branches. It entirely eliminates
    the need to use FUSE for sdcard emulation and moves all the
    wrapping logic to kernel. This vastly improves performance for
    use cases which read/write to emulated as well as removable
    cards.

Change-Id: I3e394a99e0a4b5beacaeddc0d4dd4855ff0cf082

Change Summary

差異

--- a/sdcard/sdcard.c
+++ b/sdcard/sdcard.c
@@ -41,6 +41,7 @@
4141 #include <cutils/hashmap.h>
4242 #include <cutils/log.h>
4343 #include <cutils/multiuser.h>
44+#include <cutils/properties.h>
4445
4546 #include <private/android_filesystem_config.h>
4647
@@ -1776,24 +1777,39 @@ static int usage() {
17761777 return 1;
17771778 }
17781779
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) {
17801781 char opts[256];
17811782
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+ }
17861789 }
17871790
17881791 umount2(fuse->dest_path, MNT_DETACH);
17891792
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+ }
17971813 }
17981814
17991815 fuse->gid = gid;
@@ -1803,7 +1819,7 @@ static int fuse_setup(struct fuse* fuse, gid_t gid, mode_t mask) {
18031819 }
18041820
18051821 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) {
18071823 struct fuse_global global;
18081824 struct fuse fuse_default;
18091825 struct fuse fuse_read;
@@ -1875,9 +1891,9 @@ static void run(const char* source_path, const char* label, uid_t uid,
18751891 if (multi_user) {
18761892 /* Multi-user storage is fully isolated per user, so "other"
18771893 * 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)) {
18811897 ERROR("failed to fuse_setup\n");
18821898 exit(1);
18831899 }
@@ -1885,14 +1901,19 @@ static void run(const char* source_path, const char* label, uid_t uid,
18851901 /* Physical storage is readable by all users on device, but
18861902 * the Android directories are masked off to a single user
18871903 * 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)) {
18911907 ERROR("failed to fuse_setup\n");
18921908 exit(1);
18931909 }
18941910 }
18951911
1912+ // Nothing else for us to do if sdcardfs is in use!
1913+ if (use_sdcardfs) {
1914+ exit(0);
1915+ }
1916+
18961917 /* Drop privs */
18971918 if (setgroups(sizeof(kGroups) / sizeof(kGroups[0]), kGroups) < 0) {
18981919 ERROR("cannot setgroups: %s\n", strerror(errno));
@@ -1995,6 +2016,8 @@ int sdcard_main(int argc, char **argv) {
19952016 sleep(1);
19962017 }
19972018
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);
19992022 return 1;
20002023 }