summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs_mgr/libdm/dm.cpp48
-rw-r--r--fs_mgr/libdm/dm_table.cpp11
-rw-r--r--fs_mgr/libdm/dm_target.cpp9
-rw-r--r--fs_mgr/libdm/include/libdm/dm.h (renamed from fs_mgr/libdm/include/dm.h)31
-rw-r--r--fs_mgr/libdm/include/libdm/dm_table.h (renamed from fs_mgr/libdm/include/dm_table.h)9
-rw-r--r--fs_mgr/libdm/include/libdm/dm_target.h (renamed from fs_mgr/libdm/include/dm_target.h)4
-rw-r--r--fs_mgr/tools/dmctl.cpp7
-rw-r--r--init/Android.bp52
-rw-r--r--init/mac_init_verifier.cpp19
-rw-r--r--shell_and_utilities/Android.bp37
-rw-r--r--shell_and_utilities/README.md4
11 files changed, 127 insertions, 104 deletions
diff --git a/fs_mgr/libdm/dm.cpp b/fs_mgr/libdm/dm.cpp
index e8bae60ef..5a2dfc67a 100644
--- a/fs_mgr/libdm/dm.cpp
+++ b/fs_mgr/libdm/dm.cpp
@@ -14,23 +14,12 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17#include <errno.h> 17#include "libdm/dm.h"
18#include <fcntl.h> 18
19#include <linux/dm-ioctl.h>
20#include <stdint.h>
21#include <sys/ioctl.h> 19#include <sys/ioctl.h>
22#include <sys/types.h> 20#include <sys/types.h>
23#include <unistd.h>
24
25#include <memory>
26#include <string>
27#include <vector>
28 21
29#include <android-base/logging.h>
30#include <android-base/macros.h> 22#include <android-base/macros.h>
31#include <android-base/unique_fd.h>
32
33#include "dm.h"
34 23
35namespace android { 24namespace android {
36namespace dm { 25namespace dm {
@@ -105,8 +94,37 @@ DmDeviceState DeviceMapper::state(const std::string& /* name */) const {
105 return DmDeviceState::INVALID; 94 return DmDeviceState::INVALID;
106} 95}
107 96
108bool DeviceMapper::LoadTableAndActivate(const std::string& /* name */, const DmTable& /* table */) { 97bool DeviceMapper::CreateDevice(const std::string& name, const DmTable& table) {
109 return false; 98 if (!CreateDevice(name)) {
99 return false;
100 }
101 if (!LoadTableAndActivate(name, table)) {
102 DeleteDevice(name);
103 return false;
104 }
105 return true;
106}
107
108bool DeviceMapper::LoadTableAndActivate(const std::string& name, const DmTable& table) {
109 std::string ioctl_buffer(sizeof(struct dm_ioctl), 0);
110 ioctl_buffer += table.Serialize();
111
112 struct dm_ioctl* io = reinterpret_cast<struct dm_ioctl*>(&ioctl_buffer[0]);
113 InitIo(io, name);
114 io->data_size = ioctl_buffer.size();
115 io->data_start = sizeof(struct dm_ioctl);
116 io->target_count = static_cast<uint32_t>(table.num_targets());
117 if (ioctl(fd_, DM_TABLE_LOAD, io)) {
118 PLOG(ERROR) << "DM_TABLE_LOAD failed";
119 return false;
120 }
121
122 InitIo(io, name);
123 if (ioctl(fd_, DM_DEV_SUSPEND, io)) {
124 PLOG(ERROR) << "DM_TABLE_SUSPEND resume failed";
125 return false;
126 }
127 return true;
110} 128}
111 129
112// Reads all the available device mapper targets and their corresponding 130// Reads all the available device mapper targets and their corresponding
diff --git a/fs_mgr/libdm/dm_table.cpp b/fs_mgr/libdm/dm_table.cpp
index 14b393297..868286e22 100644
--- a/fs_mgr/libdm/dm_table.cpp
+++ b/fs_mgr/libdm/dm_table.cpp
@@ -14,14 +14,11 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17#include "libdm/dm_table.h"
18
17#include <android-base/logging.h> 19#include <android-base/logging.h>
18#include <android-base/macros.h> 20#include <android-base/macros.h>
19 21
20#include <string>
21#include <vector>
22
23#include "dm_table.h"
24
25namespace android { 22namespace android {
26namespace dm { 23namespace dm {
27 24
@@ -37,8 +34,8 @@ bool DmTable::valid() const {
37 return true; 34 return true;
38} 35}
39 36
40uint64_t DmTable::size() const { 37uint64_t DmTable::num_sectors() const {
41 return valid() ? size_ : 0; 38 return valid() ? num_sectors_ : 0;
42} 39}
43 40
44// Returns a string represnetation of the table that is ready to be passed 41// Returns a string represnetation of the table that is ready to be passed
diff --git a/fs_mgr/libdm/dm_target.cpp b/fs_mgr/libdm/dm_target.cpp
index 8bcd5262a..dbe4fede1 100644
--- a/fs_mgr/libdm/dm_target.cpp
+++ b/fs_mgr/libdm/dm_target.cpp
@@ -14,16 +14,11 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17#include "libdm/dm_target.h"
18
17#include <android-base/logging.h> 19#include <android-base/logging.h>
18#include <android-base/macros.h> 20#include <android-base/macros.h>
19 21
20#include <stdint.h>
21
22#include <string>
23#include <vector>
24
25#include "dm_target.h"
26
27namespace android { 22namespace android {
28namespace dm {} // namespace dm 23namespace dm {} // namespace dm
29} // namespace android 24} // namespace android
diff --git a/fs_mgr/libdm/include/dm.h b/fs_mgr/libdm/include/libdm/dm.h
index 52a9a111a..840777499 100644
--- a/fs_mgr/libdm/include/dm.h
+++ b/fs_mgr/libdm/include/libdm/dm.h
@@ -17,18 +17,20 @@
17#ifndef _LIBDM_DM_H_ 17#ifndef _LIBDM_DM_H_
18#define _LIBDM_DM_H_ 18#define _LIBDM_DM_H_
19 19
20#include <errno.h>
21#include <fcntl.h> 20#include <fcntl.h>
22#include <linux/dm-ioctl.h> 21#include <linux/dm-ioctl.h>
23#include <linux/kdev_t.h> 22#include <linux/kdev_t.h>
23#include <stdint.h>
24#include <sys/sysmacros.h> 24#include <sys/sysmacros.h>
25#include <unistd.h> 25#include <unistd.h>
26 26
27#include <memory> 27#include <memory>
28#include <string>
29#include <vector>
28 30
29#include <android-base/logging.h> 31#include <android-base/logging.h>
30 32
31#include <dm_table.h> 33#include "dm_table.h"
32 34
33// The minimum expected device mapper major.minor version 35// The minimum expected device mapper major.minor version
34#define DM_VERSION0 (4) 36#define DM_VERSION0 (4)
@@ -67,14 +69,6 @@ class DeviceMapper final {
67 uint64_t dev_; 69 uint64_t dev_;
68 }; 70 };
69 71
70 // Creates a device mapper device with given name.
71 // Return 'true' on success and 'false' on failure to
72 // create OR if a device mapper device with the same name already
73 // exists.
74 // TODO(b/110035986): Make this method private and to be only
75 // called through LoadTableAndActivate() below.
76 bool CreateDevice(const std::string& name);
77
78 // Removes a device mapper device with the given name. 72 // Removes a device mapper device with the given name.
79 // Returns 'true' on success, false otherwise. 73 // Returns 'true' on success, false otherwise.
80 bool DeleteDevice(const std::string& name); 74 bool DeleteDevice(const std::string& name);
@@ -88,9 +82,14 @@ class DeviceMapper final {
88 // One of INVALID, SUSPENDED or ACTIVE. 82 // One of INVALID, SUSPENDED or ACTIVE.
89 DmDeviceState state(const std::string& name) const; 83 DmDeviceState state(const std::string& name) const;
90 84
91 // Loads the device mapper table from parameter into the underlying 85 // Creates a device, loads the given table, and activates it. If the device
92 // device mapper device with given name and activate / resumes the device in the process. 86 // is not able to be activated, it is destroyed, and false is returned.
93 // If a device mapper device with the 'name', doesn't exist, it will be created. 87 bool CreateDevice(const std::string& name, const DmTable& table);
88
89 // Loads the device mapper table from parameter into the underlying device
90 // mapper device with given name and activate / resumes the device in the
91 // process. A device with the given name must already exist.
92 //
94 // Returns 'true' on success, false otherwise. 93 // Returns 'true' on success, false otherwise.
95 bool LoadTableAndActivate(const std::string& name, const DmTable& table); 94 bool LoadTableAndActivate(const std::string& name, const DmTable& table);
96 95
@@ -138,6 +137,12 @@ class DeviceMapper final {
138 } 137 }
139 } 138 }
140 139
140 // Creates a device mapper device with given name.
141 // Return 'true' on success and 'false' on failure to
142 // create OR if a device mapper device with the same name already
143 // exists.
144 bool CreateDevice(const std::string& name);
145
141 int fd_; 146 int fd_;
142 // Non-copyable & Non-movable 147 // Non-copyable & Non-movable
143 DeviceMapper(const DeviceMapper&) = delete; 148 DeviceMapper(const DeviceMapper&) = delete;
diff --git a/fs_mgr/libdm/include/dm_table.h b/fs_mgr/libdm/include/libdm/dm_table.h
index 0b1685db0..8a5c62400 100644
--- a/fs_mgr/libdm/include/dm_table.h
+++ b/fs_mgr/libdm/include/libdm/dm_table.h
@@ -30,7 +30,7 @@ namespace dm {
30 30
31class DmTable { 31class DmTable {
32 public: 32 public:
33 DmTable() : size_(0){}; 33 DmTable() : num_sectors_(0){};
34 34
35 // Adds a target to the device mapper table for a range specified in the target object. 35 // Adds a target to the device mapper table for a range specified in the target object.
36 // The function will return 'true' if the target was successfully added and doesn't overlap with 36 // The function will return 'true' if the target was successfully added and doesn't overlap with
@@ -48,9 +48,12 @@ class DmTable {
48 // table is malformed. 48 // table is malformed.
49 bool valid() const; 49 bool valid() const;
50 50
51 // Returns the toatl number of targets.
52 size_t num_targets() const { return targets_.size(); }
53
51 // Returns the total size represented by the table in terms of number of 512-byte sectors. 54 // Returns the total size represented by the table in terms of number of 512-byte sectors.
52 // NOTE: This function will overlook if there are any gaps in the targets added in the table. 55 // NOTE: This function will overlook if there are any gaps in the targets added in the table.
53 uint64_t size() const; 56 uint64_t num_sectors() const;
54 57
55 // Returns the string represntation of the table that is ready to be passed into the kernel 58 // Returns the string represntation of the table that is ready to be passed into the kernel
56 // as part of the DM_TABLE_LOAD ioctl. 59 // as part of the DM_TABLE_LOAD ioctl.
@@ -66,7 +69,7 @@ class DmTable {
66 69
67 // Total size in terms of # of sectors, as calculated by looking at the last and the first 70 // Total size in terms of # of sectors, as calculated by looking at the last and the first
68 // target in 'target_'. 71 // target in 'target_'.
69 uint64_t size_; 72 uint64_t num_sectors_;
70}; 73};
71 74
72} // namespace dm 75} // namespace dm
diff --git a/fs_mgr/libdm/include/dm_target.h b/fs_mgr/libdm/include/libdm/dm_target.h
index 31b0cb69c..e3058a87d 100644
--- a/fs_mgr/libdm/include/dm_target.h
+++ b/fs_mgr/libdm/include/libdm/dm_target.h
@@ -20,10 +20,10 @@
20#include <linux/dm-ioctl.h> 20#include <linux/dm-ioctl.h>
21#include <stdint.h> 21#include <stdint.h>
22 22
23#include <android-base/logging.h>
24
25#include <string> 23#include <string>
26 24
25#include <android-base/logging.h>
26
27namespace android { 27namespace android {
28namespace dm { 28namespace dm {
29 29
diff --git a/fs_mgr/tools/dmctl.cpp b/fs_mgr/tools/dmctl.cpp
index e82c71872..d637dc67c 100644
--- a/fs_mgr/tools/dmctl.cpp
+++ b/fs_mgr/tools/dmctl.cpp
@@ -23,7 +23,7 @@
23#include <unistd.h> 23#include <unistd.h>
24 24
25#include <android-base/unique_fd.h> 25#include <android-base/unique_fd.h>
26#include <dm.h> 26#include <libdm/dm.h>
27 27
28#include <functional> 28#include <functional>
29#include <iomanip> 29#include <iomanip>
@@ -34,6 +34,7 @@
34#include <vector> 34#include <vector>
35 35
36using DeviceMapper = ::android::dm::DeviceMapper; 36using DeviceMapper = ::android::dm::DeviceMapper;
37using DmTable = ::android::dm::DmTable;
37using DmTarget = ::android::dm::DmTarget; 38using DmTarget = ::android::dm::DmTarget;
38using DmBlockDevice = ::android::dm::DeviceMapper::DmBlockDevice; 39using DmBlockDevice = ::android::dm::DeviceMapper::DmBlockDevice;
39 40
@@ -53,9 +54,11 @@ static int DmCreateCmdHandler(int argc, char** argv) {
53 return -EINVAL; 54 return -EINVAL;
54 } 55 }
55 56
57 DmTable table;
58
56 std::string name = argv[0]; 59 std::string name = argv[0];
57 DeviceMapper& dm = DeviceMapper::Instance(); 60 DeviceMapper& dm = DeviceMapper::Instance();
58 if (!dm.CreateDevice(name)) { 61 if (!dm.CreateDevice(name, table)) {
59 std::cerr << "Failed to create device-mapper device with name: " << name << std::endl; 62 std::cerr << "Failed to create device-mapper device with name: " << name << std::endl;
60 return -EIO; 63 return -EIO;
61 } 64 }
diff --git a/init/Android.bp b/init/Android.bp
index da0895f94..cf7637f96 100644
--- a/init/Android.bp
+++ b/init/Android.bp
@@ -227,41 +227,39 @@ cc_binary {
227 "liblog", 227 "liblog",
228 "libcutils", 228 "libcutils",
229 ], 229 ],
230 srcs: [
231 "action.cpp",
232 "action_manager.cpp",
233 "action_parser.cpp",
234 "capabilities.cpp",
235 "descriptors.cpp",
236 "epoll.cpp",
237 "keychords.cpp",
238 "import_parser.cpp",
239 "host_import_parser.cpp",
240 "host_init_verifier.cpp",
241 "host_init_stubs.cpp",
242 "parser.cpp",
243 "rlimit_parser.cpp",
244 "tokenizer.cpp",
245 "service.cpp",
246 "subcontext.cpp",
247 "subcontext.proto",
248 "util.cpp",
249 ],
230 proto: { 250 proto: {
231 type: "lite", 251 type: "lite",
232 }, 252 },
253 generated_headers: [
254 "generated_stub_builtin_function_map",
255 "generated_android_ids"
256 ],
233 target: { 257 target: {
234 linux: {
235 srcs: [
236 "action.cpp",
237 "action_manager.cpp",
238 "action_parser.cpp",
239 "capabilities.cpp",
240 "descriptors.cpp",
241 "epoll.cpp",
242 "keychords.cpp",
243 "import_parser.cpp",
244 "host_import_parser.cpp",
245 "host_init_verifier.cpp",
246 "host_init_stubs.cpp",
247 "parser.cpp",
248 "rlimit_parser.cpp",
249 "tokenizer.cpp",
250 "service.cpp",
251 "subcontext.cpp",
252 "subcontext.proto",
253 "util.cpp",
254 ],
255 generated_headers: [
256 "generated_stub_builtin_function_map",
257 "generated_android_ids",
258 ],
259 },
260 android: { 258 android: {
261 enabled: false, 259 enabled: false,
262 }, 260 },
263 darwin: { 261 darwin: {
264 srcs: ["mac_init_verifier.cpp"], 262 enabled: false,
265 }, 263 },
266 }, 264 },
267} 265}
diff --git a/init/mac_init_verifier.cpp b/init/mac_init_verifier.cpp
deleted file mode 100644
index 646509e1e..000000000
--- a/init/mac_init_verifier.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
1//
2// Copyright (C) 2018 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
17int main() {
18 return 0;
19}
diff --git a/shell_and_utilities/Android.bp b/shell_and_utilities/Android.bp
index dfb88f74d..7834dd50c 100644
--- a/shell_and_utilities/Android.bp
+++ b/shell_and_utilities/Android.bp
@@ -1,25 +1,46 @@
1phony { 1phony {
2 name: "shell_and_utilities", 2 name: "shell_and_utilities",
3 required: [ 3 required: [
4 "shell_and_utilities_system",
5 "shell_and_utilities_recovery",
6 "shell_and_utilities_vendor",
7 ],
8}
9
10phony {
11 name: "shell_and_utilities_system",
12 required: [
4 "awk", 13 "awk",
5 "awk_vendor",
6 "bzip2", 14 "bzip2",
7 "grep", 15 "grep",
8 "grep_vendor",
9 "logwrapper", 16 "logwrapper",
10 "logwrapper_vendor",
11 "mkshrc", 17 "mkshrc",
12 "mkshrc_vendor",
13 "newfs_msdos", 18 "newfs_msdos",
14 "reboot", 19 "reboot",
15 "sh", 20 "sh",
16 "sh.recovery",
17 "sh_vendor",
18 "toolbox", 21 "toolbox",
19 "toolbox.recovery",
20 "toolbox_vendor",
21 "toybox", 22 "toybox",
23 ],
24}
25
26phony {
27 name: "shell_and_utilities_recovery",
28 required: [
29 "sh.recovery",
30 "toolbox.recovery",
22 "toybox.recovery", 31 "toybox.recovery",
32 ],
33}
34
35phony {
36 name: "shell_and_utilities_vendor",
37 required: [
38 "awk_vendor",
39 "grep_vendor",
40 "logwrapper_vendor",
41 "mkshrc_vendor",
42 "sh_vendor",
43 "toolbox_vendor",
23 "toybox_vendor", 44 "toybox_vendor",
24 ], 45 ],
25} 46}
diff --git a/shell_and_utilities/README.md b/shell_and_utilities/README.md
index b15be1fd4..e310e6b9b 100644
--- a/shell_and_utilities/README.md
+++ b/shell_and_utilities/README.md
@@ -193,13 +193,15 @@ which whoami xargs xxd yes zcat
193Android Q 193Android Q
194--------- 194---------
195 195
196BSD: fsck\_msdos newfs\_msdos
197
196bzip2: bzcat bzip2 bunzip2 198bzip2: bzcat bzip2 bunzip2
197 199
198one-true-awk: awk 200one-true-awk: awk
199 201
200PCRE: egrep fgrep grep 202PCRE: egrep fgrep grep
201 203
202toolbox: getevent getprop newfs\_msdos 204toolbox: getevent getprop
203 205
204toybox: acpi base64 basename blockdev cal cat chcon chgrp chmod chown 206toybox: acpi base64 basename blockdev cal cat chcon chgrp chmod chown
205chroot chrt cksum clear cmp comm cp cpio cut date dd df diff dirname 207chroot chrt cksum clear cmp comm cp cpio cut date dd df diff dirname