mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-18 09:04:49 -04:00
Add a way for the system to set values
This commit is contained in:
parent
5be3c5fda7
commit
0c236f1a36
@ -20,16 +20,61 @@ namespace {
|
|||||||
struct sys_value {
|
struct sys_value {
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string value;
|
std::string value;
|
||||||
|
|
||||||
|
sys_value(){}
|
||||||
|
sys_value(std::string name, std::string value) : name(name), value(value){
|
||||||
|
//Nothing else to init
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sys_folder {
|
struct sys_folder {
|
||||||
std::string name;
|
std::string name;
|
||||||
std::vector<sys_folder> folders;
|
std::vector<sys_folder> folders;
|
||||||
std::vector<sys_value> values;
|
std::vector<sys_value> values;
|
||||||
|
|
||||||
|
sys_folder(){}
|
||||||
|
|
||||||
|
sys_folder(std::string name) : name(name) {
|
||||||
|
//Nothing else to init
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<sys_folder> root_folders;
|
std::vector<sys_folder> root_folders;
|
||||||
|
|
||||||
|
sys_folder& find_root_folder(const std::string& mount_point){
|
||||||
|
for(auto& sys_folder : root_folders){
|
||||||
|
if(sys_folder.name == mount_point){
|
||||||
|
return sys_folder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
root_folders.emplace_back(mount_point);
|
||||||
|
|
||||||
|
return root_folders.back();
|
||||||
|
}
|
||||||
|
|
||||||
|
sys_folder& find_folder(sys_folder& root, const std::vector<std::string>& path, size_t i = 0){
|
||||||
|
auto& name = path[i];
|
||||||
|
|
||||||
|
for(auto& folder : root.folders){
|
||||||
|
if(folder.name == name){
|
||||||
|
if(i == path.size() - 1){
|
||||||
|
return folder;
|
||||||
|
} else {
|
||||||
|
return find_folder(folder, path, i + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
root.folders.emplace_back(name);
|
||||||
|
|
||||||
|
if(i == path.size() - 1){
|
||||||
|
return root.folders.back();
|
||||||
|
} else {
|
||||||
|
return find_folder(root.folders.back(), path, i + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} //end of anonymous namespace
|
} //end of anonymous namespace
|
||||||
|
|
||||||
sysfs::sysfs_file_system::sysfs_file_system(std::string mp) : mount_point(mp) {
|
sysfs::sysfs_file_system::sysfs_file_system(std::string mp) : mount_point(mp) {
|
||||||
@ -55,15 +100,15 @@ size_t sysfs::sysfs_file_system::ls(const std::vector<std::string>& file_path, s
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t sysfs::sysfs_file_system::touch(const std::vector<std::string>& file_path){
|
size_t sysfs::sysfs_file_system::touch(const std::vector<std::string>& ){
|
||||||
return std::ERROR_PERMISSION_DENIED;
|
return std::ERROR_PERMISSION_DENIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t sysfs::sysfs_file_system::mkdir(const std::vector<std::string>& file_path){
|
size_t sysfs::sysfs_file_system::mkdir(const std::vector<std::string>& ){
|
||||||
return std::ERROR_PERMISSION_DENIED;
|
return std::ERROR_PERMISSION_DENIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t sysfs::sysfs_file_system::rm(const std::vector<std::string>& file_path){
|
size_t sysfs::sysfs_file_system::rm(const std::vector<std::string>& ){
|
||||||
return std::ERROR_PERMISSION_DENIED;
|
return std::ERROR_PERMISSION_DENIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +120,22 @@ size_t sysfs::sysfs_file_system::statfs(statfs_info& file){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void set_value(const std::string& mount_point, const std::string& path, const std::string& value){
|
void set_value(const std::string& mount_point, const std::string& path, const std::string& value){
|
||||||
//TODO
|
auto& root_folder = find_root_folder(mount_point);
|
||||||
|
|
||||||
|
auto file_path = std::split(path, '/');
|
||||||
|
auto last = file_path.back();
|
||||||
|
file_path.pop_back();
|
||||||
|
|
||||||
|
auto& folder = find_folder(root_folder, file_path);
|
||||||
|
|
||||||
|
for(auto& v : folder.values){
|
||||||
|
if(v.name == last){
|
||||||
|
v.value = value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
folder.values.emplace_back(last, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void delete_value(const std::string& mount_point, const std::string& path){
|
void delete_value(const std::string& mount_point, const std::string& path){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user