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

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

Make clean_scratch_files work

clean_scratch_files.rc seems to never work as intended due to
missing domain transition rules.
Add a 'remount' domain to the platform policies to allow
remount-related operations, including clean_scratch_files.
Merge remount and clean_scratch_files binary to simplify the added
policies.

Bug: 204836146
Test: 1. Use a VAB device, for example bramble-userdebug
  2. adb remount system
  3. adb reboot fastboot && fastboot flash system system.img
  4. recovery (fastbootd) should mark the remount scratch as disabled
  5. fastboot reboot && adb shell mount | grep scratch => nothing
  6. adb logcat | grep 'clean_scratch_files|gsid' => shows that
    disabled image "scratch" is removed during boot
Change-Id: I18d543868d1f37d43b483eae7517b707e46df1bd
parent cab12f8a
Loading
Loading
Loading
Loading
+3 −19
Original line number Diff line number Diff line
@@ -246,28 +246,12 @@ cc_binary {
                "-UALLOW_ADBD_DISABLE_VERITY",
                "-DALLOW_ADBD_DISABLE_VERITY=1",
            ],
        },
    },
    required: [
        "clean_scratch_files",
    ],
}

cc_binary {
    name: "clean_scratch_files",
    defaults: ["fs_mgr_defaults"],
    shared_libs: [
        "libbase",
        "libfs_mgr_binder",
    ],
    srcs: [
        "clean_scratch_files.cpp",
    ],
    product_variables: {
        debuggable: {
            init_rc: [
                "clean_scratch_files.rc",
            ],
        },
    },
    symlinks: [
        "clean_scratch_files",
    ],
}

fs_mgr/clean_scratch_files.cpp

deleted100644 → 0
+0 −22
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.
 */

#include <fs_mgr_overlayfs.h>

int main() {
    android::fs_mgr::CleanupOldScratchFiles();
    return 0;
}
+16 −0
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@
#include <libavb_user/libavb_user.h>
#include <libgsi/libgsid.h>

using namespace std::literals;

namespace {

[[noreturn]] void usage(int exit_status) {
@@ -142,6 +144,7 @@ enum RemountStatus {
    BINDER_ERROR,
    CHECKPOINTING,
    GSID_ERROR,
    CLEAN_SCRATCH_FILES,
};

static int do_remount(int argc, char* argv[]) {
@@ -163,6 +166,7 @@ static int do_remount(int argc, char* argv[]) {
            {"help", no_argument, nullptr, 'h'},
            {"reboot", no_argument, nullptr, 'R'},
            {"verbose", no_argument, nullptr, 'v'},
            {"clean_scratch_files", no_argument, nullptr, 'C'},
            {0, 0, nullptr, 0},
    };
    for (int opt; (opt = ::getopt_long(argc, argv, "hRT:v", longopts, nullptr)) != -1;) {
@@ -183,6 +187,8 @@ static int do_remount(int argc, char* argv[]) {
            case 'v':
                verbose = true;
                break;
            case 'C':
                return CLEAN_SCRATCH_FILES;
            default:
                LOG(ERROR) << "Bad Argument -" << char(opt);
                usage(BADARG);
@@ -476,14 +482,24 @@ static int do_remount(int argc, char* argv[]) {
    return retval;
}

static int do_clean_scratch_files() {
    android::fs_mgr::CleanupOldScratchFiles();
    return 0;
}

int main(int argc, char* argv[]) {
    android::base::InitLogging(argv, MyLogger);
    if (argc > 0 && android::base::Basename(argv[0]) == "clean_scratch_files"s) {
        return do_clean_scratch_files();
    }
    int result = do_remount(argc, argv);
    if (result == MUST_REBOOT) {
        LOG(INFO) << "Now reboot your device for settings to take effect";
        result = 0;
    } else if (result == REMOUNT_SUCCESS) {
        printf("remount succeeded\n");
    } else if (result == CLEAN_SCRATCH_FILES) {
        return do_clean_scratch_files();
    } else {
        printf("remount failed\n");
    }
+6 −1
Original line number Diff line number Diff line
@@ -696,7 +696,12 @@ bool ImageManager::RemoveDisabledImages() {
    bool ok = true;
    for (const auto& partition : metadata->partitions) {
        if (partition.attributes & LP_PARTITION_ATTR_DISABLED) {
            ok &= DeleteBackingImage(GetPartitionName(partition));
            const auto name = GetPartitionName(partition);
            if (!DeleteBackingImage(name)) {
                ok = false;
            } else {
                LOG(INFO) << "Removed disabled partition image: " << name;
            }
        }
    }
    return ok;