Example #1
0
std::string Roms::get_mountpoint(Rom::Source source)
{
    switch (source) {
    case Rom::Source::SYSTEM:
        return get_system_partition();
    case Rom::Source::CACHE:
        return get_cache_partition();
    case Rom::Source::DATA:
        return get_data_partition();
    case Rom::Source::EXTERNAL_SD:
        return get_extsd_partition();
    default:
        return std::string();
    }
}
Example #2
0
void Roms::add_extsd_roms()
{
    std::string mount_point = get_extsd_partition();
    if (mount_point.empty()) {
        return;
    }

    std::string search_dir(mount_point);
    search_dir += "/multiboot";

    DIR *dp = opendir(search_dir.c_str());
    if (!dp) {
        return;
    }

    auto close_dp = util::finally([&]{
        closedir(dp);
    });

    struct stat sb;

    std::vector<std::shared_ptr<Rom>> temp_roms;

    struct dirent *ent;
    while ((ent = readdir(dp))) {
        if (strcmp(ent->d_name, "extsd-slot-") == 0
                || !util::starts_with(ent->d_name, "extsd-slot-")) {
            continue;
        }

        std::string image(search_dir);
        image += "/";
        image += ent->d_name;
        image += "/system.img";

        if (stat(image.c_str(), &sb) == 0 && S_ISREG(sb.st_mode)) {
            temp_roms.push_back(create_rom_extsd_slot(ent->d_name + 11));
        }
    }

    std::sort(temp_roms.begin(), temp_roms.end(), &cmp_rom_id);
    std::move(temp_roms.begin(), temp_roms.end(), std::back_inserter(roms));
}