libmodprobe: add support to list modules
List the known modules with a name matching a given pattern. Change-Id: I7f6bd1f09a688c66682f94c5837e61d7dc61c1f7
This commit is contained in:
parent
e31f840a0a
commit
012cfa19b0
2 changed files with 14 additions and 0 deletions
|
|
@ -29,6 +29,7 @@ class Modprobe {
|
||||||
bool LoadWithAliases(const std::string& module_name, bool strict,
|
bool LoadWithAliases(const std::string& module_name, bool strict,
|
||||||
const std::string& parameters = "");
|
const std::string& parameters = "");
|
||||||
bool Remove(const std::string& module_name);
|
bool Remove(const std::string& module_name);
|
||||||
|
std::vector<std::string> ListModules(const std::string& pattern);
|
||||||
void EnableBlacklist(bool enable);
|
void EnableBlacklist(bool enable);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -363,3 +363,16 @@ bool Modprobe::Remove(const std::string& module_name) {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> Modprobe::ListModules(const std::string& pattern) {
|
||||||
|
std::vector<std::string> rv;
|
||||||
|
for (const auto& [module, deps] : module_deps_) {
|
||||||
|
// Attempt to match both the canonical module name and the module filename.
|
||||||
|
if (!fnmatch(pattern.c_str(), module.c_str(), 0)) {
|
||||||
|
rv.emplace_back(module);
|
||||||
|
} else if (!fnmatch(pattern.c_str(), basename(deps[0].c_str()), 0)) {
|
||||||
|
rv.emplace_back(deps[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue