• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 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 #ifndef _INIT_UTIL_H_
18 #define _INIT_UTIL_H_
19 
20 #include <sys/stat.h>
21 #include <sys/types.h>
22 
23 #include <chrono>
24 #include <functional>
25 #include <ostream>
26 #include <string>
27 
28 #include <android-base/chrono_utils.h>
29 #include <selinux/label.h>
30 
31 #include "result.h"
32 
33 #define COLDBOOT_DONE "/dev/.coldboot_done"
34 
35 using android::base::boot_clock;
36 using namespace std::chrono_literals;
37 
38 namespace android {
39 namespace init {
40 
41 int CreateSocket(const char* name, int type, bool passcred, mode_t perm, uid_t uid, gid_t gid,
42                  const char* socketcon);
43 
44 Result<std::string> ReadFile(const std::string& path);
45 Result<Success> WriteFile(const std::string& path, const std::string& content);
46 
47 Result<uid_t> DecodeUid(const std::string& name);
48 
49 bool mkdir_recursive(const std::string& pathname, mode_t mode);
50 int wait_for_file(const char *filename, std::chrono::nanoseconds timeout);
51 void import_kernel_cmdline(bool in_qemu,
52                            const std::function<void(const std::string&, const std::string&, bool)>&);
53 bool make_dir(const std::string& path, mode_t mode);
54 bool is_dir(const char* pathname);
55 bool expand_props(const std::string& src, std::string* dst);
56 
57 // Returns the platform's Android DT directory as specified in the kernel cmdline.
58 // If the platform does not configure a custom DT path, returns the standard one (based in procfs).
59 const std::string& get_android_dt_dir();
60 // Reads or compares the content of device tree file under the platform's Android DT directory.
61 bool read_android_dt_file(const std::string& sub_path, std::string* dt_content);
62 bool is_android_dt_value_expected(const std::string& sub_path, const std::string& expected_content);
63 
64 bool IsLegalPropertyName(const std::string& name);
65 
66 void SetStdioToDevNull(char** argv);
67 void InitKernelLogging(char** argv);
68 bool IsRecoveryMode();
69 }  // namespace init
70 }  // namespace android
71 
72 #endif
73