リビジョン | 2cc005de01ad822ea8c8904a32738a38b5bacdf6 (tree) |
---|---|
日時 | 2017-08-24 23:49:32 |
作者 | Jani Lusikka <jani.lusikka@gmai...> |
コミッター | Adrian DC |
vold: Mount ext4/f2fs portable storage with sdcard_posix
This commit is a forward port of following commits:
Author: Michael Stucki <mundaun@gmx.ch>
Change-Id: Ia34ad91444951e62f6d17374f480dcbdfa34cca3
Author: Tom Marshall <tdm@cyngn.com>
Change-Id: I05d9b57cc28ffd1f8deb8148d81c7f6fad0aa8db
Author: Pawit Pornkitprasan <p.pawit@gmail.com>
Change-Id: I1364f37018b25d79b1826c85849def64e868d72f
Author: Pawit Pornkitprasan <p.pawit@gmail.com>
Change-Id: I873af4dc2309d3d0942ce466b8acf8158abb85ae
Author: Jorge Ruesga <jorge@ruesga.com>
Change-Id: Ic0bb314b30e42489c45caec29d35d6896c9849eb
Signed-off-by: Michael Bestas <mikeioannina@cyanogenmod.org>
Change-Id: I9699643987c53d8e2538720f33da28de35230dfe
@@ -152,9 +152,9 @@ status_t PublicVolume::doMount() { | ||
152 | 152 | ret = exfat::Mount(mDevPath, mRawPath, false, false, false, |
153 | 153 | AID_MEDIA_RW, AID_MEDIA_RW, 0007); |
154 | 154 | } else if (mFsType == "ext4") { |
155 | - ret = ext4::Mount(mDevPath, mRawPath, false, false, true, mMntOpts); | |
155 | + ret = ext4::Mount(mDevPath, mRawPath, false, false, true, mMntOpts, true); | |
156 | 156 | } else if (mFsType == "f2fs") { |
157 | - ret = f2fs::Mount(mDevPath, mRawPath, mMntOpts); | |
157 | + ret = f2fs::Mount(mDevPath, mRawPath, mMntOpts, true); | |
158 | 158 | } else if (mFsType == "ntfs") { |
159 | 159 | ret = ntfs::Mount(mDevPath, mRawPath, false, false, false, |
160 | 160 | AID_MEDIA_RW, AID_MEDIA_RW, 0007, true); |
@@ -36,7 +36,7 @@ | ||
36 | 36 | #include <linux/kdev_t.h> |
37 | 37 | |
38 | 38 | #define LOG_TAG "Vold" |
39 | - | |
39 | +#include <private/android_filesystem_config.h> | |
40 | 40 | #include <android-base/logging.h> |
41 | 41 | #include <android-base/stringprintf.h> |
42 | 42 | #include <cutils/log.h> |
@@ -130,13 +130,21 @@ status_t Check(const std::string& source, const std::string& target, bool truste | ||
130 | 130 | } |
131 | 131 | |
132 | 132 | status_t Mount(const std::string& source, const std::string& target, bool ro, |
133 | - bool remount, bool executable, const std::string& opts /* = "" */) { | |
133 | + bool remount, bool executable, const std::string& opts /* = "" */, bool portable) { | |
134 | 134 | int rc; |
135 | 135 | unsigned long flags; |
136 | 136 | |
137 | + std::string data(opts); | |
138 | + | |
139 | + if (portable) { | |
140 | + if (!data.empty()) { | |
141 | + data += ","; | |
142 | + } | |
143 | + data += "context=u:object_r:sdcard_posix:s0"; | |
144 | + } | |
137 | 145 | const char* c_source = source.c_str(); |
138 | 146 | const char* c_target = target.c_str(); |
139 | - const char* c_opts = opts.c_str(); | |
147 | + const char* c_data = data.c_str(); | |
140 | 148 | |
141 | 149 | flags = MS_NOATIME | MS_NODEV | MS_NOSUID | MS_DIRSYNC; |
142 | 150 |
@@ -144,12 +152,16 @@ status_t Mount(const std::string& source, const std::string& target, bool ro, | ||
144 | 152 | flags |= (ro ? MS_RDONLY : 0); |
145 | 153 | flags |= (remount ? MS_REMOUNT : 0); |
146 | 154 | |
147 | - rc = mount(c_source, c_target, "ext4", flags, c_opts); | |
155 | + rc = mount(c_source, c_target, "ext4", flags, c_data); | |
156 | + if (portable && rc == 0) { | |
157 | + chown(c_target, AID_MEDIA_RW, AID_MEDIA_RW); | |
158 | + chmod(c_target, 0755); | |
159 | + } | |
148 | 160 | |
149 | 161 | if (rc && errno == EROFS) { |
150 | 162 | SLOGE("%s appears to be a read only filesystem - retrying mount RO", c_source); |
151 | 163 | flags |= MS_RDONLY; |
152 | - rc = mount(c_source, c_target, "ext4", flags, NULL); | |
164 | + rc = mount(c_source, c_target, "ext4", flags, c_data); | |
153 | 165 | } |
154 | 166 | |
155 | 167 | return rc; |
@@ -29,7 +29,7 @@ bool IsSupported(); | ||
29 | 29 | |
30 | 30 | status_t Check(const std::string& source, const std::string& target, bool trusted); |
31 | 31 | status_t Mount(const std::string& source, const std::string& target, bool ro, |
32 | - bool remount, bool executable, const std::string& opts = ""); | |
32 | + bool remount, bool executable, const std::string& opts = "", bool portable = false); | |
33 | 33 | status_t Format(const std::string& source, unsigned long numSectors, |
34 | 34 | const std::string& target); |
35 | 35 | status_t Resize(const std::string& source, unsigned long numSectors); |
@@ -19,10 +19,10 @@ | ||
19 | 19 | |
20 | 20 | #include <android-base/logging.h> |
21 | 21 | #include <android-base/stringprintf.h> |
22 | - | |
22 | +#include <private/android_filesystem_config.h> | |
23 | 23 | #include <vector> |
24 | 24 | #include <string> |
25 | - | |
25 | +#include <sys/stat.h> | |
26 | 26 | #include <sys/mount.h> |
27 | 27 | |
28 | 28 | using android::base::StringPrintf; |
@@ -49,17 +49,32 @@ status_t Check(const std::string& source, bool trusted) { | ||
49 | 49 | return ForkExecvp(cmd, trusted ? sFsckContext : sFsckUntrustedContext); |
50 | 50 | } |
51 | 51 | |
52 | -status_t Mount(const std::string& source, const std::string& target, const std::string& opts /* = "" */) { | |
52 | +status_t Mount(const std::string& source, const std::string& target, const std::string& opts /* = "" */, bool portable) { | |
53 | + | |
54 | + std::string data(opts); | |
55 | + | |
56 | + if (portable) { | |
57 | + if (!data.empty()) { | |
58 | + data += ","; | |
59 | + } | |
60 | + data += "context=u:object_r:sdcard_posix:s0"; | |
61 | + } | |
62 | + | |
53 | 63 | const char* c_source = source.c_str(); |
54 | 64 | const char* c_target = target.c_str(); |
55 | - const char* c_opts = opts.c_str(); | |
65 | + const char* c_data = data.c_str(); | |
56 | 66 | unsigned long flags = MS_NOATIME | MS_NODEV | MS_NOSUID | MS_DIRSYNC; |
57 | 67 | |
58 | - int res = mount(c_source, c_target, "f2fs", flags, c_opts); | |
68 | + int res = mount(c_source, c_target, "f2fs", flags, c_data); | |
69 | + if (portable && res == 0) { | |
70 | + chown(c_target, AID_MEDIA_RW, AID_MEDIA_RW); | |
71 | + chmod(c_target, 0755); | |
72 | + } | |
73 | + | |
59 | 74 | if (res != 0) { |
60 | 75 | PLOG(ERROR) << "Failed to mount " << source; |
61 | 76 | if (errno == EROFS) { |
62 | - res = mount(c_source, c_target, "f2fs", flags | MS_RDONLY, NULL); | |
77 | + res = mount(c_source, c_target, "f2fs", flags | MS_RDONLY, c_data); | |
63 | 78 | if (res != 0) { |
64 | 79 | PLOG(ERROR) << "Failed to mount read-only " << source; |
65 | 80 | } |
@@ -28,7 +28,7 @@ namespace f2fs { | ||
28 | 28 | bool IsSupported(); |
29 | 29 | |
30 | 30 | status_t Check(const std::string& source, bool trusted); |
31 | -status_t Mount(const std::string& source, const std::string& target, const std::string& opts = ""); | |
31 | +status_t Mount(const std::string& source, const std::string& target, const std::string& opts = "", bool portable = false); | |
32 | 32 | status_t Format(const std::string& source); |
33 | 33 | |
34 | 34 | } // namespace f2fs |