parent
67fc592638
commit
01a1fb5d82
@ -0,0 +1,35 @@
|
||||
#include "my_device.h"
|
||||
|
||||
namespace Devices {
|
||||
std::vector<Get_device::Mount> Get_device::get_all_device() {
|
||||
std::vector<Mount> vec_mount_devices;
|
||||
std::vector<string> vec_str;
|
||||
std::ifstream file("/proc/mounts");
|
||||
if (file.is_open()) {
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
vec_str = Utils::split(line, ' ');
|
||||
struct Mount mount;
|
||||
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);
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
return vec_mount_devices;
|
||||
|
||||
}
|
||||
std::vector<Get_device::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;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
#ifndef MY_DEVICE_H
|
||||
#define MY_DEVICE_H
|
||||
|
||||
#include "project_lib.h"
|
||||
#include "util.h"
|
||||
|
||||
|
||||
namespace Devices {
|
||||
class Get_device
|
||||
{
|
||||
public:
|
||||
struct Mount {
|
||||
std::string device;
|
||||
std::string destination;
|
||||
std::string fstype;
|
||||
std::string options;
|
||||
std::string dump;
|
||||
std::string pass;
|
||||
};
|
||||
|
||||
public:
|
||||
std::vector<Mount> get_all_device();
|
||||
std::vector<Get_device::Mount> Get_device::get_part_devices(string find_device_name)
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in new issue