Exemple #1
0
std::shared_ptr<Rom> Roms::create_rom(const std::string &id)
{
    if (id == "primary") {
        return create_rom_primary();
    } else if (id == "dual") {
        return create_rom_dual();
    } else if (util::starts_with(id, "multi-slot-")) {
        unsigned int num;
        if (sscanf(id.c_str(), "multi-slot-%u", &num) == 1) {
            return create_rom_multi_slot(num);
        }
    } else if (util::starts_with(id, "data-slot-") && id != "data-slot-") {
        return create_rom_data_slot(id.substr(10));
    } else if (util::starts_with(id, "extsd-slot-") && id != "extsd-slot-") {
        return create_rom_extsd_slot(id.substr(11));
    }

    return std::shared_ptr<Rom>();
}
Exemple #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));
}
Exemple #3
0
void Roms::add_extsd_roms()
{
    for (const std::string &mount_point : extsd_mount_points) {
        std::string search_dir(mount_point);
        search_dir += "/multiboot";

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

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

        struct stat sb;

        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)) {
                roms.push_back(create_rom_extsd_slot(ent->d_name + 11));
            }
        }

        break;
    }
}