From 969787cffdf057bb8b4d3995423d818c15b52e9f Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 27 Jan 2020 09:29:02 -0800 Subject: Remove fsck_unshare_blocks. This code is dead. It was briefly used to support "adb remount" with deduplicated partitions, but was very quickly obsoleted by overlayfs support. There is no reason to include it anymore. Bug: N/A Test: N/A Change-Id: I4cdcbf66bec80092f954826eaae037934ff37765 --- Android.bp | 1 - fsck_unshare_blocks.cpp | 151 ------------------------------------------------ fsck_unshare_blocks.h | 22 ------- recovery.cpp | 11 +--- 4 files changed, 1 insertion(+), 184 deletions(-) delete mode 100644 fsck_unshare_blocks.cpp delete mode 100644 fsck_unshare_blocks.h diff --git a/Android.bp b/Android.bp index 3a8e97883..4032bcc19 100644 --- a/Android.bp +++ b/Android.bp @@ -90,7 +90,6 @@ cc_library_static { ], srcs: [ - "fsck_unshare_blocks.cpp", "recovery.cpp", ], diff --git a/fsck_unshare_blocks.cpp b/fsck_unshare_blocks.cpp deleted file mode 100644 index e0b2d966b..000000000 --- a/fsck_unshare_blocks.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (C) 2018 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 "fsck_unshare_blocks.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "recovery_utils/roots.h" - -static constexpr const char* SYSTEM_E2FSCK_BIN = "/system/bin/e2fsck_static"; -static constexpr const char* TMP_E2FSCK_BIN = "/tmp/e2fsck.bin"; - -static bool copy_file(const char* source, const char* dest) { - android::base::unique_fd source_fd(open(source, O_RDONLY)); - if (source_fd < 0) { - PLOG(ERROR) << "open %s failed" << source; - return false; - } - - android::base::unique_fd dest_fd(open(dest, O_CREAT | O_WRONLY, S_IRWXU)); - if (dest_fd < 0) { - PLOG(ERROR) << "open %s failed" << dest; - return false; - } - - for (;;) { - char buf[4096]; - ssize_t rv = read(source_fd, buf, sizeof(buf)); - if (rv < 0) { - PLOG(ERROR) << "read failed"; - return false; - } - if (rv == 0) { - break; - } - if (write(dest_fd, buf, rv) != rv) { - PLOG(ERROR) << "write failed"; - return false; - } - } - return true; -} - -static bool run_e2fsck(const std::string& partition) { - Volume* volume = volume_for_mount_point(partition); - if (!volume) { - LOG(INFO) << "No fstab entry for " << partition << ", skipping."; - return true; - } - - LOG(INFO) << "Running e2fsck on device " << volume->blk_device; - - std::vector args = { TMP_E2FSCK_BIN, "-p", "-E", "unshare_blocks", - volume->blk_device }; - std::vector argv(args.size()); - std::transform(args.cbegin(), args.cend(), argv.begin(), - [](const std::string& arg) { return const_cast(arg.c_str()); }); - argv.push_back(nullptr); - - pid_t child; - char* env[] = { nullptr }; - if (posix_spawn(&child, argv[0], nullptr, nullptr, argv.data(), env)) { - PLOG(ERROR) << "posix_spawn failed"; - return false; - } - - int status = 0; - int ret = TEMP_FAILURE_RETRY(waitpid(child, &status, 0)); - if (ret < 0) { - PLOG(ERROR) << "waitpid failed"; - return false; - } - if (!WIFEXITED(status)) { - LOG(ERROR) << "e2fsck exited abnormally: " << status; - return false; - } - int return_code = WEXITSTATUS(status); - if (return_code >= 8) { - LOG(ERROR) << "e2fsck could not unshare blocks: " << return_code; - return false; - } - - LOG(INFO) << "Successfully unshared blocks on " << partition; - return true; -} - -bool do_fsck_unshare_blocks() { - // List of partitions we will try to e2fsck -E unshare_blocks. - std::vector partitions = { "/odm", "/oem", "/product", "/vendor" }; - - // Temporarily mount system so we can copy e2fsck_static. - auto system_root = android::fs_mgr::GetSystemRoot(); - bool mounted = ensure_path_mounted_at(system_root, "/mnt/system") != -1; - partitions.push_back(system_root); - - if (!mounted) { - LOG(ERROR) << "Failed to mount system image."; - return false; - } - if (!copy_file(SYSTEM_E2FSCK_BIN, TMP_E2FSCK_BIN)) { - LOG(ERROR) << "Could not copy e2fsck to /tmp."; - return false; - } - if (umount("/mnt/system") < 0) { - PLOG(ERROR) << "umount failed"; - return false; - } - - bool ok = true; - for (const auto& partition : partitions) { - ok &= run_e2fsck(partition); - } - - if (ok) { - LOG(INFO) << "Finished running e2fsck."; - } else { - LOG(ERROR) << "Finished running e2fsck, but not all partitions succceeded."; - } - return ok; -} diff --git a/fsck_unshare_blocks.h b/fsck_unshare_blocks.h deleted file mode 100644 index 9de8ef9a3..000000000 --- a/fsck_unshare_blocks.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2018 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. - */ - -#ifndef _FILESYSTEM_CMDS_H -#define _FILESYSTEM_CMDS_H - -bool do_fsck_unshare_blocks(); - -#endif // _FILESYSTEM_CMDS_H diff --git a/recovery.cpp b/recovery.cpp index e4b8e45fb..cbf29b6c1 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -45,7 +45,6 @@ #include #include "bootloader_message/bootloader_message.h" -#include "fsck_unshare_blocks.h" #include "install/adb_install.h" #include "install/fuse_install.h" #include "install/install.h" @@ -524,7 +523,6 @@ static void log_failure_code(ErrorCode code, const std::string& update_package) Device::BuiltinAction start_recovery(Device* device, const std::vector& args) { static constexpr struct option OPTIONS[] = { { "fastboot", no_argument, nullptr, 0 }, - { "fsck_unshare_blocks", no_argument, nullptr, 0 }, { "install_with_fuse", no_argument, nullptr, 0 }, { "just_exit", no_argument, nullptr, 'x' }, { "locale", required_argument, nullptr, 0 }, @@ -557,7 +555,6 @@ Device::BuiltinAction start_recovery(Device* device, const std::vectorPrint("\nInstall from ADB complete (status: %d).\n", status); - } else if (fsck_unshare_blocks) { - if (!do_fsck_unshare_blocks()) { - status = INSTALL_ERROR; - } } else if (!just_exit) { // If this is an eng or userdebug build, automatically turn on the text display if no command // is specified. Note that this should be called before setting the background to avoid -- cgit v1.2.3