vold: Honor mount options for ext4/f2fs partitions

* Save mount options and fstype for DiskPartition objects
 * Pass mount options and fstype to PublicVolume ctor
 * Pass mount options to ext4::Mount/f2fs:Mount
 * Use specified/default fstype if blkid fails

This is trivially extensible for other fs types.

[mikeioannina] Adapt for Pie and Q

Change-Id: Ie5dd27f26a4a7129dd9efe6a7ad0a589928282a0
gugelfrei
Tom Marshall 9 years ago committed by Aaron Kling
parent af516f8875
commit 76c235ffe3

@ -245,7 +245,8 @@ void VolumeManager::handleBlockEvent(NetlinkEvent* evt) {
source->getNickname(), flags) :
new android::vold::DiskPartition(eventPath, device,
source->getNickname(), flags,
source->getPartNum());
source->getPartNum(),
source->getFsType(), source->getMntOpts());
handleDiskAdded(std::shared_ptr<android::vold::Disk>(disk));
break;
}

@ -63,8 +63,12 @@ class VolumeManager {
class DiskSource {
public:
DiskSource(const std::string& sysPattern, const std::string& nickname, int partnum, int flags)
: mSysPattern(sysPattern), mNickname(nickname), mPartNum(partnum), mFlags(flags) {}
DiskSource(const std::string& sysPattern, const std::string& nickname,
int partnum, int flags,
const std::string& fstype, const std::string mntopts)
: mSysPattern(sysPattern), mNickname(nickname),
mPartNum(partnum), mFlags(flags),
mFsType(fstype), mMntOpts(mntopts) {}
bool matches(const std::string& sysPath) {
return !fnmatch(mSysPattern.c_str(), sysPath.c_str(), 0);
@ -73,12 +77,16 @@ class VolumeManager {
const std::string& getNickname() const { return mNickname; }
int getPartNum() const { return mPartNum; }
int getFlags() const { return mFlags; }
const std::string& getFsType() { return mFsType; }
const std::string& getMntOpts() { return mMntOpts; }
private:
std::string mSysPattern;
std::string mNickname;
int mPartNum;
int mFlags;
std::string mFsType;
std::string mMntOpts;
};
void addDiskSource(const std::shared_ptr<DiskSource>& diskSource);

@ -123,12 +123,13 @@ status_t Check(const std::string& source, const std::string& target, bool truste
}
status_t Mount(const std::string& source, const std::string& target, bool ro, bool remount,
bool executable) {
bool executable, const std::string& opts /* = "" */) {
int rc;
unsigned long flags;
const char* c_source = source.c_str();
const char* c_target = target.c_str();
const char* c_opts = opts.c_str();
flags = MS_NOATIME | MS_NODEV | MS_NOSUID | MS_DIRSYNC;
@ -136,7 +137,7 @@ status_t Mount(const std::string& source, const std::string& target, bool ro, bo
flags |= (ro ? MS_RDONLY : 0);
flags |= (remount ? MS_REMOUNT : 0);
rc = mount(c_source, c_target, "ext4", flags, NULL);
rc = mount(c_source, c_target, "ext4", flags, c_opts);
if (rc && errno == EROFS) {
LOG(ERROR) << source << " appears to be a read only filesystem - retrying mount RO";

@ -29,7 +29,7 @@ bool IsSupported();
status_t Check(const std::string& source, const std::string& target, bool trusted);
status_t Mount(const std::string& source, const std::string& target, bool ro, bool remount,
bool executable);
bool executable, const std::string& opts = "");
status_t Format(const std::string& source, unsigned long numSectors, const std::string& target);
status_t Resize(const std::string& source, unsigned long numSectors);

@ -50,12 +50,13 @@ status_t Check(const std::string& source, bool trusted) {
return ForkExecvp(cmd, nullptr, trusted ? sFsckContext : sFsckUntrustedContext);
}
status_t Mount(const std::string& source, const std::string& target) {
status_t Mount(const std::string& source, const std::string& target, const std::string& opts /* = "" */) {
const char* c_source = source.c_str();
const char* c_target = target.c_str();
const char* c_opts = opts.c_str();
unsigned long flags = MS_NOATIME | MS_NODEV | MS_NOSUID | MS_DIRSYNC;
int res = mount(c_source, c_target, "f2fs", flags, NULL);
int res = mount(c_source, c_target, "f2fs", flags, c_opts);
if (res != 0) {
PLOG(ERROR) << "Failed to mount " << source;
if (errno == EROFS) {

@ -28,7 +28,7 @@ namespace f2fs {
bool IsSupported();
status_t Check(const std::string& source, bool trusted);
status_t Mount(const std::string& source, const std::string& target);
status_t Mount(const std::string& source, const std::string& target, const std::string& opts = "");
status_t Format(const std::string& source);
} // namespace f2fs

@ -243,6 +243,14 @@ static int process_config(VolumeManager* vm, bool* has_adoptable, bool* has_quot
if (entry.fs_mgr_flags.vold_managed) {
std::string sysPattern(entry.blk_device);
std::string fstype;
if (!entry.fs_type.empty()) {
fstype = entry.fs_type;
}
std::string mntopts;
if (!entry.fs_options.empty()) {
mntopts = entry.fs_options;
}
std::string nickname(entry.label);
int partnum = entry.partnum;
int flags = 0;
@ -260,7 +268,8 @@ static int process_config(VolumeManager* vm, bool* has_adoptable, bool* has_quot
}
vm->addDiskSource(std::shared_ptr<VolumeManager::DiskSource>(
new VolumeManager::DiskSource(sysPattern, nickname, partnum, flags)));
new VolumeManager::DiskSource(sysPattern, nickname, partnum, flags,
fstype, mntopts)));
}
}
return 0;

@ -171,8 +171,10 @@ status_t Disk::destroy() {
return OK;
}
void Disk::createPublicVolume(dev_t device) {
auto vol = std::shared_ptr<VolumeBase>(new PublicVolume(device));
void Disk::createPublicVolume(dev_t device,
const std::string& fstype /* = "" */,
const std::string& mntopts /* = "" */) {
auto vol = std::shared_ptr<VolumeBase>(new PublicVolume(device, fstype, mntopts));
if (mJustPartitioned) {
LOG(DEBUG) << "Device just partitioned; silently formatting";
vol->setSilent(true);

@ -116,7 +116,9 @@ class Disk {
/* Flag that we need to skip first disk change events after partitioning*/
bool mSkipChange;
void createPublicVolume(dev_t device);
void createPublicVolume(dev_t device,
const std::string& fstype = "",
const std::string& mntopts = "");
void createPrivateVolume(dev_t device, const std::string& partGuid);
void createStubVolume();

@ -44,9 +44,12 @@ namespace android {
namespace vold {
DiskPartition::DiskPartition(const std::string& eventPath, dev_t device,
const std::string& nickname, int flags, int partnum) :
const std::string& nickname, int flags, int partnum,
const std::string& fstype /* = "" */, const std::string& mntopts /* = "" */) :
Disk(eventPath, device, nickname, flags),
mPartNum(partnum) {
mPartNum(partnum),
mFsType(fstype),
mMntOpts(mntopts) {
// Empty
}
@ -60,7 +63,7 @@ status_t DiskPartition::create() {
auto listener = VolumeManager::Instance()->getListener();
if (listener) listener->onDiskCreated(getId(), mFlags);
dev_t partDevice = makedev(major(mDevice), minor(mDevice) + mPartNum);
createPublicVolume(partDevice);
createPublicVolume(partDevice, mFsType, mMntOpts);
return OK;
}

@ -31,7 +31,8 @@ class DiskPartition : public Disk {
public:
DiskPartition(const std::string& eventPath, dev_t device,
const std::string& nickname,
int flags, int partnum);
int flags, int partnum,
const std::string& fstype = "", const std::string& mntopts = "");
virtual ~DiskPartition();
virtual status_t create();
@ -44,6 +45,10 @@ public:
private:
/* Partition number */
int mPartNum;
/* Filesystem type */
std::string mFsType;
/* Mount options */
std::string mMntOpts;
};
} // namespace vold

@ -177,7 +177,7 @@ status_t PrivateVolume::doMount() {
return -EIO;
}
if (f2fs::Mount(mDmDevPath, mPath)) {
if (f2fs::Mount(mDmDevPath, mPath, "")) {
PLOG(ERROR) << getId() << " failed to mount";
return -EIO;
}

@ -50,7 +50,10 @@ static const char* kSdcardFsPath = "/system/bin/sdcard";
static const char* kAsecPath = "/mnt/secure/asec";
PublicVolume::PublicVolume(dev_t device) : VolumeBase(Type::kPublic), mDevice(device) {
PublicVolume::PublicVolume(dev_t device, const std::string& fstype /* = "" */,
const std::string& mntopts /* = "" */)
: VolumeBase(Type::kPublic), mDevice(device),
mFsType(fstype), mMntOpts(mntopts) {
setId(StringPrintf("public:%u,%u", major(device), minor(device)));
mDevPath = StringPrintf("/dev/block/vold/%s", getId().c_str());
mFuseMounted = false;
@ -156,9 +159,9 @@ status_t PublicVolume::doMount() {
ret = exfat::Mount(mDevPath, mRawPath, AID_ROOT,
(isVisible ? AID_MEDIA_RW : AID_EXTERNAL_STORAGE), 0007);
} else if (mFsType == "ext4") {
ret = ext4::Mount(mDevPath, mRawPath, false, false, true);
ret = ext4::Mount(mDevPath, mRawPath, false, false, true, mMntOpts);
} else if (mFsType == "f2fs") {
ret = f2fs::Mount(mDevPath, mRawPath);
ret = f2fs::Mount(mDevPath, mRawPath, mMntOpts);
} else if (mFsType == "ntfs") {
ret = ntfs::Mount(mDevPath, mRawPath, AID_ROOT,
(isVisible ? AID_MEDIA_RW : AID_EXTERNAL_STORAGE), 0007);

@ -39,7 +39,8 @@ namespace vold {
*/
class PublicVolume : public VolumeBase {
public:
explicit PublicVolume(dev_t device);
explicit PublicVolume(dev_t device, const std::string& mntopts = "",
const std::string& fstype = "");
virtual ~PublicVolume();
protected:
@ -77,6 +78,8 @@ class PublicVolume : public VolumeBase {
std::string mFsUuid;
/* User-visible filesystem label */
std::string mFsLabel;
/* Mount options */
std::string mMntOpts;
DISALLOW_COPY_AND_ASSIGN(PublicVolume);
};

Loading…
Cancel
Save