OSDN Git Service

vold3: support the old SDCARD=xxx function
authorChih-Wei Huang <cwhuang@linux.org.tw>
Fri, 12 Aug 2016 17:58:29 +0000 (01:58 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Fri, 12 Aug 2016 17:58:29 +0000 (01:58 +0800)
By specifying SDCARD=xxx in kernel cmdline, vold will try to mount
that disk or partition as a sdcard. This is an old function we've
added to vold 2.0. Now re-implement it in vold 3.0. Some people
still like and use it.

main.cpp

index 4301b2e..06221db 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -22,6 +22,7 @@
 #include "cryptfs.h"
 #include "sehandle.h"
 
+#include <base/file.h>
 #include <base/logging.h>
 #include <base/stringprintf.h>
 #include <cutils/klog.h>
@@ -255,6 +256,36 @@ static int process_config(VolumeManager *vm) {
                                     fstype, mntopts)));
         }
     }
+
+    if (android::base::ReadFileToString("/proc/cmdline", &path)) {
+        size_t pos = path.find("SDCARD=");
+        if (pos != std::string::npos) {
+            std::string sdcard = path.substr(pos + 7);
+            sdcard = sdcard.substr(0, sdcard.find_first_of(" \n"));
+            if (!sdcard.empty()) {
+                int partnum = -1;
+                if (access(std::string("/sys/block/" + sdcard).c_str(), X_OK)) { // not a disk
+                    auto d = std::find_if_not(sdcard.rbegin(), sdcard.rend(), ::isdigit);
+                    pos = std::distance(d, sdcard.rend());
+                    if (pos != sdcard.length()) {
+                        partnum = std::stoi(sdcard.substr(pos));
+                        sdcard = sdcard.substr(0, pos);
+                        if (sdcard.find("mmcblk") != std::string::npos) {
+                            // exclude the last 'p'
+                            sdcard = sdcard.substr(0, pos - 1);
+                        }
+                    }
+                }
+                vm->addDiskSource(std::shared_ptr<VolumeManager::DiskSource>(
+                        new VolumeManager::DiskSource("/devices/*/" + sdcard, sdcard,
+                        partnum, android::vold::Disk::Flags::kAdoptable, "auto", "")));
+                has_adoptable = true;
+                LOG(INFO) << "Add SDCARD=" << sdcard << " partnum=" << partnum;
+            }
+        }
+
+    }
+
     property_set("vold.has_adoptable", has_adoptable ? "1" : "0");
     return 0;
 }