From 9b667fbe416363ff0cb7aeb58e67c9da5ad61a37 Mon Sep 17 00:00:00 2001 From: Daniel Rosenberg Date: Tue, 22 Jan 2019 17:27:25 -0800 Subject: [PATCH] Add supportsCheckpoint This returns true if any entries in the fstab have checkpoint= set. Test: Call vdc checkpoint supportsCheckpoint. Should return 1 iff an fstab entry has checkpoint=fs or checkpoint=block set Bug: 111020314 Change-Id: Ic79bc96ded4da6605f73992dcff542e7cb50d705 --- Checkpoint.cpp | 15 +++++++++++++++ Checkpoint.h | 2 ++ VoldNativeService.cpp | 7 +++++++ VoldNativeService.h | 1 + binder/android/os/IVold.aidl | 1 + vdc.cpp | 4 ++++ 6 files changed, 30 insertions(+) diff --git a/Checkpoint.cpp b/Checkpoint.cpp index 7586a6c..e06e855 100644 --- a/Checkpoint.cpp +++ b/Checkpoint.cpp @@ -67,6 +67,21 @@ bool setBowState(std::string const& block_device, std::string const& state) { } // namespace +Status cp_supportsCheckpoint(bool& result) { + result = false; + auto fstab_default = std::unique_ptr{ + fs_mgr_read_fstab_default(), fs_mgr_free_fstab}; + if (!fstab_default) return Status::fromExceptionCode(EINVAL, "Failed to get fstab"); + + for (int i = 0; i < fstab_default->num_entries; ++i) { + if (fs_mgr_is_checkpoint(&fstab_default->recs[i])) { + result = true; + return Status::ok(); + } + } + return Status::ok(); +} + Status cp_startCheckpoint(int retry) { if (retry < -1) return Status::fromExceptionCode(EINVAL, "Retry count must be more than -1"); std::string content = std::to_string(retry + 1); diff --git a/Checkpoint.h b/Checkpoint.h index eac2f94..64ceed3 100644 --- a/Checkpoint.h +++ b/Checkpoint.h @@ -23,6 +23,8 @@ namespace android { namespace vold { +android::binder::Status cp_supportsCheckpoint(bool& result); + android::binder::Status cp_startCheckpoint(int retry); android::binder::Status cp_commitChanges(); diff --git a/VoldNativeService.cpp b/VoldNativeService.cpp index c58ff01..1001d2b 100644 --- a/VoldNativeService.cpp +++ b/VoldNativeService.cpp @@ -864,5 +864,12 @@ binder::Status VoldNativeService::abortChanges() { return cp_abortChanges(); } +binder::Status VoldNativeService::supportsCheckpoint(bool* _aidl_return) { + ENFORCE_UID(AID_SYSTEM); + ACQUIRE_LOCK; + + return cp_supportsCheckpoint(*_aidl_return); +} + } // namespace vold } // namespace android diff --git a/VoldNativeService.h b/VoldNativeService.h index 161acb8..7db3e5c 100644 --- a/VoldNativeService.h +++ b/VoldNativeService.h @@ -129,6 +129,7 @@ class VoldNativeService : public BinderService, public os::Bn binder::Status restoreCheckpoint(const std::string& mountPoint); binder::Status markBootAttempt(); binder::Status abortChanges(); + binder::Status supportsCheckpoint(bool* _aidl_return); }; } // namespace vold diff --git a/binder/android/os/IVold.aidl b/binder/android/os/IVold.aidl index 976eab1..4b21078 100644 --- a/binder/android/os/IVold.aidl +++ b/binder/android/os/IVold.aidl @@ -104,6 +104,7 @@ interface IVold { void prepareCheckpoint(); void restoreCheckpoint(@utf8InCpp String device); void markBootAttempt(); + boolean supportsCheckpoint(); @utf8InCpp String createStubVolume(@utf8InCpp String sourcePath, @utf8InCpp String mountPath, @utf8InCpp String fsType, diff --git a/vdc.cpp b/vdc.cpp index e971d52..35775a7 100644 --- a/vdc.cpp +++ b/vdc.cpp @@ -105,6 +105,10 @@ int main(int argc, char** argv) { checkStatus(vold->mountFstab(args[2])); } else if (args[0] == "cryptfs" && args[1] == "encryptFstab" && args.size() == 3) { checkStatus(vold->encryptFstab(args[2])); + } else if (args[0] == "checkpoint" && args[1] == "supportsCheckpoint" && args.size() == 2) { + bool supported = false; + checkStatus(vold->supportsCheckpoint(&supported)); + return supported ? 1 : 0; } else if (args[0] == "checkpoint" && args[1] == "startCheckpoint" && args.size() == 3) { int retry; if (!android::base::ParseInt(args[2], &retry)) exit(EINVAL);