OSDN Git Service

vold: Honor mount options for ext4 partitions
authorTom Marshall <tdm@cyngn.com>
Thu, 5 Nov 2015 19:20:54 +0000 (11:20 -0800)
committerAdrian DC <radian.dc@gmail.com>
Thu, 24 Aug 2017 14:49:32 +0000 (16:49 +0200)
 * Save mount options and fstype for DiskPartition objects
 * Pass mount options and fstype to PublicVolume ctor
 * Pass mount options to Ext4::Mount
 * Use specified/default fstype if blkid fails

This is trivially extensible for other fs types.

Change-Id: Ie5dd27f26a4a7129dd9efe6a7ad0a589928282a0

Disk.cpp
Disk.h
DiskPartition.cpp
DiskPartition.h
PublicVolume.cpp
PublicVolume.h
VolumeManager.cpp
VolumeManager.h
fs/Ext4.cpp
fs/Ext4.h
main.cpp

index a85bfe5..d33593c 100644 (file)
--- a/Disk.cpp
+++ b/Disk.cpp
@@ -163,8 +163,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);
diff --git a/Disk.h b/Disk.h
index c94e829..a334069 100644 (file)
--- a/Disk.h
+++ b/Disk.h
@@ -110,7 +110,9 @@ protected:
     /* Flag that we just partitioned and should format all volumes */
     bool mJustPartitioned;
 
-    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 destroyAllVolumes();
index e0a606a..bb979da 100644 (file)
@@ -45,9 +45,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() {
     mCreated = true;
     notifyEvent(ResponseCode::DiskCreated, StringPrintf("%d", mFlags));
     dev_t partDevice = makedev(major(mDevice), minor(mDevice) + mPartNum);
-    createPublicVolume(partDevice);
+    createPublicVolume(partDevice, mFsType, mMntOpts);
     return OK;
 }
 
index 274d6be..7756271 100644 (file)
@@ -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
index 8a50e6e..b64488e 100644 (file)
@@ -45,8 +45,10 @@ static const char* kFusePath = "/system/bin/sdcard";
 
 static const char* kAsecPath = "/mnt/secure/asec";
 
-PublicVolume::PublicVolume(dev_t device) :
-        VolumeBase(Type::kPublic), mDevice(device), mFusePid(0) {
+PublicVolume::PublicVolume(dev_t device, const std::string& fstype /* = "" */,
+                const std::string& mntopts /* = "" */) :
+        VolumeBase(Type::kPublic), mDevice(device), mFusePid(0),
+        mFsType(fstype), mMntOpts(mntopts) {
     setId(StringPrintf("public:%u,%u", major(device), minor(device)));
     mDevPath = StringPrintf("/dev/block/vold/%s", getId().c_str());
 }
@@ -150,7 +152,7 @@ status_t PublicVolume::doMount() {
         ret = exfat::Mount(mDevPath, mRawPath, false, false, false,
                 AID_MEDIA_RW, AID_MEDIA_RW, 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);
     } else if (mFsType == "ntfs") {
index 3aa7a73..7b7186c 100644 (file)
@@ -39,7 +39,8 @@ namespace vold {
  */
 class PublicVolume : public VolumeBase {
 public:
-    explicit PublicVolume(dev_t device);
+    PublicVolume(dev_t device, const std::string& mntopts = "",
+                    const std::string& fstype = "");
     virtual ~PublicVolume();
 
 protected:
@@ -73,6 +74,8 @@ private:
     std::string mFsUuid;
     /* User-visible filesystem label */
     std::string mFsLabel;
+    /* Mount options */
+    std::string mMntOpts;
 
     DISALLOW_COPY_AND_ASSIGN(PublicVolume);
 };
index e720439..4b23218 100644 (file)
@@ -374,7 +374,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());
                 disk->create();
                 mDisks.push_back(std::shared_ptr<android::vold::Disk>(disk));
                 break;
index 29b72ab..3b7aa00 100644 (file)
@@ -97,8 +97,12 @@ public:
 
     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) {
@@ -108,12 +112,16 @@ public:
         const std::string& getNickname() { return mNickname; }
         int getPartNum() { return mPartNum; }
         int getFlags() { 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);
index 579a457..d77ef88 100644 (file)
@@ -130,12 +130,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 remount, 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;
 
@@ -143,7 +144,7 @@ status_t Mount(const std::string& source, const std::string& target, bool ro,
     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) {
         SLOGE("%s appears to be a read only filesystem - retrying mount RO", c_source);
index 8213c47..3fdf6f7 100644 (file)
--- a/fs/Ext4.h
+++ b/fs/Ext4.h
@@ -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 remount, 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);
index 78cce58..a49386f 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -228,6 +228,14 @@ static int process_config(VolumeManager *vm, bool* has_adoptable) {
     for (int i = 0; i < fstab->num_entries; i++) {
         if (fs_mgr_is_voldmanaged(&fstab->recs[i])) {
             std::string sysPattern(fstab->recs[i].blk_device);
+            std::string fstype;
+            if (fstab->recs[i].fs_type) {
+                fstype = fstab->recs[i].fs_type;
+            }
+            std::string mntopts;
+            if (fstab->recs[i].fs_options) {
+                mntopts = fstab->recs[i].fs_options;
+            }
             std::string nickname(fstab->recs[i].label);
             int partnum = fstab->recs[i].partnum;
             int flags = 0;
@@ -245,7 +253,8 @@ static int process_config(VolumeManager *vm, bool* has_adoptable) {
             }
 
             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;