util.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (C) 2019 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #pragma once
  17. #include <chrono>
  18. #include <string>
  19. #ifdef HOST_TEST
  20. #include <base/logging.h>
  21. #else
  22. #include <android-base/logging.h>
  23. #endif
  24. #define FS_AVB_TAG "[libfs_avb]"
  25. // Logs a message to kernel
  26. #define LINFO LOG(INFO) << FS_AVB_TAG
  27. #define LWARNING LOG(WARNING) << FS_AVB_TAG
  28. #define LERROR LOG(ERROR) << FS_AVB_TAG
  29. #define LFATAL LOG(FATAL) << FS_AVB_TAG
  30. // Logs a message with strerror(errno) at the end
  31. #define PINFO PLOG(INFO) << FS_AVB_TAG
  32. #define PWARNING PLOG(WARNING) << FS_AVB_TAG
  33. #define PERROR PLOG(ERROR) << FS_AVB_TAG
  34. #define PFATAL PLOG(FATAL) << FS_AVB_TAG
  35. extern bool fs_mgr_get_boot_config(const std::string& key, std::string* out_val);
  36. using namespace std::chrono_literals;
  37. namespace android {
  38. namespace fs_mgr {
  39. bool NibbleValue(const char& c, uint8_t* value);
  40. bool HexToBytes(uint8_t* bytes, size_t bytes_len, const std::string& hex);
  41. std::string BytesToHex(const uint8_t* bytes, size_t bytes_len);
  42. enum class FileWaitMode { Exists, DoesNotExist };
  43. bool WaitForFile(const std::string& filename, const std::chrono::milliseconds relative_timeout,
  44. FileWaitMode wait_mode = FileWaitMode::Exists);
  45. bool IsDeviceUnlocked();
  46. bool SetBlockDeviceReadOnly(const std::string& blockdev);
  47. } // namespace fs_mgr
  48. } // namespace android