diff options
author | Mark Salyzyn | 2017-05-02 10:56:15 -0500 |
---|---|---|
committer | Mark Salyzyn | 2017-05-03 10:04:35 -0500 |
commit | 163ecc68c7a7ee06a384880fec0d05d303812a4e (patch) | |
tree | ad606f2d47fb000b5e4205a979391d5c337db29e | |
parent | 0447a3e5d1591b0a232106534ca0463bac5346dc (diff) | |
download | platform-system-core-163ecc68c7a7ee06a384880fec0d05d303812a4e.tar.gz platform-system-core-163ecc68c7a7ee06a384880fec0d05d303812a4e.tar.xz platform-system-core-163ecc68c7a7ee06a384880fec0d05d303812a4e.zip |
libcutils: convert fs_config.cpp
C++ify fs_config.c
Test: gTest libcutils-test
Bug: 37703469
Change-Id: Id48ae22f203ed923942257575296c69b32345ae6
-rw-r--r-- | libcutils/Android.bp | 5 | ||||
-rw-r--r-- | libcutils/fs_config.cpp (renamed from libcutils/fs_config.c) | 93 |
2 files changed, 48 insertions, 50 deletions
diff --git a/libcutils/Android.bp b/libcutils/Android.bp index 58170ec71..245deb113 100644 --- a/libcutils/Android.bp +++ b/libcutils/Android.bp | |||
@@ -53,7 +53,7 @@ cc_library { | |||
53 | host_supported: true, | 53 | host_supported: true, |
54 | srcs: [ | 54 | srcs: [ |
55 | "config_utils.c", | 55 | "config_utils.c", |
56 | "fs_config.c", | 56 | "fs_config.cpp", |
57 | "canned_fs_config.c", | 57 | "canned_fs_config.c", |
58 | "hashmap.c", | 58 | "hashmap.c", |
59 | "iosched_policy.c", | 59 | "iosched_policy.c", |
@@ -94,6 +94,9 @@ cc_library { | |||
94 | shared: { | 94 | shared: { |
95 | enabled: false, | 95 | enabled: false, |
96 | }, | 96 | }, |
97 | cflags: [ | ||
98 | "-D_GNU_SOURCE", | ||
99 | ], | ||
97 | }, | 100 | }, |
98 | 101 | ||
99 | android: { | 102 | android: { |
diff --git a/libcutils/fs_config.c b/libcutils/fs_config.cpp index e4541f787..a2dd67776 100644 --- a/libcutils/fs_config.c +++ b/libcutils/fs_config.cpp | |||
@@ -14,15 +14,12 @@ | |||
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | /* This file is used to define the properties of the filesystem | 17 | // This file is used to define the properties of the filesystem |
18 | ** images generated by build tools (mkbootfs and mkyaffs2image) and | 18 | // images generated by build tools (mkbootfs and mkyaffs2image) and |
19 | ** by the device side of adb. | 19 | // by the device side of adb. |
20 | */ | ||
21 | 20 | ||
22 | #define LOG_TAG "fs_config" | 21 | #define LOG_TAG "fs_config" |
23 | 22 | ||
24 | #define _GNU_SOURCE | ||
25 | |||
26 | #include <errno.h> | 23 | #include <errno.h> |
27 | #include <fcntl.h> | 24 | #include <fcntl.h> |
28 | #include <stdbool.h> | 25 | #include <stdbool.h> |
@@ -42,8 +39,10 @@ | |||
42 | #define O_BINARY 0 | 39 | #define O_BINARY 0 |
43 | #endif | 40 | #endif |
44 | 41 | ||
45 | /* My kingdom for <endian.h> */ | 42 | // My kingdom for <endian.h> |
46 | static inline uint16_t get2LE(const uint8_t* src) { return src[0] | (src[1] << 8); } | 43 | static inline uint16_t get2LE(const uint8_t* src) { |
44 | return src[0] | (src[1] << 8); | ||
45 | } | ||
47 | 46 | ||
48 | static inline uint64_t get8LE(const uint8_t* src) { | 47 | static inline uint64_t get8LE(const uint8_t* src) { |
49 | uint32_t low, high; | 48 | uint32_t low, high; |
@@ -55,14 +54,13 @@ static inline uint64_t get8LE(const uint8_t* src) { | |||
55 | 54 | ||
56 | #define ALIGN(x, alignment) (((x) + ((alignment)-1)) & ~((alignment)-1)) | 55 | #define ALIGN(x, alignment) (((x) + ((alignment)-1)) & ~((alignment)-1)) |
57 | 56 | ||
58 | /* Rules for directories. | 57 | // Rules for directories. |
59 | ** These rules are applied based on "first match", so they | 58 | // These rules are applied based on "first match", so they |
60 | ** should start with the most specific path and work their | 59 | // should start with the most specific path and work their |
61 | ** way up to the root. | 60 | // way up to the root. |
62 | */ | ||
63 | 61 | ||
64 | static const struct fs_path_config android_dirs[] = { | 62 | static const struct fs_path_config android_dirs[] = { |
65 | /* clang-format off */ | 63 | // clang-format off |
66 | { 00770, AID_SYSTEM, AID_CACHE, 0, "cache" }, | 64 | { 00770, AID_SYSTEM, AID_CACHE, 0, "cache" }, |
67 | { 00500, AID_ROOT, AID_ROOT, 0, "config" }, | 65 | { 00500, AID_ROOT, AID_ROOT, 0, "config" }, |
68 | { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app" }, | 66 | { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app" }, |
@@ -92,25 +90,23 @@ static const struct fs_path_config android_dirs[] = { | |||
92 | { 00755, AID_ROOT, AID_SHELL, 0, "system/xbin" }, | 90 | { 00755, AID_ROOT, AID_SHELL, 0, "system/xbin" }, |
93 | { 00755, AID_ROOT, AID_SHELL, 0, "vendor" }, | 91 | { 00755, AID_ROOT, AID_SHELL, 0, "vendor" }, |
94 | { 00755, AID_ROOT, AID_ROOT, 0, 0 }, | 92 | { 00755, AID_ROOT, AID_ROOT, 0, 0 }, |
95 | /* clang-format on */ | 93 | // clang-format on |
96 | }; | 94 | }; |
97 | 95 | ||
98 | /* Rules for files. | 96 | // Rules for files. |
99 | ** These rules are applied based on "first match", so they | 97 | // These rules are applied based on "first match", so they |
100 | ** should start with the most specific path and work their | 98 | // should start with the most specific path and work their |
101 | ** way up to the root. Prefixes ending in * denotes wildcard | 99 | // way up to the root. Prefixes ending in * denotes wildcard |
102 | ** and will allow partial matches. | 100 | // and will allow partial matches. |
103 | */ | ||
104 | static const char sys_conf_dir[] = "/system/etc/fs_config_dirs"; | 101 | static const char sys_conf_dir[] = "/system/etc/fs_config_dirs"; |
105 | static const char sys_conf_file[] = "/system/etc/fs_config_files"; | 102 | static const char sys_conf_file[] = "/system/etc/fs_config_files"; |
106 | /* No restrictions are placed on the vendor and oem file-system config files, | 103 | // No restrictions are placed on the vendor and oem file-system config files, |
107 | * although the developer is advised to restrict the scope to the /vendor or | 104 | // although the developer is advised to restrict the scope to the /vendor or |
108 | * oem/ file-system since the intent is to provide support for customized | 105 | // oem/ file-system since the intent is to provide support for customized |
109 | * portions of a separate vendor.img or oem.img. Has to remain open so that | 106 | // portions of a separate vendor.img or oem.img. Has to remain open so that |
110 | * customization can also land on /system/vendor, /system/oem or /system/odm. | 107 | // customization can also land on /system/vendor, /system/oem or /system/odm. |
111 | * We expect build-time checking or filtering when constructing the associated | 108 | // We expect build-time checking or filtering when constructing the associated |
112 | * fs_config_* files (see build/tools/fs_config/fs_config_generate.c) | 109 | // fs_config_* files (see build/tools/fs_config/fs_config_generate.c) |
113 | */ | ||
114 | static const char ven_conf_dir[] = "/vendor/etc/fs_config_dirs"; | 110 | static const char ven_conf_dir[] = "/vendor/etc/fs_config_dirs"; |
115 | static const char ven_conf_file[] = "/vendor/etc/fs_config_files"; | 111 | static const char ven_conf_file[] = "/vendor/etc/fs_config_files"; |
116 | static const char oem_conf_dir[] = "/oem/etc/fs_config_dirs"; | 112 | static const char oem_conf_dir[] = "/oem/etc/fs_config_dirs"; |
@@ -125,7 +121,7 @@ static const char* conf[][2] = { | |||
125 | }; | 121 | }; |
126 | 122 | ||
127 | static const struct fs_path_config android_files[] = { | 123 | static const struct fs_path_config android_files[] = { |
128 | /* clang-format off */ | 124 | // clang-format off |
129 | { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app/*" }, | 125 | { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app/*" }, |
130 | { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app-ephemeral/*" }, | 126 | { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app-ephemeral/*" }, |
131 | { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app-private/*" }, | 127 | { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app-private/*" }, |
@@ -173,13 +169,13 @@ static const struct fs_path_config android_files[] = { | |||
173 | { 00444, AID_ROOT, AID_ROOT, 0, ven_conf_dir + 1 }, | 169 | { 00444, AID_ROOT, AID_ROOT, 0, ven_conf_dir + 1 }, |
174 | { 00444, AID_ROOT, AID_ROOT, 0, ven_conf_file + 1 }, | 170 | { 00444, AID_ROOT, AID_ROOT, 0, ven_conf_file + 1 }, |
175 | 171 | ||
176 | /* the following two files are INTENTIONALLY set-uid, but they | 172 | // the following two files are INTENTIONALLY set-uid, but they |
177 | * are NOT included on user builds. */ | 173 | // are NOT included on user builds. |
178 | { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procmem" }, | 174 | { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procmem" }, |
179 | { 04750, AID_ROOT, AID_SHELL, 0, "system/xbin/su" }, | 175 | { 04750, AID_ROOT, AID_SHELL, 0, "system/xbin/su" }, |
180 | 176 | ||
181 | /* the following files have enhanced capabilities and ARE included | 177 | // the following files have enhanced capabilities and ARE included |
182 | * in user builds. */ | 178 | // in user builds. |
183 | { 00700, AID_SYSTEM, AID_SHELL, CAP_MASK_LONG(CAP_BLOCK_SUSPEND), | 179 | { 00700, AID_SYSTEM, AID_SHELL, CAP_MASK_LONG(CAP_BLOCK_SUSPEND), |
184 | "system/bin/inputflinger" }, | 180 | "system/bin/inputflinger" }, |
185 | { 00550, AID_LOGD, AID_LOGD, CAP_MASK_LONG(CAP_SYSLOG) | | 181 | { 00550, AID_LOGD, AID_LOGD, CAP_MASK_LONG(CAP_SYSLOG) | |
@@ -190,17 +186,17 @@ static const struct fs_path_config android_files[] = { | |||
190 | CAP_MASK_LONG(CAP_SETGID), | 186 | CAP_MASK_LONG(CAP_SETGID), |
191 | "system/bin/run-as" }, | 187 | "system/bin/run-as" }, |
192 | 188 | ||
193 | /* Support FIFO scheduling mode in SurfaceFlinger. */ | 189 | // Support FIFO scheduling mode in SurfaceFlinger. |
194 | { 00755, AID_SYSTEM, AID_GRAPHICS, CAP_MASK_LONG(CAP_SYS_NICE), | 190 | { 00755, AID_SYSTEM, AID_GRAPHICS, CAP_MASK_LONG(CAP_SYS_NICE), |
195 | "system/bin/surfaceflinger" }, | 191 | "system/bin/surfaceflinger" }, |
196 | 192 | ||
197 | /* Support hostapd administering a network interface. */ | 193 | // Support hostapd administering a network interface. |
198 | { 00755, AID_WIFI, AID_WIFI, CAP_MASK_LONG(CAP_NET_ADMIN) | | 194 | { 00755, AID_WIFI, AID_WIFI, CAP_MASK_LONG(CAP_NET_ADMIN) | |
199 | CAP_MASK_LONG(CAP_NET_RAW), | 195 | CAP_MASK_LONG(CAP_NET_RAW), |
200 | "system/bin/hostapd" }, | 196 | "system/bin/hostapd" }, |
201 | 197 | ||
202 | /* Support Bluetooth legacy hal accessing /sys/class/rfkill | 198 | // Support Bluetooth legacy hal accessing /sys/class/rfkill |
203 | * Support RT scheduling in Bluetooth */ | 199 | // Support RT scheduling in Bluetooth |
204 | { 00700, AID_BLUETOOTH, AID_BLUETOOTH, CAP_MASK_LONG(CAP_NET_ADMIN) | | 200 | { 00700, AID_BLUETOOTH, AID_BLUETOOTH, CAP_MASK_LONG(CAP_NET_ADMIN) | |
205 | CAP_MASK_LONG(CAP_SYS_NICE), | 201 | CAP_MASK_LONG(CAP_SYS_NICE), |
206 | "system/vendor/bin/hw/android.hardware.bluetooth@1.0-service" }, | 202 | "system/vendor/bin/hw/android.hardware.bluetooth@1.0-service" }, |
@@ -208,7 +204,7 @@ static const struct fs_path_config android_files[] = { | |||
208 | CAP_MASK_LONG(CAP_SYS_NICE), | 204 | CAP_MASK_LONG(CAP_SYS_NICE), |
209 | "vendor/bin/hw/android.hardware.bluetooth@1.0-service" }, | 205 | "vendor/bin/hw/android.hardware.bluetooth@1.0-service" }, |
210 | 206 | ||
211 | /* Support wifi_hal_legacy administering a network interface. */ | 207 | // Support wifi_hal_legacy administering a network interface. |
212 | { 00755, AID_WIFI, AID_WIFI, CAP_MASK_LONG(CAP_NET_ADMIN) | | 208 | { 00755, AID_WIFI, AID_WIFI, CAP_MASK_LONG(CAP_NET_ADMIN) | |
213 | CAP_MASK_LONG(CAP_NET_RAW), | 209 | CAP_MASK_LONG(CAP_NET_RAW), |
214 | "system/vendor/bin/hw/android.hardware.wifi@1.0-service" }, | 210 | "system/vendor/bin/hw/android.hardware.wifi@1.0-service" }, |
@@ -216,8 +212,7 @@ static const struct fs_path_config android_files[] = { | |||
216 | CAP_MASK_LONG(CAP_NET_RAW), | 212 | CAP_MASK_LONG(CAP_NET_RAW), |
217 | "vendor/bin/hw/android.hardware.wifi@1.0-service" }, | 213 | "vendor/bin/hw/android.hardware.wifi@1.0-service" }, |
218 | 214 | ||
219 | /* A non-privileged zygote that spawns | 215 | // A non-privileged zygote that spawns isolated processes for web rendering. |
220 | * isolated processes for web rendering. */ | ||
221 | { 0750, AID_ROOT, AID_ROOT, CAP_MASK_LONG(CAP_SETUID) | | 216 | { 0750, AID_ROOT, AID_ROOT, CAP_MASK_LONG(CAP_SETUID) | |
222 | CAP_MASK_LONG(CAP_SETGID) | | 217 | CAP_MASK_LONG(CAP_SETGID) | |
223 | CAP_MASK_LONG(CAP_SETPCAP), | 218 | CAP_MASK_LONG(CAP_SETPCAP), |
@@ -227,7 +222,7 @@ static const struct fs_path_config android_files[] = { | |||
227 | CAP_MASK_LONG(CAP_SETPCAP), | 222 | CAP_MASK_LONG(CAP_SETPCAP), |
228 | "system/bin/webview_zygote64" }, | 223 | "system/bin/webview_zygote64" }, |
229 | 224 | ||
230 | /* generic defaults */ | 225 | // generic defaults |
231 | { 00755, AID_ROOT, AID_ROOT, 0, "bin/*" }, | 226 | { 00755, AID_ROOT, AID_ROOT, 0, "bin/*" }, |
232 | { 00640, AID_ROOT, AID_SHELL, 0, "fstab.*" }, | 227 | { 00640, AID_ROOT, AID_SHELL, 0, "fstab.*" }, |
233 | { 00750, AID_ROOT, AID_SHELL, 0, "init*" }, | 228 | { 00750, AID_ROOT, AID_SHELL, 0, "init*" }, |
@@ -241,7 +236,7 @@ static const struct fs_path_config android_files[] = { | |||
241 | { 00755, AID_ROOT, AID_SHELL, 0, "vendor/bin/*" }, | 236 | { 00755, AID_ROOT, AID_SHELL, 0, "vendor/bin/*" }, |
242 | { 00755, AID_ROOT, AID_SHELL, 0, "vendor/xbin/*" }, | 237 | { 00755, AID_ROOT, AID_SHELL, 0, "vendor/xbin/*" }, |
243 | { 00644, AID_ROOT, AID_ROOT, 0, 0 }, | 238 | { 00644, AID_ROOT, AID_ROOT, 0, 0 }, |
244 | /* clang-format on */ | 239 | // clang-format on |
245 | }; | 240 | }; |
246 | 241 | ||
247 | static size_t strip(const char* path, size_t len, const char suffix[]) { | 242 | static size_t strip(const char* path, size_t len, const char suffix[]) { |
@@ -254,9 +249,9 @@ static int fs_config_open(int dir, int which, const char* target_out_path) { | |||
254 | int fd = -1; | 249 | int fd = -1; |
255 | 250 | ||
256 | if (target_out_path && *target_out_path) { | 251 | if (target_out_path && *target_out_path) { |
257 | /* target_out_path is the path to the directory holding content of | 252 | // target_out_path is the path to the directory holding content of |
258 | * system partition but as we cannot guarantee it ends with '/system' | 253 | // system partition but as we cannot guarantee it ends with '/system' |
259 | * or with or without a trailing slash, need to strip them carefully. */ | 254 | // or with or without a trailing slash, need to strip them carefully. |
260 | char* name = NULL; | 255 | char* name = NULL; |
261 | size_t len = strlen(target_out_path); | 256 | size_t len = strlen(target_out_path); |
262 | len = strip(target_out_path, len, "/"); | 257 | len = strip(target_out_path, len, "/"); |
@@ -278,7 +273,7 @@ static bool fs_config_cmp(bool dir, const char* prefix, size_t len, const char* | |||
278 | return false; | 273 | return false; |
279 | } | 274 | } |
280 | } else { | 275 | } else { |
281 | /* If name ends in * then allow partial matches. */ | 276 | // If name ends in * then allow partial matches. |
282 | if (prefix[len - 1] == '*') { | 277 | if (prefix[len - 1] == '*') { |
283 | return !strncmp(prefix, path, len - 1); | 278 | return !strncmp(prefix, path, len - 1); |
284 | } | 279 | } |
@@ -314,7 +309,7 @@ void fs_config(const char* path, int dir, const char* target_out_path, unsigned* | |||
314 | ALOGE("%s len is corrupted", conf[which][dir]); | 309 | ALOGE("%s len is corrupted", conf[which][dir]); |
315 | break; | 310 | break; |
316 | } | 311 | } |
317 | prefix = calloc(1, remainder); | 312 | prefix = static_cast<char*>(calloc(1, remainder)); |
318 | if (!prefix) { | 313 | if (!prefix) { |
319 | ALOGE("%s out of memory", conf[which][dir]); | 314 | ALOGE("%s out of memory", conf[which][dir]); |
320 | break; | 315 | break; |
@@ -325,7 +320,7 @@ void fs_config(const char* path, int dir, const char* target_out_path, unsigned* | |||
325 | break; | 320 | break; |
326 | } | 321 | } |
327 | len = strnlen(prefix, remainder); | 322 | len = strnlen(prefix, remainder); |
328 | if (len >= remainder) { /* missing a terminating null */ | 323 | if (len >= remainder) { // missing a terminating null |
329 | free(prefix); | 324 | free(prefix); |
330 | ALOGE("%s is corrupted", conf[which][dir]); | 325 | ALOGE("%s is corrupted", conf[which][dir]); |
331 | break; | 326 | break; |