• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #pragma once
18 
19 #include <chrono>
20 #include <string>
21 
22 #ifdef HOST_TEST
23 #include <base/logging.h>
24 #else
25 #include <android-base/logging.h>
26 #endif
27 
28 #define FS_AVB_TAG "[libfs_avb]"
29 
30 // Logs a message to kernel
31 #define LINFO LOG(INFO) << FS_AVB_TAG
32 #define LWARNING LOG(WARNING) << FS_AVB_TAG
33 #define LERROR LOG(ERROR) << FS_AVB_TAG
34 #define LFATAL LOG(FATAL) << FS_AVB_TAG
35 
36 // Logs a message with strerror(errno) at the end
37 #define PINFO PLOG(INFO) << FS_AVB_TAG
38 #define PWARNING PLOG(WARNING) << FS_AVB_TAG
39 #define PERROR PLOG(ERROR) << FS_AVB_TAG
40 #define PFATAL PLOG(FATAL) << FS_AVB_TAG
41 
42 extern bool fs_mgr_get_boot_config(const std::string& key, std::string* out_val);
43 
44 using namespace std::chrono_literals;
45 
46 namespace android {
47 namespace fs_mgr {
48 
49 bool NibbleValue(const char& c, uint8_t* value);
50 
51 bool HexToBytes(uint8_t* bytes, size_t bytes_len, const std::string& hex);
52 
53 std::string BytesToHex(const uint8_t* bytes, size_t bytes_len);
54 
55 enum class FileWaitMode { Exists, DoesNotExist };
56 bool WaitForFile(const std::string& filename, const std::chrono::milliseconds relative_timeout,
57                  FileWaitMode wait_mode = FileWaitMode::Exists);
58 
59 bool IsDeviceUnlocked();
60 
61 bool SetBlockDeviceReadOnly(const std::string& blockdev);
62 
63 }  // namespace fs_mgr
64 }  // namespace android
65