blob: 427ab7c2845d03e200245ee12fb0189de908b6d8 [file] [log] [blame]
Bowgo Tsaid79dd842019-01-08 17:05:48 +08001/*
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>
Bowgo Tsaiacaa95d2019-12-06 11:44:18 +080021#include <vector>
Bowgo Tsaid79dd842019-01-08 17:05:48 +080022
23#ifdef HOST_TEST
24#include <base/logging.h>
25#else
26#include <android-base/logging.h>
27#endif
28
Bowgo Tsaiacaa95d2019-12-06 11:44:18 +080029#include <android-base/result.h>
30
31using android::base::ErrnoError;
32using android::base::Result;
33
Bowgo Tsaid79dd842019-01-08 17:05:48 +080034#define FS_AVB_TAG "[libfs_avb]"
35
36// Logs a message to kernel
37#define LINFO LOG(INFO) << FS_AVB_TAG
38#define LWARNING LOG(WARNING) << FS_AVB_TAG
39#define LERROR LOG(ERROR) << FS_AVB_TAG
40#define LFATAL LOG(FATAL) << FS_AVB_TAG
41
42// Logs a message with strerror(errno) at the end
43#define PINFO PLOG(INFO) << FS_AVB_TAG
44#define PWARNING PLOG(WARNING) << FS_AVB_TAG
45#define PERROR PLOG(ERROR) << FS_AVB_TAG
46#define PFATAL PLOG(FATAL) << FS_AVB_TAG
47
48extern bool fs_mgr_get_boot_config(const std::string& key, std::string* out_val);
49
50using namespace std::chrono_literals;
51
52namespace android {
53namespace fs_mgr {
54
55bool NibbleValue(const char& c, uint8_t* value);
56
57bool HexToBytes(uint8_t* bytes, size_t bytes_len, const std::string& hex);
58
59std::string BytesToHex(const uint8_t* bytes, size_t bytes_len);
60
Yifan Hong402633d2019-04-09 10:11:34 -070061enum class FileWaitMode { Exists, DoesNotExist };
62bool WaitForFile(const std::string& filename, const std::chrono::milliseconds relative_timeout,
63 FileWaitMode wait_mode = FileWaitMode::Exists);
Bowgo Tsaid79dd842019-01-08 17:05:48 +080064
65bool IsDeviceUnlocked();
66
67bool SetBlockDeviceReadOnly(const std::string& blockdev);
68
Bowgo Tsaiacaa95d2019-12-06 11:44:18 +080069// Returns a list of file under the dir, no order is guaranteed.
70Result<std::vector<std::string>> ListFiles(const std::string& dir);
71
Bowgo Tsaid79dd842019-01-08 17:05:48 +080072} // namespace fs_mgr
73} // namespace android