Remove unused execution paths when formatting

fastboot uses the internal functions generate_ext4_image and
generate_f2fs_image when called via the `format` subcommand. An option
for populating the newly created fs with an initial directory exists,
but it is not exposed to the command line interface (initial_dir is
always ""). Remove the unused codepaths for this preloading.

Test: atest --host fastboot_test
Bug: 237960487
Change-Id: I7acfe6352cf26b5cbe0e5553b288c3798e96a893
This commit is contained in:
Thiébaud Weksteen 2022-07-21 14:43:20 +10:00
parent c20b6b58fc
commit 5d72d6ce20
3 changed files with 15 additions and 41 deletions

View file

@ -1683,10 +1683,9 @@ static unsigned fb_get_flash_block_size(std::string name) {
return size;
}
static void fb_perform_format(
const std::string& partition, int skip_if_not_supported,
static void fb_perform_format(const std::string& partition, int skip_if_not_supported,
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;
struct fastboot_buffer buf;
@ -1748,8 +1747,7 @@ static void fb_perform_format(
eraseBlkSize = fb_get_flash_block_size("erase-block-size");
logicalBlkSize = fb_get_flash_block_size("logical-block-size");
if (fs_generator_generate(gen, output.path, size, initial_dir,
eraseBlkSize, logicalBlkSize, fs_options)) {
if (fs_generator_generate(gen, output.path, size, eraseBlkSize, logicalBlkSize, fs_options)) {
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);
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);
} else if (command == "signature") {
@ -2282,7 +2280,7 @@ int FastBootTool::Main(int argc, char* argv[]) {
}
if (partition_type.empty()) continue;
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) {

View file

@ -111,8 +111,7 @@ static int exec_cmd(const char* path, const char** argv, const char** envp) {
}
#endif
static int generate_ext4_image(const char* fileName, long long partSize,
const std::string& initial_dir, unsigned eraseBlkSize,
static int generate_ext4_image(const char* fileName, long long partSize, unsigned eraseBlkSize,
unsigned logicalBlkSize, const unsigned fsOptions) {
static constexpr int block_size = 4096;
const std::string exec_dir = android::base::GetExecutableDirectory();
@ -163,16 +162,7 @@ static int generate_ext4_image(const char* fileName, long long partSize,
if (ret != 0) {
return -1;
}
if (initial_dir.empty()) {
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);
return 0;
}
enum {
@ -188,8 +178,7 @@ enum {
// clang-format on
};
static int generate_f2fs_image(const char* fileName, long long partSize,
const std::string& initial_dir, unsigned /* unused */,
static int generate_f2fs_image(const char* fileName, long long partSize, unsigned /* unused */,
unsigned /* unused */, const unsigned fsOptions) {
const std::string exec_dir = android::base::GetExecutableDirectory();
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) {
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;
}
@ -247,8 +223,8 @@ static const struct fs_generator {
const char* fs_type; //must match what fastboot reports for partition type
//returns 0 or error value
int (*generate)(const char* fileName, long long partSize, const std::string& initial_dir,
unsigned eraseBlkSize, unsigned logicalBlkSize, const unsigned fsOptions);
int (*generate)(const char* fileName, long long partSize, unsigned eraseBlkSize,
unsigned logicalBlkSize, const unsigned fsOptions);
} generators[] = {
{ "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,
const std::string& initial_dir, unsigned eraseBlkSize,
unsigned logicalBlkSize, const unsigned fsOptions) {
return gen->generate(fileName, partSize, initial_dir, eraseBlkSize, logicalBlkSize, fsOptions);
unsigned eraseBlkSize, unsigned logicalBlkSize,
const unsigned fsOptions) {
return gen->generate(fileName, partSize, eraseBlkSize, logicalBlkSize, fsOptions);
}

View file

@ -13,5 +13,5 @@ enum FS_OPTION {
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,
const std::string& initial_dir, unsigned eraseBlkSize = 0,
unsigned logicalBlkSize = 0, unsigned fsOptions = 0);
unsigned eraseBlkSize = 0, unsigned logicalBlkSize = 0,
unsigned fsOptions = 0);