OSDN Git Service

minivold: Use libblkid for readMetadata
authorTom Marshall <tdm@cyngn.com>
Thu, 10 Mar 2016 23:55:01 +0000 (15:55 -0800)
committerTom Marshall <tdm@cyngn.com>
Fri, 11 Mar 2016 00:03:28 +0000 (16:03 -0800)
We cannot popen() /sbin/blkid because selinux.

Change-Id: I0ba032c362dcfaa72443860071e5bd4d4d3b8270

Android.mk
Utils.cpp

index 3f4dd1c..f812755 100644 (file)
@@ -39,7 +39,8 @@ common_c_includes := \
        frameworks/native/include \
        system/security/keystore \
        hardware/libhardware/include/hardware \
-       system/security/softkeymaster/include/keymaster
+       system/security/softkeymaster/include/keymaster \
+       external/e2fsprogs/lib
 
 common_libraries := \
        libsysutils \
index a2640eb..6ffdd7f 100644 (file)
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -56,7 +56,7 @@ security_context_t sFsckContext = nullptr;
 security_context_t sFsckUntrustedContext = nullptr;
 
 #ifdef MINIVOLD
-static const char* kBlkidPath = "/sbin/blkid";
+#include <blkid/blkid.h>
 #else
 static const char* kBlkidPath = "/system/bin/blkid";
 #endif
@@ -198,9 +198,23 @@ status_t BindMount(const std::string& source, const std::string& target) {
 
 static status_t readMetadata(const std::string& path, std::string& fsType,
         std::string& fsUuid, std::string& fsLabel, bool untrusted) {
+#ifdef MINIVOLD
+    char *val = NULL;
+    val = blkid_get_tag_value(NULL, "TYPE", path.c_str());
+    if (val) {
+        fsType = val;
+    }
+    val = blkid_get_tag_value(NULL, "UUID", path.c_str());
+    if (val) {
+        fsUuid = val;
+    }
+    val = blkid_get_tag_value(NULL, "LABEL", path.c_str());
+    if (val) {
+        fsUuid = val;
+    }
+#else
     std::vector<std::string> cmd;
     cmd.push_back(kBlkidPath);
-#ifndef MINIVOLD
     cmd.push_back("-c");
     cmd.push_back("/dev/null");
     cmd.push_back("-s");
@@ -209,7 +223,6 @@ static status_t readMetadata(const std::string& path, std::string& fsType,
     cmd.push_back("UUID");
     cmd.push_back("-s");
     cmd.push_back("LABEL");
-#endif
     cmd.push_back(path);
 
     std::vector<std::string> output;
@@ -238,6 +251,7 @@ static status_t readMetadata(const std::string& path, std::string& fsType,
             fsLabel = value;
         }
     }
+#endif
 
     return OK;
 }