Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5f82055a authored by Mark Salyzyn's avatar Mark Salyzyn Committed by android-build-merger
Browse files

Merge "libcutils: convert fs_config.cpp" am: c50245e4

am: a255ab0c

Change-Id: Ife5d12b9f4d3924b3903d91cd09e6592f4ee08b8
parents eed955d7 a255ab0c
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ cc_library {
    host_supported: true,
    srcs: [
        "config_utils.c",
        "fs_config.c",
        "fs_config.cpp",
        "canned_fs_config.c",
        "hashmap.c",
        "iosched_policy.c",
@@ -94,6 +94,9 @@ cc_library {
            shared: {
                enabled: false,
            },
            cflags: [
                "-D_GNU_SOURCE",
            ],
        },

        android: {
+44 −49
Original line number Diff line number Diff line
@@ -14,15 +14,12 @@
 * limitations under the License.
 */

/* This file is used to define the properties of the filesystem
** images generated by build tools (mkbootfs and mkyaffs2image) and
** by the device side of adb.
*/
// This file is used to define the properties of the filesystem
// images generated by build tools (mkbootfs and mkyaffs2image) and
// by the device side of adb.

#define LOG_TAG "fs_config"

#define _GNU_SOURCE

#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
@@ -42,8 +39,10 @@
#define O_BINARY 0
#endif

/* My kingdom for <endian.h> */
static inline uint16_t get2LE(const uint8_t* src) { return src[0] | (src[1] << 8); }
// My kingdom for <endian.h>
static inline uint16_t get2LE(const uint8_t* src) {
    return src[0] | (src[1] << 8);
}

static inline uint64_t get8LE(const uint8_t* src) {
    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))

/* Rules for directories.
** These rules are applied based on "first match", so they
** should start with the most specific path and work their
** way up to the root.
*/
// Rules for directories.
// These rules are applied based on "first match", so they
// should start with the most specific path and work their
// way up to the root.

static const struct fs_path_config android_dirs[] = {
    /* clang-format off */
    // clang-format off
    { 00770, AID_SYSTEM,       AID_CACHE,        0, "cache" },
    { 00500, AID_ROOT,         AID_ROOT,         0, "config" },
    { 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, "vendor" },
    { 00755, AID_ROOT,         AID_ROOT,         0, 0 },
    /* clang-format on */
    // clang-format on
};

/* Rules for files.
** These rules are applied based on "first match", so they
** should start with the most specific path and work their
** way up to the root. Prefixes ending in * denotes wildcard
** and will allow partial matches.
*/
// Rules for files.
// These rules are applied based on "first match", so they
// should start with the most specific path and work their
// way up to the root. Prefixes ending in * denotes wildcard
// and will allow partial matches.
static const char sys_conf_dir[] = "/system/etc/fs_config_dirs";
static const char sys_conf_file[] = "/system/etc/fs_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
 * 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
 * customization can also land on /system/vendor, /system/oem or /system/odm.
 * We expect build-time checking or filtering when constructing the associated
 * fs_config_* files (see build/tools/fs_config/fs_config_generate.c)
 */
// 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
// 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
// customization can also land on /system/vendor, /system/oem or /system/odm.
// We expect build-time checking or filtering when constructing the associated
// 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_file[] = "/vendor/etc/fs_config_files";
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[] = {
    /* clang-format off */
    // clang-format off
    { 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-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_file + 1 },

    /* the following two files are INTENTIONALLY set-uid, but they
     * are NOT included on user builds. */
    // the following two files are INTENTIONALLY set-uid, but they
    // are NOT included on user builds.
    { 06755, AID_ROOT,      AID_ROOT,      0, "system/xbin/procmem" },
    { 04750, AID_ROOT,      AID_SHELL,     0, "system/xbin/su" },

    /* the following files have enhanced capabilities and ARE included
     * in user builds. */
    // the following files have enhanced capabilities and ARE included
    // in user builds.
    { 00700, AID_SYSTEM,    AID_SHELL,     CAP_MASK_LONG(CAP_BLOCK_SUSPEND),
                                              "system/bin/inputflinger" },
    { 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),
                                              "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),
                                              "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) |
                                           CAP_MASK_LONG(CAP_NET_RAW),
                                              "system/bin/hostapd" },

    /* Support Bluetooth legacy hal accessing /sys/class/rfkill
     * Support RT scheduling in Bluetooth */
    // Support Bluetooth legacy hal accessing /sys/class/rfkill
    // Support RT scheduling in Bluetooth
    { 00700, AID_BLUETOOTH, AID_BLUETOOTH, CAP_MASK_LONG(CAP_NET_ADMIN) |
                                           CAP_MASK_LONG(CAP_SYS_NICE),
                                              "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),
                                              "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) |
                                           CAP_MASK_LONG(CAP_NET_RAW),
                                              "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),
                                              "vendor/bin/hw/android.hardware.wifi@1.0-service" },

    /* A non-privileged zygote that spawns
     * isolated processes for web rendering. */
    // A non-privileged zygote that spawns isolated processes for web rendering.
    { 0750,  AID_ROOT,      AID_ROOT,      CAP_MASK_LONG(CAP_SETUID) |
                                           CAP_MASK_LONG(CAP_SETGID) |
                                           CAP_MASK_LONG(CAP_SETPCAP),
@@ -227,7 +222,7 @@ static const struct fs_path_config android_files[] = {
                                           CAP_MASK_LONG(CAP_SETPCAP),
                                              "system/bin/webview_zygote64" },

    /* generic defaults */
    // generic defaults
    { 00755, AID_ROOT,      AID_ROOT,      0, "bin/*" },
    { 00640, AID_ROOT,      AID_SHELL,     0, "fstab.*" },
    { 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/xbin/*" },
    { 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[]) {
@@ -254,9 +249,9 @@ static int fs_config_open(int dir, int which, const char* target_out_path) {
    int fd = -1;

    if (target_out_path && *target_out_path) {
        /* target_out_path is the path to the directory holding content of
         * system partition but as we cannot guarantee it ends with '/system'
         * or with or without a trailing slash, need to strip them carefully. */
        // target_out_path is the path to the directory holding content of
        // system partition but as we cannot guarantee it ends with '/system'
        // or with or without a trailing slash, need to strip them carefully.
        char* name = NULL;
        size_t len = strlen(target_out_path);
        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;
        }
    } else {
        /* If name ends in * then allow partial matches. */
        // If name ends in * then allow partial matches.
        if (prefix[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]);
                break;
            }
            prefix = calloc(1, remainder);
            prefix = static_cast<char*>(calloc(1, remainder));
            if (!prefix) {
                ALOGE("%s out of memory", conf[which][dir]);
                break;
@@ -325,7 +320,7 @@ void fs_config(const char* path, int dir, const char* target_out_path, unsigned*
                break;
            }
            len = strnlen(prefix, remainder);
            if (len >= remainder) { /* missing a terminating null */
            if (len >= remainder) {  // missing a terminating null
                free(prefix);
                ALOGE("%s is corrupted", conf[which][dir]);
                break;