AID_MEDIA_RW, AID_MEDIA_RW, 0007);
} else if (mFsType == "ext4") {
ret = ext4::Mount(mDevPath, mRawPath, false, false, true, mMntOpts,
- false);
+ false, true);
} else if (mFsType == "f2fs") {
- ret = f2fs::Mount(mDevPath, mRawPath, mMntOpts, false);
+ ret = f2fs::Mount(mDevPath, mRawPath, mMntOpts, false, true);
} else if (mFsType == "ntfs") {
ret = ntfs::Mount(mDevPath, mRawPath, false, false, false,
AID_MEDIA_RW, AID_MEDIA_RW, 0007, true);
#include <cutils/log.h>
#include <cutils/properties.h>
#include <logwrap/logwrap.h>
+#include <private/android_filesystem_config.h>
#include <selinux/selinux.h>
#include "Ext4.h"
status_t Mount(const std::string& source, const std::string& target, bool ro,
bool remount, bool executable, const std::string& opts /* = "" */,
- bool trusted) {
+ bool trusted, bool portable) {
int rc;
unsigned long flags;
+ std::string data(opts);
+
+ if (portable) {
+ if (!data.empty()) {
+ data += ",";
+ }
+ data += "context=u:object_r:sdcard_posix:s0";
+ }
+
const char* c_source = source.c_str();
const char* c_target = target.c_str();
- const char* c_opts = opts.c_str();
+ const char* c_data = data.c_str();
flags = MS_NOATIME | MS_NODEV | MS_NOSUID;
flags |= (ro ? MS_RDONLY : 0);
flags |= (remount ? MS_REMOUNT : 0);
- rc = mount(c_source, c_target, "ext4", flags, c_opts);
+ rc = mount(c_source, c_target, "ext4", flags, c_data);
+
+ if (portable && rc == 0) {
+ chown(c_target, AID_MEDIA_RW, AID_MEDIA_RW);
+ chmod(c_target, 0755);
+ }
if (rc && errno == EROFS) {
SLOGE("%s appears to be a read only filesystem - retrying mount RO", c_source);
flags |= MS_RDONLY;
- rc = mount(c_source, c_target, "ext4", flags, NULL);
+ rc = mount(c_source, c_target, "ext4", flags, c_data);
}
return rc;
bool trusted);
status_t Mount(const std::string& source, const std::string& target, bool ro,
bool remount, bool executable, const std::string& opts = "",
- bool trusted = false);
+ bool trusted = false, bool portable = false);
status_t Format(const std::string& source, unsigned int numSectors,
const std::string& target);
status_t Resize(const std::string& source, unsigned int numSectors);
#include <base/logging.h>
#include <base/stringprintf.h>
+#include <private/android_filesystem_config.h>
#include <vector>
#include <string>
#include <sys/mount.h>
+#include <sys/stat.h>
using android::base::StringPrintf;
}
status_t Mount(const std::string& source, const std::string& target,
- const std::string& opts /* = "" */, bool trusted) {
+ const std::string& opts /* = "" */, bool trusted, bool portable) {
+ std::string data(opts);
+
+ if (portable) {
+ if (!data.empty()) {
+ data += ",";
+ }
+ data += "context=u:object_r:sdcard_posix:s0";
+ }
+
const char* c_source = source.c_str();
const char* c_target = target.c_str();
- const char* c_opts = opts.c_str();
+ const char* c_data = data.c_str();
+
unsigned long flags = MS_NOATIME | MS_NODEV | MS_NOSUID;
// Only use MS_DIRSYNC if we're not mounting adopted storage
flags |= MS_DIRSYNC;
}
- int res = mount(c_source, c_target, "f2fs", flags, c_opts);
+ int res = mount(c_source, c_target, "f2fs", flags, c_data);
+
+ if (portable && res == 0) {
+ chown(c_target, AID_MEDIA_RW, AID_MEDIA_RW);
+ chmod(c_target, 0755);
+ }
+
if (res != 0) {
PLOG(ERROR) << "Failed to mount " << source;
if (errno == EROFS) {
- res = mount(c_source, c_target, "f2fs", flags | MS_RDONLY, NULL);
+ res = mount(c_source, c_target, "f2fs", flags | MS_RDONLY, c_data);
if (res != 0) {
PLOG(ERROR) << "Failed to mount read-only " << source;
}
status_t Check(const std::string& source, bool trusted);
status_t Mount(const std::string& source, const std::string& target,
- const std::string& opts = "", bool trusted = false);
+ const std::string& opts = "", bool trusted = false,
+ bool portable = false);
status_t Format(const std::string& source);
} // namespace f2fs