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

Commit 6eb4d64e authored by Thiébaud Weksteen's avatar Thiébaud Weksteen Committed by Gerrit Code Review
Browse files

Merge "Remove unused execution paths when formatting"

parents e7bc3e37 5d72d6ce
Loading
Loading
Loading
Loading
+5 −7
Original line number Original line Diff line number Diff line
@@ -1683,10 +1683,9 @@ static unsigned fb_get_flash_block_size(std::string name) {
    return size;
    return size;
}
}


static void fb_perform_format(
static void fb_perform_format(const std::string& partition, int skip_if_not_supported,
                              const std::string& partition, int skip_if_not_supported,
                              const std::string& type_override, const std::string& size_override,
                              const std::string& type_override, const std::string& size_override,
                              const std::string& initial_dir, const unsigned fs_options) {
                              const unsigned fs_options) {
    std::string partition_type, partition_size;
    std::string partition_type, partition_size;


    struct fastboot_buffer buf;
    struct fastboot_buffer buf;
@@ -1748,8 +1747,7 @@ static void fb_perform_format(
    eraseBlkSize = fb_get_flash_block_size("erase-block-size");
    eraseBlkSize = fb_get_flash_block_size("erase-block-size");
    logicalBlkSize = fb_get_flash_block_size("logical-block-size");
    logicalBlkSize = fb_get_flash_block_size("logical-block-size");


    if (fs_generator_generate(gen, output.path, size, initial_dir,
    if (fs_generator_generate(gen, output.path, size, eraseBlkSize, logicalBlkSize, fs_options)) {
            eraseBlkSize, logicalBlkSize, fs_options)) {
        die("Cannot generate image for %s", partition.c_str());
        die("Cannot generate image for %s", partition.c_str());
    }
    }


@@ -2091,7 +2089,7 @@ int FastBootTool::Main(int argc, char* argv[]) {
            std::string partition = next_arg(&args);
            std::string partition = next_arg(&args);


            auto format = [&](const std::string& partition) {
            auto format = [&](const std::string& partition) {
                fb_perform_format(partition, 0, type_override, size_override, "", fs_options);
                fb_perform_format(partition, 0, type_override, size_override, fs_options);
            };
            };
            do_for_partitions(partition, slot_override, format, true);
            do_for_partitions(partition, slot_override, format, true);
        } else if (command == "signature") {
        } else if (command == "signature") {
@@ -2282,7 +2280,7 @@ int FastBootTool::Main(int argc, char* argv[]) {
            }
            }
            if (partition_type.empty()) continue;
            if (partition_type.empty()) continue;
            fb->Erase(partition);
            fb->Erase(partition);
            fb_perform_format(partition, 1, partition_type, "", "", fs_options);
            fb_perform_format(partition, 1, partition_type, "", fs_options);
        }
        }
    }
    }
    if (wants_set_active) {
    if (wants_set_active) {
+8 −32
Original line number Original line Diff line number Diff line
@@ -111,8 +111,7 @@ static int exec_cmd(const char* path, const char** argv, const char** envp) {
}
}
#endif
#endif


static int generate_ext4_image(const char* fileName, long long partSize,
static int generate_ext4_image(const char* fileName, long long partSize, unsigned eraseBlkSize,
                               const std::string& initial_dir, unsigned eraseBlkSize,
                               unsigned logicalBlkSize, const unsigned fsOptions) {
                               unsigned logicalBlkSize, const unsigned fsOptions) {
    static constexpr int block_size = 4096;
    static constexpr int block_size = 4096;
    const std::string exec_dir = android::base::GetExecutableDirectory();
    const std::string exec_dir = android::base::GetExecutableDirectory();
@@ -163,18 +162,9 @@ static int generate_ext4_image(const char* fileName, long long partSize,
    if (ret != 0) {
    if (ret != 0) {
        return -1;
        return -1;
    }
    }

    if (initial_dir.empty()) {
    return 0;
    return 0;
}
}


    const std::string e2fsdroid_path = exec_dir + "/e2fsdroid";
    std::vector<const char*> e2fsdroid_args = {e2fsdroid_path.c_str(), "-f", initial_dir.c_str(),
                                               fileName, nullptr};

    return exec_cmd(e2fsdroid_args[0], e2fsdroid_args.data(), nullptr);
}

enum {
enum {
    // clang-format off
    // clang-format off
    FSCK_SUCCESS                 = 0,
    FSCK_SUCCESS                 = 0,
@@ -188,8 +178,7 @@ enum {
    // clang-format on
    // clang-format on
};
};


static int generate_f2fs_image(const char* fileName, long long partSize,
static int generate_f2fs_image(const char* fileName, long long partSize, unsigned /* unused */,
                               const std::string& initial_dir, unsigned /* unused */,
                               unsigned /* unused */, const unsigned fsOptions) {
                               unsigned /* unused */, const unsigned fsOptions) {
    const std::string exec_dir = android::base::GetExecutableDirectory();
    const std::string exec_dir = android::base::GetExecutableDirectory();
    const std::string mkf2fs_path = exec_dir + "/make_f2fs";
    const std::string mkf2fs_path = exec_dir + "/make_f2fs";
@@ -227,19 +216,6 @@ static int generate_f2fs_image(const char* fileName, long long partSize,
    if (ret != 0) {
    if (ret != 0) {
        return -1;
        return -1;
    }
    }

    if (initial_dir.empty()) {
        return 0;
    }

    const std::string sload_path = exec_dir + "/sload_f2fs";
    std::vector<const char*> sload_args = {sload_path.c_str(), "-S",
                                       "-f", initial_dir.c_str(), fileName, nullptr};

    ret = exec_cmd(sload_args[0], sload_args.data(), nullptr);
    if (ret != 0 && ret != FSCK_ERROR_CORRECTED) {
        return -1;
    }
    return 0;
    return 0;
}
}


@@ -247,8 +223,8 @@ static const struct fs_generator {
    const char* fs_type;  //must match what fastboot reports for partition type
    const char* fs_type;  //must match what fastboot reports for partition type


    //returns 0 or error value
    //returns 0 or error value
    int (*generate)(const char* fileName, long long partSize, const std::string& initial_dir,
    int (*generate)(const char* fileName, long long partSize, unsigned eraseBlkSize,
                    unsigned eraseBlkSize, unsigned logicalBlkSize, const unsigned fsOptions);
                    unsigned logicalBlkSize, const unsigned fsOptions);


} generators[] = {
} generators[] = {
    { "ext4", generate_ext4_image},
    { "ext4", generate_ext4_image},
@@ -265,7 +241,7 @@ const struct fs_generator* fs_get_generator(const std::string& fs_type) {
}
}


int fs_generator_generate(const struct fs_generator* gen, const char* fileName, long long partSize,
int fs_generator_generate(const struct fs_generator* gen, const char* fileName, long long partSize,
                          const std::string& initial_dir, unsigned eraseBlkSize,
                          unsigned eraseBlkSize, unsigned logicalBlkSize,
                          unsigned logicalBlkSize, const unsigned fsOptions) {
                          const unsigned fsOptions) {
    return gen->generate(fileName, partSize, initial_dir, eraseBlkSize, logicalBlkSize, fsOptions);
    return gen->generate(fileName, partSize, eraseBlkSize, logicalBlkSize, fsOptions);
}
}
+2 −2
Original line number Original line Diff line number Diff line
@@ -13,5 +13,5 @@ enum FS_OPTION {


const struct fs_generator* fs_get_generator(const std::string& fs_type);
const struct fs_generator* fs_get_generator(const std::string& fs_type);
int fs_generator_generate(const struct fs_generator* gen, const char* fileName, long long partSize,
int fs_generator_generate(const struct fs_generator* gen, const char* fileName, long long partSize,
                          const std::string& initial_dir, unsigned eraseBlkSize = 0,
                          unsigned eraseBlkSize = 0, unsigned logicalBlkSize = 0,
                          unsigned logicalBlkSize = 0, unsigned fsOptions = 0);
                          unsigned fsOptions = 0);