Added mountinfo parser and bind mount hiding

closes #3
This commit is contained in:
snake-4
2024-04-01 04:58:18 +02:00
parent 112c4027fe
commit 83f2880922
6 changed files with 183 additions and 69 deletions
+26 -47
View File
@@ -11,55 +11,15 @@
mount_entry_t::mount_entry_t(::mntent *entry)
: fsname(entry->mnt_fsname), dir(entry->mnt_dir), type(entry->mnt_type), freq(entry->mnt_freq), passno(entry->mnt_passno)
{
parseMountOptions(entry->mnt_opts);
opts_map = parseMountOptions(entry->mnt_opts);
}
const std::string &mount_entry_t::getFsName() const
{
return fsname;
}
const std::string &mount_entry_t::getMountPoint() const
{
return dir;
}
const std::string &mount_entry_t::getType() const
{
return type;
}
const std::unordered_map<std::string, std::string> &mount_entry_t::getOptions() const
{
return opts_map;
}
int mount_entry_t::getDumpFrequency() const
{
return freq;
}
int mount_entry_t::getPassNumber() const
{
return passno;
}
void mount_entry_t::parseMountOptions(const std::string &input)
{
std::istringstream iss(input);
std::string token;
while (std::getline(iss, token, ','))
{
std::istringstream tokenStream(token);
std::string key, value;
if (std::getline(tokenStream, key, '='))
{
std::getline(tokenStream, value); // Put what's left in the stream to value, could be empty
opts_map[key] = value;
}
}
}
const std::string &mount_entry_t::getFsName() const { return fsname; }
const std::string &mount_entry_t::getMountPoint() const { return dir; }
const std::string &mount_entry_t::getType() const { return type; }
const std::unordered_map<std::string, std::string> &mount_entry_t::getOptions() const { return opts_map; }
int mount_entry_t::getDumpFrequency() const { return freq; }
int mount_entry_t::getPassNumber() const { return passno; }
std::vector<mount_entry_t> parseMountsFromPath(const char *path)
{
@@ -81,3 +41,22 @@ std::vector<mount_entry_t> parseMountsFromPath(const char *path)
endmntent(file);
return result;
}
std::unordered_map<std::string, std::string> parseMountOptions(const std::string &input)
{
std::unordered_map<std::string, std::string> ret;
std::istringstream iss(input);
std::string token;
while (std::getline(iss, token, ','))
{
std::istringstream tokenStream(token);
std::string key, value;
if (std::getline(tokenStream, key, '='))
{
std::getline(tokenStream, value); // Put what's left in the stream to value, could be empty
ret[key] = value;
}
}
return ret;
}