From c7bfc370ae8974302cf1e316b3e03d0e6e960e0c Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Tue, 24 Sep 2024 13:38:34 +0200 Subject: src: add used_size and free_size to partition data Extend database table ordenadores_particiones to add new "used_size" and "free_size" fields. FIELD TYPE | tamano | bigint | | uso | tinyint | | used_size | bigint | | free_size | bigint | "tamano" is the field storing the total size of the partition. "uso" is a field storing the integer percentage of use, it is preserved for backwards compatibility with scritps that access the database. "used_size" and "free_size" contain the used and free partition size in bytes. Old response from ogClient for /cache/delete, /cache/fetch and /image/restore: { 'cache': [ {'name': 'windows.img', 'size': 2432370213, checksum: '5d4dcc677bc19f40a647d0002f4ade90'}, {'name': 'linux.img', 'size': 243234534213, checksum: '3eb22f888f88a55ad954f55644e1192e'} ] } New response: { 'cache': { 'used_size': 4520232322423, 'free_size': 48273465287452945, 'images': [ {'name': 'windows.img', 'size': 2432370213, checksum: '5d4dcc677bc19f40a647d0002f4ade90'}, {'name': 'linux.img', 'size': 243234534213, checksum: '3eb22f888f88a55ad954f55644e1192e'} ] } } Parse the new "free_size" and "used_size" fields of each partition data in the response payload of /refresh Parse "free_size" and "used_size" fields of the cache data in the reponse payload of /image/restore, /cache/delete and /cache/fetch Replace "used_size" field of GET /client/setup with the value of the new database field "used_size" --- src/rest.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/rest.c') diff --git a/src/rest.c b/src/rest.c index 917b72b..87259cf 100644 --- a/src/rest.c +++ b/src/rest.c @@ -1723,7 +1723,8 @@ static int og_cmd_get_client_setup(json_t *element, int filesystem; int format; int os; - int used_size; + uint64_t used_size; + uint64_t free_size; int image; int software; } partition; @@ -1761,8 +1762,8 @@ static int og_cmd_get_client_setup(json_t *element, result = dbi_conn_queryf(dbi->conn, "SELECT numdisk, numpar, codpar, tamano, " - " uso, idsistemafichero, idnombreso, " - " idimagen, idperfilsoft " + " idsistemafichero, idnombreso, " + " idimagen, idperfilsoft, used_size, free_size " "FROM ordenadores_particiones " "INNER JOIN ordenadores " "ON ordenadores.idordenador = ordenadores_particiones.idordenador " @@ -1784,11 +1785,12 @@ static int og_cmd_get_client_setup(json_t *element, partition.number = dbi_result_get_int(result, "numpar"); partition.code = dbi_result_get_int(result, "codpar"); partition.size = dbi_result_get_longlong(result, "tamano"); - partition.used_size = dbi_result_get_int(result, "uso"); partition.filesystem = dbi_result_get_int(result, "idsistemafichero"); partition.os = dbi_result_get_int(result, "idnombreso"); partition.image = dbi_result_get_int(result, "idimagen"); partition.software = dbi_result_get_int(result, "idperfilsoft"); + partition.used_size = dbi_result_get_longlong(result, "used_size"); + partition.free_size = dbi_result_get_longlong(result, "free_size"); partition_json = json_object(); if (!partition_json) { @@ -1808,6 +1810,8 @@ static int og_cmd_get_client_setup(json_t *element, json_integer(partition.size)); json_object_set_new(partition_json, "used_size", json_integer(partition.used_size)); + json_object_set_new(partition_json, "free_size", + json_integer(partition.free_size)); json_object_set_new(partition_json, "filesystem", json_integer(partition.filesystem)); json_object_set_new(partition_json, "os", -- cgit v1.2.3-18-g5258