aboutsummaryrefslogtreecommitdiff
path: root/c_implementation/src/akfs_map_v3.c
diff options
context:
space:
mode:
authorkaotisk <kaotisk@arching-kaos.org>2025-04-24 01:59:36 +0300
committerkaotisk <kaotisk@arching-kaos.org>2025-04-24 01:59:36 +0300
commit22d9aeb0f3057c43cf7c561bc208c3acec45135e (patch)
tree2e0eca7350a778a0e9c1011b41eea18429a742b4 /c_implementation/src/akfs_map_v3.c
parent07d2b7e430e17cceaab2715a816e4182f299f441 (diff)
downloadarching-kaos-tools-22d9aeb0f3057c43cf7c561bc208c3acec45135e.tar.gz
arching-kaos-tools-22d9aeb0f3057c43cf7c561bc208c3acec45135e.tar.bz2
arching-kaos-tools-22d9aeb0f3057c43cf7c561bc208c3acec45135e.zip
[libakfs] Updates
Diffstat (limited to 'c_implementation/src/akfs_map_v3.c')
-rw-r--r--c_implementation/src/akfs_map_v3.c139
1 files changed, 139 insertions, 0 deletions
diff --git a/c_implementation/src/akfs_map_v3.c b/c_implementation/src/akfs_map_v3.c
new file mode 100644
index 0000000..7b7e75b
--- /dev/null
+++ b/c_implementation/src/akfs_map_v3.c
@@ -0,0 +1,139 @@
+#include <stdio.h>
+#include <string.h>
+#include <libakfs.h>
+#include <libaklog.h>
+#include <sys/stat.h>
+
+// const char maps_dir[] = "/home/kaotisk/.arching-kaos/akfs/maps/";
+
+void ak_fs_map_v3_init(akfs_map_v3 *map)
+{
+ ak_fs_sha512sum_init(&map->oh);
+ ak_fs_sha512sum_init(&map->rh);
+ ak_fs_sha512sum_init(&map->mh);
+ ak_fs_init_string(map->filename, 256);
+}
+
+void ak_fs_map_v3_init_store(akfs_map_v3** ms, size_t l)
+{
+ akfs_map_v3 *m = NULL;
+ for (m = *ms; m < *ms+l; ++m)
+ {
+ ak_fs_map_v3_init(m);
+ }
+}
+
+void ak_fs_map_v3_print_original_hash(akfs_map_v3 *map)
+{
+ if (!ak_fs_map_v3_is_null(map))
+ {
+ char string[129];
+ ak_fs_sha512sum_struct_to_string(&(map->oh), string);
+ printf(" .oh: %s\n", string);
+ }
+ else
+ {
+ ak_log_debug(__func__,"map is null");
+ }
+}
+
+void ak_fs_map_v3_print_root_hash(akfs_map_v3 *map)
+{
+ if (!ak_fs_map_v3_is_null(map))
+ {
+ char string[129];
+ ak_fs_sha512sum_struct_to_string(&(map->rh), string);
+ printf(" .rh: %s\n", string );
+ }
+ else
+ {
+ ak_log_debug(__func__,"map is null");
+ }
+}
+
+char* ak_fs_map_v3_get_filename(akfs_map_v3 *map)
+{
+ if (!ak_fs_map_v3_is_null(map))
+ {
+ return map->filename;
+ }
+ else
+ {
+ return "";
+ }
+}
+
+void ak_fs_map_v3_print_filename(akfs_map_v3 *map)
+{
+ if (!ak_fs_map_v3_is_null(map))
+ {
+ printf(" .fn: %s\n", ak_fs_map_v3_get_filename(map));
+ }
+}
+
+void ak_fs_map_v3_print_map_hash(akfs_map_v3 *map)
+{
+ if (!ak_fs_map_v3_is_null(map))
+ {
+ char string[129];
+ ak_fs_sha512sum_struct_to_string(&(map->mh), string);
+ printf(" .mh: %s\n", string );
+ }
+}
+
+void ak_fs_map_v3_print(akfs_map_v3 *map)
+{
+ printf("map_v3 {\n");
+ ak_fs_map_v3_print_map_hash(map);
+ ak_fs_map_v3_print_original_hash(map);
+ ak_fs_map_v3_print_root_hash(map);
+ ak_fs_map_v3_print_filename(map);
+ printf("}\n");
+}
+
+int ak_fs_open_map_v3_file(char* maphash, akfs_map_v3 * map)
+{
+ if (map==0x0||map==NULL)
+ {
+ ak_log_debug(__func__, "Zeropointer");
+ return 1;
+ }
+ if ( !ak_fs_verify_input_is_hash(maphash) )
+ {
+ ak_log_debug(__func__,"not a hash");
+ return 1;
+ }
+ FILE *fd;
+ char *full_path = {0};
+ asprintf(&full_path, "%s%s", ak_fs_maps_v3_get_dir(), maphash);
+ // printf("Trying path: %s\n", full_path);
+ fd = fopen(full_path, "rb");
+ if (!fd)
+ {
+ // perror("fopen");
+ return 1;
+ }
+ struct stat sb;
+ if (stat(full_path, &sb) == -1) {
+ perror("stat");
+ return 2;
+ }
+ // File size: %lld in bytes: (long long) sb.st_size);
+ char buffer[(long long) sb.st_size+1];
+ fread(&buffer, sizeof(buffer), (long long) sb.st_size, fd);
+ ak_fs_sha512sum_string_to_struct(maphash, &(map->mh));
+ if ( ak_fs_convert_map_v3_string_to_struct(buffer, strlen(buffer), map) != 0 )
+ {
+ ak_log_debug(__func__,"conversion failed");
+ fclose(fd);
+ return 1;
+ }
+ fclose(fd);
+ return 0;
+}
+
+int ak_fs_map_v3_to_file(akfs_map_v3 maphash)
+{
+ (void)maphash;
+ return 0;
+}