parent
4acb8c8bba
commit
65894da802
@ -1,43 +1,28 @@
|
|||||||
#include "my_device.h"
|
#include "my_device.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Devices {
|
namespace Devices {
|
||||||
std::vector<Mount> Get_device::get_all_device() {
|
|
||||||
std::vector<Mount> vec_mount_devices;
|
map_str_str Parted::get_parted() {
|
||||||
std::vector<string> vec_str;
|
string cmd = "lsblk --fs --raw --output PATH,FSTYPE --exclude 7,11,253";
|
||||||
std::ifstream file("/proc/mounts");
|
string response = obj_process_call.call_all_sections(cmd);
|
||||||
if (file.is_open()) {
|
vector<string> vec_parted = Utils::split(response, '\n');
|
||||||
std::string line;
|
map_str_str dict_parted;
|
||||||
while (std::getline(file, line)) {
|
string key = "";
|
||||||
vec_str = Utils::split(line, ' ');
|
if (vec_parted.size()>1) {
|
||||||
struct Mount mount;
|
vec_parted.erase(vec_parted.begin());
|
||||||
mount.device = vec_str[0];
|
|
||||||
mount.destination = vec_str[1];
|
|
||||||
mount.fstype = vec_str[2];
|
|
||||||
mount.options = vec_str[3];
|
|
||||||
mount.dump = vec_str[4];
|
|
||||||
mount.pass = vec_str[5];
|
|
||||||
vec_mount_devices.push_back(mount);
|
|
||||||
}
|
}
|
||||||
|
for (const string& str_parted : vec_parted) {
|
||||||
|
key = str_parted.substr(0, str_parted.find(" "));
|
||||||
|
if (str_parted.find(" ") != string::npos) {
|
||||||
|
dict_parted[key] = str_parted.substr(str_parted.find(" ") + 1, str_parted.length());
|
||||||
}
|
}
|
||||||
file.close();
|
else {
|
||||||
return vec_mount_devices;
|
dict_parted[key] = "";
|
||||||
|
|
||||||
}
|
|
||||||
std::vector<Mount> Get_device::get_part_devices(string find_device_name) {
|
|
||||||
std::vector<Mount> vec_mount_devices;
|
|
||||||
for (const auto &device: this->get_all_device()) {
|
|
||||||
if (device.device.find(find_device_name) != std::string::npos) {
|
|
||||||
vec_mount_devices.push_back(device);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return vec_mount_devices;
|
|
||||||
}
|
|
||||||
|
|
||||||
map_str_device Get_device::get_map_part_devices(string find_device_name) {
|
return dict_parted;
|
||||||
map_str_device map_device;
|
|
||||||
for (const auto &device: this->get_part_devices(find_device_name)) {
|
|
||||||
map_device[device.device] = device;
|
|
||||||
}
|
|
||||||
return map_device;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in new issue