OSDN Git Service

[incremental] use vold to mount/unmount IncrementalFileSystem
authorSongchun Fan <schfan@google.com>
Mon, 2 Dec 2019 18:50:12 +0000 (10:50 -0800)
committerSongchun Fan <schfan@google.com>
Wed, 4 Dec 2019 22:01:22 +0000 (14:01 -0800)
Let vold mount IncFs onto directories under data and open control files.

Test: builds
Change-Id: Ibd96aae254b4fefaf56c9d549c4672a987c46221

Android.bp
VoldNativeService.cpp
VoldNativeService.h
binder/android/os/IVold.aidl

index 452746c..8d88e5f 100644 (file)
@@ -54,6 +54,7 @@ cc_defaults {
         "libf2fs_sparseblock",
         "libhardware",
         "libhardware_legacy",
+        "libincfs",
         "libhidlbase",
         "libkeymaster4support",
         "libkeyutils",
@@ -78,9 +79,15 @@ cc_library_static {
     ],
     aidl: {
         local_include_dirs: ["binder"],
-        include_dirs: ["frameworks/native/aidl/binder"],
+        include_dirs: [
+            "frameworks/native/aidl/binder",
+            "frameworks/base/core/java/android/os/incremental",
+        ],
         export_aidl_headers: true,
     },
+    whole_static_libs: [
+        "libincremental_aidl-cpp",
+    ],
 }
 
 cc_library_headers {
index f17f59f..cc32820 100644 (file)
@@ -28,6 +28,7 @@
 #include "FsCrypt.h"
 #include "MetadataCrypt.h"
 #include "cryptfs.h"
+#include "incfs_ndk.h"
 
 #include <fstream>
 #include <thread>
@@ -915,5 +916,38 @@ binder::Status VoldNativeService::resetCheckpoint() {
     return ok();
 }
 
+binder::Status VoldNativeService::incFsVersion(int32_t* _aidl_return) {
+    *_aidl_return = IncFs_Version();
+    return ok();
+}
+
+binder::Status VoldNativeService::mountIncFs(
+        const std::string& imagePath, const std::string& targetDir, int32_t flags,
+        ::android::os::incremental::IncrementalFileSystemControlParcel* _aidl_return) {
+    auto result = IncFs_Mount(imagePath.c_str(), targetDir.c_str(), flags,
+                              INCFS_DEFAULT_READ_TIMEOUT_MS, 0777);
+    if (result.cmdFd < 0) {
+        return translate(result.cmdFd);
+    }
+    LOG(INFO) << "VoldNativeService::mountIncFs: everything is fine! " << result.cmdFd << "/"
+              << result.logFd;
+    using ParcelFileDescriptor = ::android::os::ParcelFileDescriptor;
+    using unique_fd = ::android::base::unique_fd;
+    _aidl_return->cmd = std::make_unique<ParcelFileDescriptor>(unique_fd(result.cmdFd));
+    if (result.logFd >= 0) {
+        _aidl_return->log = std::make_unique<ParcelFileDescriptor>(unique_fd(result.logFd));
+    }
+    return ok();
+}
+
+binder::Status VoldNativeService::unmountIncFs(const std::string& dir) {
+    return translate(IncFs_Unmount(dir.c_str()));
+}
+
+binder::Status VoldNativeService::bindMount(const std::string& sourceDir,
+                                            const std::string& targetDir) {
+    return translate(IncFs_BindMount(sourceDir.c_str(), targetDir.c_str()));
+}
+
 }  // namespace vold
 }  // namespace android
index 13137c5..0718263 100644 (file)
@@ -141,6 +141,13 @@ class VoldNativeService : public BinderService<VoldNativeService>, public os::Bn
     binder::Status supportsBlockCheckpoint(bool* _aidl_return);
     binder::Status supportsFileCheckpoint(bool* _aidl_return);
     binder::Status resetCheckpoint();
+
+    binder::Status incFsVersion(int32_t* _aidl_return) override;
+    binder::Status mountIncFs(
+            const std::string& imagePath, const std::string& targetDir, int32_t flags,
+            ::android::os::incremental::IncrementalFileSystemControlParcel* _aidl_return) override;
+    binder::Status unmountIncFs(const std::string& dir) override;
+    binder::Status bindMount(const std::string& sourceDir, const std::string& targetDir) override;
 };
 
 }  // namespace vold
index 8e5c53d..681e9dc 100644 (file)
@@ -16,6 +16,7 @@
 
 package android.os;
 
+import android.os.incremental.IncrementalFileSystemControlParcel;
 import android.os.IVoldListener;
 import android.os.IVoldTaskListener;
 
@@ -125,6 +126,11 @@ interface IVold {
 
     FileDescriptor openAppFuseFile(int uid, int mountId, int fileId, int flags);
 
+    int incFsVersion();
+    IncrementalFileSystemControlParcel mountIncFs(@utf8InCpp String imagePath, @utf8InCpp String targetDir, int flags);
+    void unmountIncFs(@utf8InCpp String dir);
+    void bindMount(@utf8InCpp String sourceDir, @utf8InCpp String targetDir);
+
     const int ENCRYPTION_FLAG_NO_UI = 4;
 
     const int ENCRYPTION_STATE_NONE = 1;