parent
b9c7d7c5cb
commit
de96957bc0
@ -0,0 +1,50 @@
|
||||
#include "my_device.h"
|
||||
|
||||
device_config obj_device_config;
|
||||
|
||||
device_config* get_device_cfg() {
|
||||
return &obj_device_config;
|
||||
}
|
||||
|
||||
void device_disk_parsed() {
|
||||
char* cmd = "lsblk --fs --raw --output PATH,FSTYPE --exclude 7,11,253";
|
||||
int size = 0;
|
||||
char** responce = yon_config_load(cmd, &size);
|
||||
obj_device_config.size_disk = 0;
|
||||
char* split_simvol = " ";
|
||||
for (int index = 1; index < size; index++ ) {
|
||||
char* disk = yon_char_divide_search(responce[index], "\n", -1);
|
||||
if (yon_char_find_count(disk, " ") != 0) {
|
||||
char* name_disk = yon_char_divide_search(disk, " ", -1);
|
||||
obj_device_config.name_disk = yon_char_parsed_append(obj_device_config.name_disk, &obj_device_config.size_disk, name_disk);
|
||||
obj_device_config.size_disk--;
|
||||
obj_device_config.file_system = yon_char_parsed_append(obj_device_config.file_system, &obj_device_config.size_disk, disk);
|
||||
obj_device_config.size_disk--;
|
||||
obj_device_config.mounted = yon_char_parsed_append(obj_device_config.mounted, &obj_device_config.size_disk, "");
|
||||
obj_device_config.size_disk--;
|
||||
obj_device_config.type_dick = yon_char_parsed_append(obj_device_config.type_dick, &obj_device_config.size_disk, "");
|
||||
obj_device_config.size_disk--;
|
||||
disk = yon_char_replace(disk," ", "");
|
||||
if (strlen(disk)!=0) {
|
||||
char* description_disk = yon_char_unite(name_disk,
|
||||
split_simvol,
|
||||
disk,
|
||||
NULL);
|
||||
obj_device_config.description_disk = yon_char_parsed_append(obj_device_config.description_disk, &obj_device_config.size_disk, description_disk);
|
||||
free(description_disk);
|
||||
|
||||
}
|
||||
free(name_disk);
|
||||
}
|
||||
free(disk);
|
||||
}
|
||||
philos_free_string_array(&responce, size);
|
||||
|
||||
}
|
||||
void device_fill_disk(GtkWidget* combo_box_text) {
|
||||
for (int index = 0; index < obj_device_config.size_disk; index++) {
|
||||
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo_box_text), obj_device_config.description_disk[index]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,24 @@
|
||||
#ifndef MY_DEVICE_H
|
||||
#define MY_DEVICE_H
|
||||
#include "ubl-utils.h"
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include "philos_utils.h"
|
||||
typedef struct {
|
||||
char** name_disk;
|
||||
char** file_system;
|
||||
char** mounted;
|
||||
char** type_dick;
|
||||
char** description_disk;
|
||||
int size_disk;
|
||||
} device_config;
|
||||
|
||||
void device_disk_parsed();
|
||||
device_config* get_device_cfg();
|
||||
void device_fill_disk(GtkWidget* combo_box_text);
|
||||
size_t get_mem_total();
|
||||
float get_size_pow_memory(size_t size_memory, int size);
|
||||
size_t get_resurs_total(char* cmd);
|
||||
|
||||
#endif
|
@ -0,0 +1,101 @@
|
||||
#ifndef SAVE_H
|
||||
#define SAVE_H
|
||||
#include "save.h"
|
||||
|
||||
|
||||
char* template_format_save(config_u_g_p* config, char* cmd) {
|
||||
for (int i = 0; i < config->size; i++) {
|
||||
char* key = save_format_key(config, i);
|
||||
char* value = save_format_str_value(config, i);
|
||||
char* value_status = save_format_status_cmd(config, i);
|
||||
if (key!= NULL) {
|
||||
// key = yon_char_unite(cmd, " " , key, "=\"" , value, "\" ", NULL);
|
||||
cmd = yon_char_unite(cmd, key, "=" , value, " ", NULL);
|
||||
cmd = yon_char_unite(cmd, key, "=" , value_status, " ", NULL);
|
||||
free(key);
|
||||
free(value);
|
||||
free(value_status);
|
||||
}
|
||||
|
||||
}
|
||||
return cmd;
|
||||
}
|
||||
|
||||
char* save_format_key(config_u_g_p* config, int index) {
|
||||
if (config->status_set[index] == 1) {
|
||||
return NULL;
|
||||
}
|
||||
char* cmd = yon_char_new("");
|
||||
char* value = yon_char_new("");
|
||||
char* key = yon_char_new("");
|
||||
int number = config->number[index];
|
||||
|
||||
key = yon_char_unite("CGROUP_QUOTA[", config->type_arr[index], ":", NULL);
|
||||
if (strstr(config->type_arr[index], "prjquota")) {
|
||||
if (number!=-1) {
|
||||
key = yon_char_unite(config->UNIX_file[index],":",yon_char_from_int(number), NULL);
|
||||
}
|
||||
else {
|
||||
key = yon_char_unite(config->UNIX_file[index],":AUTO", NULL);
|
||||
}
|
||||
}
|
||||
else {
|
||||
key = yon_char_unite(config->UNIX_file[index], NULL);
|
||||
}
|
||||
|
||||
|
||||
key = yon_char_unite(key, save_str_users(config, index) , "]", NULL);
|
||||
|
||||
return cmd;
|
||||
|
||||
}
|
||||
|
||||
char* save_format_str_value(config_u_g_p* config, int index) {
|
||||
if (config->status_set[index] == 1) {
|
||||
return NULL;
|
||||
}
|
||||
char* value = yon_char_new("");
|
||||
value = philos_format_cfg_str_size_memory(value, config->soft_restriction_size[index],config->soft_restriction_size_pow[index]);
|
||||
value = yon_char_unite(value, ",");
|
||||
philos_format_cfg_str_size_memory(value, config->soft_restriction_file[index],config->soft_restriction_file_pow[index]);
|
||||
value = yon_char_unite(value, ",");
|
||||
philos_format_cfg_str_size_memory(value, config->severe_limitation_size[index],config->severe_limitation_size_pow[index]);
|
||||
value = yon_char_unite(value, ",");
|
||||
philos_format_cfg_str_size_memory(value, config->severe_limitation_file[index], config->severe_limitation_file_pow[index]);
|
||||
value = yon_char_unite(value, ",");
|
||||
philos_format_cfg_str_size_memory(value, config->deferring_size[index], config->deferring_size_pow[index]);
|
||||
value = yon_char_unite(value, ",");
|
||||
value = philos_format_cfg_str_size_memory(value, config->deferring_file[index], config->deferring_file_pow[index]);
|
||||
return value;
|
||||
}
|
||||
|
||||
char* save_str_users(config_u_g_p* config, int index) {
|
||||
char* cmd = yon_char_new("");
|
||||
char split_simvol[2] = {0};
|
||||
split_simvol[0] = 0;
|
||||
split_simvol[1] = 0;
|
||||
if (strstr(config->type_arr[index], "prjquota")) {
|
||||
for (int i=0; config->actors[i]; i++) {
|
||||
cmd = yon_char_unite(":", split_simvol, config->actors[i], NULL);
|
||||
split_simvol[0] = ',';
|
||||
split_simvol[1] = '\0';
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
char* save_format_status_cmd(config_u_g_p* config, int index) {
|
||||
if (config->status_set[index] == 1) {
|
||||
return NULL;
|
||||
}
|
||||
if (config->status[index]) {
|
||||
return yon_char_new("enable");
|
||||
}
|
||||
else {
|
||||
return yon_char_new("disable");
|
||||
}
|
||||
return yon_char_new("disable");
|
||||
}
|
||||
#endif
|
@ -0,0 +1,11 @@
|
||||
#ifndef SAVE
|
||||
#define SAVE
|
||||
#include "ubl-utils.h"
|
||||
#include "../ubl-strings.h"
|
||||
#include "model.h"
|
||||
char* template_format_save(config_u_g_p* _config, char* cmd);
|
||||
char* save_format_key(config_u_g_p* _config, int index);
|
||||
char* save_str_users(config_u_g_p* _config, int index);
|
||||
char* save_format_str_value(config_u_g_p* config, int index);
|
||||
char* save_format_status_cmd(config_u_g_p* config, int index);
|
||||
#endif
|
Loading…
Reference in new issue