Merge "libcutils: convert fs_config.cpp"

am: c50245e43e

Change-Id: I0681d0477f9782b0616ee65d8996db716541caab
This commit is contained in:
Mark Salyzyn 2017-05-03 16:52:39 +00:00 committed by android-build-merger
commit a255ab0cb0
2 changed files with 48 additions and 50 deletions

View file

@ -53,7 +53,7 @@ cc_library {
host_supported: true, host_supported: true,
srcs: [ srcs: [
"config_utils.c", "config_utils.c",
"fs_config.c", "fs_config.cpp",
"canned_fs_config.c", "canned_fs_config.c",
"hashmap.c", "hashmap.c",
"iosched_policy.c", "iosched_policy.c",
@ -94,6 +94,9 @@ cc_library {
shared: { shared: {
enabled: false, enabled: false,
}, },
cflags: [
"-D_GNU_SOURCE",
],
}, },
android: { android: {

View file

@ -14,15 +14,12 @@
* limitations under the License. * limitations under the License.
*/ */
/* This file is used to define the properties of the filesystem // This file is used to define the properties of the filesystem
** images generated by build tools (mkbootfs and mkyaffs2image) and // images generated by build tools (mkbootfs and mkyaffs2image) and
** by the device side of adb. // by the device side of adb.
*/
#define LOG_TAG "fs_config" #define LOG_TAG "fs_config"
#define _GNU_SOURCE
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdbool.h> #include <stdbool.h>
@ -42,8 +39,10 @@
#define O_BINARY 0 #define O_BINARY 0
#endif #endif
/* My kingdom for <endian.h> */ // My kingdom for <endian.h>
static inline uint16_t get2LE(const uint8_t* src) { return src[0] | (src[1] << 8); } static inline uint16_t get2LE(const uint8_t* src) {
return src[0] | (src[1] << 8);
}
static inline uint64_t get8LE(const uint8_t* src) { static inline uint64_t get8LE(const uint8_t* src) {
uint32_t low, high; uint32_t low, high;
@ -55,14 +54,13 @@ static inline uint64_t get8LE(const uint8_t* src) {
#define ALIGN(x, alignment) (((x) + ((alignment)-1)) & ~((alignment)-1)) #define ALIGN(x, alignment) (((x) + ((alignment)-1)) & ~((alignment)-1))
/* Rules for directories. // Rules for directories.
** These rules are applied based on "first match", so they // These rules are applied based on "first match", so they
** should start with the most specific path and work their // should start with the most specific path and work their
** way up to the root. // way up to the root.
*/
static const struct fs_path_config android_dirs[] = { static const struct fs_path_config android_dirs[] = {
/* clang-format off */ // clang-format off
{ 00770, AID_SYSTEM, AID_CACHE, 0, "cache" }, { 00770, AID_SYSTEM, AID_CACHE, 0, "cache" },
{ 00500, AID_ROOT, AID_ROOT, 0, "config" }, { 00500, AID_ROOT, AID_ROOT, 0, "config" },
{ 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app" }, { 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app" },
@ -92,25 +90,23 @@ static const struct fs_path_config android_dirs[] = {
{ 00755, AID_ROOT, AID_SHELL, 0, "system/xbin" }, { 00755, AID_ROOT, AID_SHELL, 0, "system/xbin" },
{ 00755, AID_ROOT, AID_SHELL, 0, "vendor" }, { 00755, AID_ROOT, AID_SHELL, 0, "vendor" },
{ 00755, AID_ROOT, AID_ROOT, 0, 0 }, { 00755, AID_ROOT, AID_ROOT, 0, 0 },
/* clang-format on */ // clang-format on
}; };
/* Rules for files. // Rules for files.
** These rules are applied based on "first match", so they // These rules are applied based on "first match", so they
** should start with the most specific path and work their // should start with the most specific path and work their
** way up to the root. Prefixes ending in * denotes wildcard // way up to the root. Prefixes ending in * denotes wildcard
** and will allow partial matches. // and will allow partial matches.
*/
static const char sys_conf_dir[] = "/system/etc/fs_config_dirs"; static const char sys_conf_dir[] = "/system/etc/fs_config_dirs";
static const char sys_conf_file[] = "/system/etc/fs_config_files"; static const char sys_conf_file[] = "/system/etc/fs_config_files";
/* No restrictions are placed on the vendor and oem file-system config files, // No restrictions are placed on the vendor and oem file-system config files,
* although the developer is advised to restrict the scope to the /vendor or // although the developer is advised to restrict the scope to the /vendor or
* oem/ file-system since the intent is to provide support for customized // oem/ file-system since the intent is to provide support for customized
* portions of a separate vendor.img or oem.img. Has to remain open so that // portions of a separate vendor.img or oem.img. Has to remain open so that
* customization can also land on /system/vendor, /system/oem or /system/odm. // customization can also land on /system/vendor, /system/oem or /system/odm.
* We expect build-time checking or filtering when constructing the associated // We expect build-time checking or filtering when constructing the associated
* fs_config_* files (see build/tools/fs_config/fs_config_generate.c) // fs_config_* files (see build/tools/fs_config/fs_config_generate.c)
*/
static const char ven_conf_dir[] = "/vendor/etc/fs_config_dirs"; static const char ven_conf_dir[] = "/vendor/etc/fs_config_dirs";
static const char ven_conf_file[] = "/vendor/etc/fs_config_files"; static const char ven_conf_file[] = "/vendor/etc/fs_config_files";
static const char oem_conf_dir[] = "/oem/etc/fs_config_dirs"; static const char oem_conf_dir[] = "/oem/etc/fs_config_dirs";
@ -125,7 +121,7 @@ static const char* conf[][2] = {
}; };
static const struct fs_path_config android_files[] = { static const struct fs_path_config android_files[] = {
/* clang-format off */ // clang-format off
{ 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app/*" }, { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app/*" },
{ 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app-ephemeral/*" }, { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app-ephemeral/*" },
{ 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app-private/*" }, { 00644, AID_SYSTEM, AID_SYSTEM, 0, "data/app-private/*" },
@ -173,13 +169,13 @@ static const struct fs_path_config android_files[] = {
{ 00444, AID_ROOT, AID_ROOT, 0, ven_conf_dir + 1 }, { 00444, AID_ROOT, AID_ROOT, 0, ven_conf_dir + 1 },
{ 00444, AID_ROOT, AID_ROOT, 0, ven_conf_file + 1 }, { 00444, AID_ROOT, AID_ROOT, 0, ven_conf_file + 1 },
/* the following two files are INTENTIONALLY set-uid, but they // the following two files are INTENTIONALLY set-uid, but they
* are NOT included on user builds. */ // are NOT included on user builds.
{ 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procmem" }, { 06755, AID_ROOT, AID_ROOT, 0, "system/xbin/procmem" },
{ 04750, AID_ROOT, AID_SHELL, 0, "system/xbin/su" }, { 04750, AID_ROOT, AID_SHELL, 0, "system/xbin/su" },
/* the following files have enhanced capabilities and ARE included // the following files have enhanced capabilities and ARE included
* in user builds. */ // in user builds.
{ 00700, AID_SYSTEM, AID_SHELL, CAP_MASK_LONG(CAP_BLOCK_SUSPEND), { 00700, AID_SYSTEM, AID_SHELL, CAP_MASK_LONG(CAP_BLOCK_SUSPEND),
"system/bin/inputflinger" }, "system/bin/inputflinger" },
{ 00550, AID_LOGD, AID_LOGD, CAP_MASK_LONG(CAP_SYSLOG) | { 00550, AID_LOGD, AID_LOGD, CAP_MASK_LONG(CAP_SYSLOG) |
@ -190,17 +186,17 @@ static const struct fs_path_config android_files[] = {
CAP_MASK_LONG(CAP_SETGID), CAP_MASK_LONG(CAP_SETGID),
"system/bin/run-as" }, "system/bin/run-as" },
/* Support FIFO scheduling mode in SurfaceFlinger. */ // Support FIFO scheduling mode in SurfaceFlinger.
{ 00755, AID_SYSTEM, AID_GRAPHICS, CAP_MASK_LONG(CAP_SYS_NICE), { 00755, AID_SYSTEM, AID_GRAPHICS, CAP_MASK_LONG(CAP_SYS_NICE),
"system/bin/surfaceflinger" }, "system/bin/surfaceflinger" },
/* Support hostapd administering a network interface. */ // Support hostapd administering a network interface.
{ 00755, AID_WIFI, AID_WIFI, CAP_MASK_LONG(CAP_NET_ADMIN) | { 00755, AID_WIFI, AID_WIFI, CAP_MASK_LONG(CAP_NET_ADMIN) |
CAP_MASK_LONG(CAP_NET_RAW), CAP_MASK_LONG(CAP_NET_RAW),
"system/bin/hostapd" }, "system/bin/hostapd" },
/* Support Bluetooth legacy hal accessing /sys/class/rfkill // Support Bluetooth legacy hal accessing /sys/class/rfkill
* Support RT scheduling in Bluetooth */ // Support RT scheduling in Bluetooth
{ 00700, AID_BLUETOOTH, AID_BLUETOOTH, CAP_MASK_LONG(CAP_NET_ADMIN) | { 00700, AID_BLUETOOTH, AID_BLUETOOTH, CAP_MASK_LONG(CAP_NET_ADMIN) |
CAP_MASK_LONG(CAP_SYS_NICE), CAP_MASK_LONG(CAP_SYS_NICE),
"system/vendor/bin/hw/android.hardware.bluetooth@1.0-service" }, "system/vendor/bin/hw/android.hardware.bluetooth@1.0-service" },
@ -208,7 +204,7 @@ static const struct fs_path_config android_files[] = {
CAP_MASK_LONG(CAP_SYS_NICE), CAP_MASK_LONG(CAP_SYS_NICE),
"vendor/bin/hw/android.hardware.bluetooth@1.0-service" }, "vendor/bin/hw/android.hardware.bluetooth@1.0-service" },
/* Support wifi_hal_legacy administering a network interface. */ // Support wifi_hal_legacy administering a network interface.
{ 00755, AID_WIFI, AID_WIFI, CAP_MASK_LONG(CAP_NET_ADMIN) | { 00755, AID_WIFI, AID_WIFI, CAP_MASK_LONG(CAP_NET_ADMIN) |
CAP_MASK_LONG(CAP_NET_RAW), CAP_MASK_LONG(CAP_NET_RAW),
"system/vendor/bin/hw/android.hardware.wifi@1.0-service" }, "system/vendor/bin/hw/android.hardware.wifi@1.0-service" },
@ -216,8 +212,7 @@ static const struct fs_path_config android_files[] = {
CAP_MASK_LONG(CAP_NET_RAW), CAP_MASK_LONG(CAP_NET_RAW),
"vendor/bin/hw/android.hardware.wifi@1.0-service" }, "vendor/bin/hw/android.hardware.wifi@1.0-service" },
/* A non-privileged zygote that spawns // A non-privileged zygote that spawns isolated processes for web rendering.
* isolated processes for web rendering. */
{ 0750, AID_ROOT, AID_ROOT, CAP_MASK_LONG(CAP_SETUID) | { 0750, AID_ROOT, AID_ROOT, CAP_MASK_LONG(CAP_SETUID) |
CAP_MASK_LONG(CAP_SETGID) | CAP_MASK_LONG(CAP_SETGID) |
CAP_MASK_LONG(CAP_SETPCAP), CAP_MASK_LONG(CAP_SETPCAP),
@ -227,7 +222,7 @@ static const struct fs_path_config android_files[] = {
CAP_MASK_LONG(CAP_SETPCAP), CAP_MASK_LONG(CAP_SETPCAP),
"system/bin/webview_zygote64" }, "system/bin/webview_zygote64" },
/* generic defaults */ // generic defaults
{ 00755, AID_ROOT, AID_ROOT, 0, "bin/*" }, { 00755, AID_ROOT, AID_ROOT, 0, "bin/*" },
{ 00640, AID_ROOT, AID_SHELL, 0, "fstab.*" }, { 00640, AID_ROOT, AID_SHELL, 0, "fstab.*" },
{ 00750, AID_ROOT, AID_SHELL, 0, "init*" }, { 00750, AID_ROOT, AID_SHELL, 0, "init*" },
@ -241,7 +236,7 @@ static const struct fs_path_config android_files[] = {
{ 00755, AID_ROOT, AID_SHELL, 0, "vendor/bin/*" }, { 00755, AID_ROOT, AID_SHELL, 0, "vendor/bin/*" },
{ 00755, AID_ROOT, AID_SHELL, 0, "vendor/xbin/*" }, { 00755, AID_ROOT, AID_SHELL, 0, "vendor/xbin/*" },
{ 00644, AID_ROOT, AID_ROOT, 0, 0 }, { 00644, AID_ROOT, AID_ROOT, 0, 0 },
/* clang-format on */ // clang-format on
}; };
static size_t strip(const char* path, size_t len, const char suffix[]) { 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) {
int fd = -1; int fd = -1;
if (target_out_path && *target_out_path) { if (target_out_path && *target_out_path) {
/* target_out_path is the path to the directory holding content of // target_out_path is the path to the directory holding content of
* system partition but as we cannot guarantee it ends with '/system' // system partition but as we cannot guarantee it ends with '/system'
* or with or without a trailing slash, need to strip them carefully. */ // or with or without a trailing slash, need to strip them carefully.
char* name = NULL; char* name = NULL;
size_t len = strlen(target_out_path); size_t len = strlen(target_out_path);
len = strip(target_out_path, len, "/"); 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*
return false; return false;
} }
} else { } else {
/* If name ends in * then allow partial matches. */ // If name ends in * then allow partial matches.
if (prefix[len - 1] == '*') { if (prefix[len - 1] == '*') {
return !strncmp(prefix, path, len - 1); return !strncmp(prefix, path, len - 1);
} }
@ -314,7 +309,7 @@ void fs_config(const char* path, int dir, const char* target_out_path, unsigned*
ALOGE("%s len is corrupted", conf[which][dir]); ALOGE("%s len is corrupted", conf[which][dir]);
break; break;
} }
prefix = calloc(1, remainder); prefix = static_cast<char*>(calloc(1, remainder));
if (!prefix) { if (!prefix) {
ALOGE("%s out of memory", conf[which][dir]); ALOGE("%s out of memory", conf[which][dir]);
break; break;
@ -325,7 +320,7 @@ void fs_config(const char* path, int dir, const char* target_out_path, unsigned*
break; break;
} }
len = strnlen(prefix, remainder); len = strnlen(prefix, remainder);
if (len >= remainder) { /* missing a terminating null */ if (len >= remainder) { // missing a terminating null
free(prefix); free(prefix);
ALOGE("%s is corrupted", conf[which][dir]); ALOGE("%s is corrupted", conf[which][dir]);
break; break;