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

Commit 96126069 authored by Yi-Yo Chiang's avatar Yi-Yo Chiang
Browse files

fs_mgr: Split libfs_mgr and libfstab

The goal is to make the header definitions of the two curiously
intertwined libraries less chaotic.

After this change, libfstab's header would be self contained. In the
sense that all symbols exported by its headers are defined in its
compilation units.
libfs_mgr would still embed libfstab like before, it can use internal
symbols (symbols not exported by public headers) of libfstab through
the libfstab/fstab_priv.h private header.

Keep include_fstab/ as a symbolic link pointing to its new location.
This is a temporary workaround as there are still some bad build rules
(incorrectly) depending on the old include path with Android.bp
`include_dirs` directive.

Bug: 293695109
Test: build
Change-Id: Ib70a84984ac2cbfca5f5b27fadebf6a16e58146a
parent c30f033b
Loading
Loading
Loading
Loading
+0 −43
Original line number Diff line number Diff line
@@ -89,8 +89,6 @@ cc_defaults {
    static_libs: [
        "libavb",
        "libfs_avb",
        "libfstab",
        "libdm",
        "libgsi",
    ],
    export_static_lib_headers: [
@@ -173,47 +171,6 @@ cc_library {
    ],
}

cc_library_static {
    // Do not ever make this a shared library as long as it is vendor_available.
    // It does not have a stable interface.
    name: "libfstab",
    vendor_available: true,
    ramdisk_available: true,
    vendor_ramdisk_available: true,
    recovery_available: true,
    apex_available: [
        "//apex_available:anyapex",
        "//apex_available:platform",
    ],
    host_supported: true,
    defaults: ["fs_mgr_defaults"],
    local_include_dirs: ["include/"],
    srcs: [
        "fs_mgr_fstab.cpp",
        "fs_mgr_boot_config.cpp",
        "fs_mgr_slotselect.cpp",
    ],
    target: {
        darwin: {
            enabled: false,
        },
        vendor: {
            cflags: [
                // Skipping entries in fstab should only be done in a system
                // process as the config file is in /system_ext.
                // Remove the op from the vendor variant.
                "-DNO_SKIP_MOUNT",
            ],
        },
    },
    export_include_dirs: ["include_fstab"],
    header_libs: [
        "libbase_headers",
        "libgsi_headers",
    ],
    min_sdk_version: "31",
}

cc_binary {
    name: "remount",
    defaults: ["fs_mgr_defaults"],
+1 −13
Original line number Diff line number Diff line
@@ -23,15 +23,7 @@
#include <fs_mgr.h>
#include <fstab/fstab.h>

#include "fs_mgr_priv_boot_config.h"

/* The CHECK() in logging.h will use program invocation name as the tag.
 * Thus, the log will have prefix "init: " when libfs_mgr is statically
 * linked in the init process. This might be opaque when debugging.
 * Appends "in libfs_mgr" at the end of the abort message to explicitly
 * indicate the check happens in fs_mgr.
 */
#define FS_MGR_CHECK(x) CHECK(x) << "in libfs_mgr "
#include "libfstab/fstab_priv.h"

#define FS_MGR_TAG "[libfs_mgr] "

@@ -89,10 +81,7 @@
using namespace std::chrono_literals;

bool fs_mgr_set_blk_ro(const std::string& blockdev, bool readonly = true);
bool fs_mgr_update_for_slotselect(android::fs_mgr::Fstab* fstab);
bool fs_mgr_is_device_unlocked();
const std::string& get_android_dt_dir();
bool is_dt_compatible();

bool fs_mgr_is_ext4(const std::string& blk_device);
bool fs_mgr_is_f2fs(const std::string& blk_device);
@@ -104,7 +93,6 @@ namespace android {
namespace fs_mgr {

bool UnmapDevice(const std::string& name);
bool InRecovery();

struct OverlayfsCheckResult {
    bool supported;

fs_mgr/include_fstab

0 → 120000
+1 −0
Original line number Diff line number Diff line
libfstab/include
 No newline at end of file
+62 −0
Original line number Diff line number Diff line
//
// Copyright (C) 2023 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package {
    default_applicable_licenses: [
        "Android-Apache-2.0",
        "system_core_fs_mgr_license",
    ],
}

cc_library_static {
    // Do not ever make this a shared library as long as it is vendor_available.
    // It does not have a stable interface.
    name: "libfstab",
    vendor_available: true,
    ramdisk_available: true,
    vendor_ramdisk_available: true,
    recovery_available: true,
    host_supported: true,
    defaults: ["fs_mgr_defaults"],
    export_include_dirs: ["include"],
    header_libs: [
        "libbase_headers",
        "libgsi_headers",
    ],
    srcs: [
        "fstab.cpp",
        "boot_config.cpp",
        "slotselect.cpp",
    ],
    target: {
        darwin: {
            enabled: false,
        },
        vendor: {
            cflags: [
                // Skipping entries in fstab should only be done in a system
                // process as the config file is in /system_ext.
                // Remove the op from the vendor variant.
                "-DNO_SKIP_MOUNT",
            ],
        },
    },
    apex_available: [
        "//apex_available:anyapex",
        "//apex_available:platform",
    ],
    min_sdk_version: "31",
}
+6 −5
Original line number Diff line number Diff line
@@ -20,11 +20,12 @@
#include <vector>

#include <android-base/file.h>
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <android-base/properties.h>

#include "fs_mgr_priv.h"
#include "fstab_priv.h"
#include "logging_macros.h"

std::vector<std::pair<std::string, std::string>> fs_mgr_parse_cmdline(const std::string& cmdline) {
    static constexpr char quote = '"';
@@ -84,7 +85,7 @@ std::vector<std::pair<std::string, std::string>> fs_mgr_parse_proc_bootconfig(

bool fs_mgr_get_boot_config_from_bootconfig(const std::string& bootconfig,
                                            const std::string& android_key, std::string* out_val) {
    FS_MGR_CHECK(out_val != nullptr);
    FSTAB_CHECK(out_val != nullptr);

    const std::string bootconfig_key("androidboot." + android_key);
    for (const auto& [key, value] : fs_mgr_parse_proc_bootconfig(bootconfig)) {
@@ -100,7 +101,7 @@ bool fs_mgr_get_boot_config_from_bootconfig(const std::string& bootconfig,

bool fs_mgr_get_boot_config_from_kernel(const std::string& cmdline, const std::string& android_key,
                                        std::string* out_val) {
    FS_MGR_CHECK(out_val != nullptr);
    FSTAB_CHECK(out_val != nullptr);

    const std::string cmdline_key("androidboot." + android_key);
    for (const auto& [key, value] : fs_mgr_parse_cmdline(cmdline)) {
@@ -140,7 +141,7 @@ bool fs_mgr_get_boot_config_from_kernel_cmdline(const std::string& key, std::str
// kernel cmdline (in that order).  Returns 'true' if successfully
// found, 'false' otherwise.
bool fs_mgr_get_boot_config(const std::string& key, std::string* out_val) {
    FS_MGR_CHECK(out_val != nullptr);
    FSTAB_CHECK(out_val != nullptr);

    // firstly, check the device tree
    if (is_dt_compatible()) {
Loading