• 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 #pragma once
18 
19 #include <sys/stat.h>
20 #include <sys/types.h>
21 
22 #include <chrono>
23 #include <functional>
24 #include <string>
25 #include <vector>
26 
27 #include <android-base/chrono_utils.h>
28 
29 #include "fscrypt_init_extensions.h"
30 #include "result.h"
31 
32 using android::base::boot_clock;
33 
34 namespace android {
35 namespace init {
36 
37 enum mount_mode {
38     MOUNT_MODE_DEFAULT = 0,
39     MOUNT_MODE_EARLY = 1,
40     MOUNT_MODE_LATE = 2,
41 };
42 
43 static const char kColdBootDoneProp[] = "ro.cold_boot_done";
44 
45 extern void (*trigger_shutdown)(const std::string& command);
46 
47 Result<int> CreateSocket(const std::string& name, int type, bool passcred, mode_t perm, uid_t uid,
48                          gid_t gid, const std::string& socketcon);
49 
50 Result<std::string> ReadFile(const std::string& path);
51 Result<void> WriteFile(const std::string& path, const std::string& content);
52 
53 Result<uid_t> DecodeUid(const std::string& name);
54 
55 bool mkdir_recursive(const std::string& pathname, mode_t mode);
56 int wait_for_file(const char *filename, std::chrono::nanoseconds timeout);
57 void ImportKernelCmdline(const std::function<void(const std::string&, const std::string&)>&);
58 void ImportBootconfig(const std::function<void(const std::string&, const std::string&)>&);
59 bool make_dir(const std::string& path, mode_t mode);
60 bool is_dir(const char* pathname);
61 Result<std::string> ExpandProps(const std::string& src);
62 
63 // Returns the platform's Android DT directory as specified in the kernel cmdline.
64 // If the platform does not configure a custom DT path, returns the standard one (based in procfs).
65 const std::string& get_android_dt_dir();
66 // Reads or compares the content of device tree file under the platform's Android DT directory.
67 bool read_android_dt_file(const std::string& sub_path, std::string* dt_content);
68 bool is_android_dt_value_expected(const std::string& sub_path, const std::string& expected_content);
69 
70 bool IsLegalPropertyName(const std::string& name);
71 Result<void> IsLegalPropertyValue(const std::string& name, const std::string& value);
72 
73 struct MkdirOptions {
74     std::string target;
75     mode_t mode;
76     uid_t uid;
77     gid_t gid;
78     FscryptAction fscrypt_action;
79     std::string ref_option;
80 };
81 
82 Result<MkdirOptions> ParseMkdir(const std::vector<std::string>& args);
83 
84 struct MountAllOptions {
85     std::vector<std::string> rc_paths;
86     std::string fstab_path;
87     mount_mode mode;
88     bool import_rc;
89 };
90 
91 Result<MountAllOptions> ParseMountAll(const std::vector<std::string>& args);
92 
93 Result<std::pair<int, std::vector<std::string>>> ParseRestorecon(
94         const std::vector<std::string>& args);
95 
96 Result<std::string> ParseSwaponAll(const std::vector<std::string>& args);
97 
98 Result<std::string> ParseUmountAll(const std::vector<std::string>& args);
99 
100 void SetStdioToDevNull(char** argv);
101 void InitKernelLogging(char** argv);
102 bool IsRecoveryMode();
103 
104 bool IsDefaultMountNamespaceReady();
105 void SetDefaultMountNamespaceReady();
106 }  // namespace init
107 }  // namespace android
108