aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--c_implementation/Makefile.am46
-rw-r--r--c_implementation/src/ak_datetime.c70
-rw-r--r--c_implementation/src/ak_fs.c (renamed from c_implementation/src/akfs.c)140
-rw-r--r--c_implementation/src/ak_fs_defuse.c (renamed from c_implementation/src/akfs_defuse.c)35
-rw-r--r--c_implementation/src/ak_fs_main.c (renamed from c_implementation/src/akfs_main.c)0
-rw-r--r--c_implementation/src/ak_fs_map_v3.c232
-rw-r--r--c_implementation/src/ak_fs_map_v4.c (renamed from c_implementation/src/akfs_map_v4.c)0
-rw-r--r--c_implementation/src/ak_fs_maps_v3.c63
-rw-r--r--c_implementation/src/ak_fs_sha512sum.c (renamed from c_implementation/src/akfs_sha512sum.c)2
-rw-r--r--c_implementation/src/ak_log.c (renamed from c_implementation/src/aklog.c)46
-rw-r--r--c_implementation/src/ak_log_main.c32
-rw-r--r--c_implementation/src/ak_logcatter.c (renamed from c_implementation/src/aklogcatter.c)0
-rw-r--r--c_implementation/src/ak_settings.c (renamed from c_implementation/src/aksettings.c)2
-rw-r--r--c_implementation/src/ak_utils.c (renamed from c_implementation/src/akutils.c)0
-rw-r--r--c_implementation/src/akfs_map_v3.c147
-rw-r--r--c_implementation/src/aklog_main.c6
16 files changed, 498 insertions, 323 deletions
diff --git a/c_implementation/Makefile.am b/c_implementation/Makefile.am
index 57fd80a..9b6cd65 100644
--- a/c_implementation/Makefile.am
+++ b/c_implementation/Makefile.am
@@ -3,45 +3,57 @@ AM_CPPFLAGS = -Wall -Werror -Wextra -Wpedantic -ggdb -I$(top_srcdir)/include
#AM_CFLAGS = -Wall -Werror -Wextra -Wpedantic -ggdb -I$(top_srcdir)/include
lib_LTLIBRARIES = libaklog.la libaksettings.la libakfs.la libakdatetime.la libakutils.la
-libaklog_la_SOURCES = $(top_srcdir)/src/aklog.c
-libaksettings_la_SOURCES = $(top_srcdir)/src/aksettings.c
+libaklog_la_SOURCES = $(top_srcdir)/src/ak_log.c $(top_srcdir)/src/ak_log_main.c
-libakfs_LDADD = libaksettings.la
-libakfs_la_SOURCES = $(top_srcdir)/src/akfs.c $(top_srcdir)/src/aksettings.c $(top_srcdir)/src/akfs_sha512sum.c $(top_srcdir)/src/akfs_map_v3.c $(top_srcdir)/src/akfs_map_v4.c $(top_srcdir)/src/akfs_main.c
+libaksettings_la_SOURCES = $(top_srcdir)/src/ak_settings.c
-libakutils_la_SOURCES = $(top_srcdir)/src/akutils.c
+libakfs_LDADD = libaksettings.la libaklog.la
+libakfs_la_SOURCES = $(top_srcdir)/src/ak_fs.c \
+ $(top_srcdir)/src/ak_fs_main.c \
+ $(top_srcdir)/src/ak_fs_maps_v3.c \
+ $(top_srcdir)/src/ak_fs_map_v3.c \
+ $(top_srcdir)/src/ak_fs_map_v4.c \
+ $(top_srcdir)/src/ak_fs_sha512sum.c
-libakdatetime_la_SOURCES = $(top_srcdir)/src/akdatetime.c
+libakutils_la_SOURCES = $(top_srcdir)/src/ak_utils.c
-include_HEADERS = include/libaklog.h include/libaksettings.h include/libakfs.h
+libakdatetime_la_SOURCES = $(top_srcdir)/src/ak_datetime.c
-bin_PROGRAMS = akt akdefuse aklog akfs
+#include_HEADERS = "$(wildcard include/*.h)"
+include_HEADERS = $(top_srcdir)/include/libaklog.h \
+ $(top_srcdir)/include/libaksettings.h \
+ $(top_srcdir)/include/libakfs.h \
+ $(top_srcdir)/include/libak.h
+
+bin_PROGRAMS = akfs akdefuse #akt akdefuse aklog
akfs_LDADD = libaklog.la libakfs.la libaksettings.la
-akfs_SOURCES = src/akfs_main.c
-akt_SOURCES = src/ak.c
+akfs_SOURCES = src/ak_fs_main.c
+
akt_LDADD = libaklog.la libakfs.la libaksettings.la
akt_SOURCES = src/ak.c
+
akdefuse_CFLAGS = -I/usr/include/fuse3 -lfuse3 -lpthread
akdefuse_LDADD = libaklog.la libakfs.la
-akdefuse_SOURCES = src/akfs_defuse.c
+akdefuse_SOURCES = src/ak_fs_defuse.c
+
aklog_LDADD = libaklog.la
-aklog_SOURCES = src/aklog_main.c
+aklog_SOURCES = src/ak_log_main.c
check_PROGRAMS = test_aklog test_aksettings test_akfs test_akutils test_akdatetime
-test_akdatetime_SOURCES = ./tests/test_akdatetime.c ./src/akdatetime.c
+test_akdatetime_SOURCES = ./tests/test_akdatetime.c ./src/ak_datetime.c
test_akdatetime_LDADD = libakdatetime.la
-test_akutils_SOURCES = ./tests/test_akutils.c ./src/akutils.c
+test_akutils_SOURCES = ./tests/test_akutils.c ./src/ak_utils.c
test_akutils_LDADD = libakutils.la
-test_aklog_SOURCES = ./tests/test_aklog.c ./src/aklog.c
+test_aklog_SOURCES = ./tests/test_aklog.c ./src/ak_log.c
test_aklog_LDADD = libaklog.la
-test_akfs_SOURCES = ./tests/test_akfs.c ./src/akfs.c
+test_akfs_SOURCES = ./tests/test_akfs.c ./src/ak_fs.c
test_akfs_LDADD = libakfs.la libaklog.la
-test_aksettings_SOURCES = ./tests/test_aksettings.c ./src/aksettings.c ./src/aklog.c
+test_aksettings_SOURCES = ./tests/test_aksettings.c ./src/ak_settings.c ./src/ak_log.c
test_aksettings_LDADD = libaksettings.la
tests_test_main_CPPFLAGS = -I$(top_srcdir)/include
diff --git a/c_implementation/src/ak_datetime.c b/c_implementation/src/ak_datetime.c
new file mode 100644
index 0000000..71dcb18
--- /dev/null
+++ b/c_implementation/src/ak_datetime.c
@@ -0,0 +1,70 @@
+#include <libakdatetime.h>
+#include <stdio.h>
+#include <time.h>
+#include <string.h>
+#include <stdbool.h>
+#include <ctype.h>
+#include <stdlib.h>
+
+// Returns Unix timestamp (seconds since epoch)
+long ak_datetime_unix() {
+ return time(NULL);
+}
+
+// Returns Unix timestamp with nanoseconds
+void ak_datetime_unix_nanosecs(char *buffer, size_t size) {
+ struct timespec ts;
+ clock_gettime(CLOCK_REALTIME, &ts);
+ snprintf(buffer, size, "%ld.%09ld", ts.tv_sec, ts.tv_nsec);
+}
+
+// Returns human-readable datetime in format YYYYMMDD_HHMMSS
+void ak_datetime_human(char *buffer, size_t size) {
+ time_t now = time(NULL);
+ const struct tm *tm = gmtime(&now);
+ strftime(buffer, size, "%Y%m%d_%H%M%S", tm);
+}
+
+// Returns human-readable date in format YYYYMMDD
+void ak_datetime_human_date_only(char *buffer, size_t size) {
+ time_t now = time(NULL);
+ const struct tm *tm = gmtime(&now);
+ strftime(buffer, size, "%Y%m%d", tm);
+}
+
+// Returns yesterday's date in format YYYYMMDD
+void ak_datetime_human_date_only_yesterday(char *buffer, size_t size) {
+ time_t now = time(NULL);
+ now -= 24 * 60 * 60; // Subtract one day
+ const struct tm *tm = gmtime(&now);
+ strftime(buffer, size, "%Y%m%d", tm);
+}
+
+// Checks if string contains only digits
+static bool is_digits_only(const char *str) {
+ while (*str) {
+ if (!isdigit(*str)) {
+ return false;
+ }
+ str++;
+ }
+ return true;
+}
+
+// Converts Unix timestamp to human-readable format YYYYMMDD_HHMMSS
+bool ak_datetime_unix_to_human(const char *timestamp_str, char *buffer, size_t size) {
+ // Check if input is valid (10-digit number)
+ if (timestamp_str == NULL || strlen(timestamp_str) != 10 || !is_digits_only(timestamp_str)) {
+ return false;
+ }
+
+ time_t timestamp = (time_t)atol(timestamp_str);
+ const struct tm *tm = gmtime(&timestamp);
+ if (tm == NULL) {
+ return false;
+ }
+
+ strftime(buffer, size, "%Y%m%d_%H%M%S", tm);
+ return true;
+}
+
diff --git a/c_implementation/src/akfs.c b/c_implementation/src/ak_fs.c
index 0e362aa..1d30744 100644
--- a/c_implementation/src/akfs.c
+++ b/c_implementation/src/ak_fs.c
@@ -10,11 +10,6 @@
#include <sys/stat.h>
#include <dirent.h>
-const char* ak_fs_maps_v3_get_dir()
-{
- return getenv("AK_MAPSDIR");
-}
-
char* ak_fs_return_hash_path(const char* str)
{
if ( ak_fs_verify_input_is_hash(str) )
@@ -185,13 +180,13 @@ int ak_fs_convert_map_v3_string_to_struct(const char *str, size_t ssize, akfs_ma
{
if ( str[i] == ' ' )
{
- spaces_found++;
- sa[spaces_found] = i;
+ // spaces_found++;
+ sa[++spaces_found] = i;
}
if ( str[i] == '\n' )
{
- newlines_found++;
- na[newlines_found] = i;
+ // newlines_found++;
+ na[++newlines_found] = i;
}
}
int si = 0;
@@ -260,60 +255,37 @@ void ak_fs_get_available_maps_from_fs(sha512sum **ma, size_t length)
closedir(d);
}
-int ak_fs_load_available_maps(sha512sum **ma, size_t ma_len, akfs_map_v3 **ms, size_t ms_len)
+int ak_fs_map_v3_resolve_maps(akfs_map_v3 **ms, size_t ms_len)
{
- sha512sum *ptr = NULL;
- akfs_map_v3 *mptr = NULL;
- mptr = *ms;
- (void)ms_len;
- for ( ptr = *ma; ptr < *ma+ma_len; ++ptr)
+ akfs_map_v3 *ptr = NULL;
+ for ( ptr = *ms; ptr < *ms+ms_len; ++ptr)
{
- if ( ak_fs_sha512sum_is_null(ptr))
+ if ( ak_fs_sha512sum_is_null(&(ptr->mh)) )
{
continue;
}
- if( ak_fs_open_map_v3_file(ak_fs_sha512sum_struct_read_as_string(ptr), mptr) != 2)
+ if( ak_fs_map_v3_open_from_file(ptr) != 2)
{
- ++(mptr);
+ ++(ptr);
continue;
}
else
{
- ++(mptr);
+ ++(ptr);
// return 1;
}
}
return 0;
}
-void ak_fs_print_loaded_maps(akfs_map_v3 **map_store, size_t length)
-{
- akfs_map_v3 *ptr = NULL;
- for ( ptr = *map_store; ptr < *map_store + length; ++ptr)
- {
- if ( !ak_fs_map_v3_is_null(ptr) ) ak_fs_map_v3_print(ptr);
- }
-}
-
-bool ak_fs_map_v3_compare(akfs_map_v3* a, akfs_map_v3* b)
-{
- return (
- (ak_fs_sha512sum_compare(&a->oh, &b->oh) == true) &&
- (ak_fs_sha512sum_compare(&a->rh, &b->rh) == true) &&
- (ak_fs_sha512sum_compare(&a->mh, &b->mh) == true) &&
- (strcmp(a->filename, b->filename) == 0)
- );
-}
-
-void ak_fs_print_available_maps(sha512sum **ma, size_t ma_len)
-{
- sha512sum *ptr = NULL;
- for ( ptr = *ma; ptr < *ma+ma_len; ++ptr)
- {
- ak_log_debug(__func__, ak_fs_sha512sum_struct_read_as_string(ptr));
- }
-
-}
+// void ak_fs_print_available_maps(sha512sum **ma, size_t ma_len)
+// {
+// sha512sum *ptr = NULL;
+// for ( ptr = *ma; ptr < *ma+ma_len; ++ptr)
+// {
+// ak_log_debug(__func__, ak_fs_sha512sum_struct_read_as_string(ptr));
+// }
+// }
void ak_fs_init_string(char *str, size_t len)
{
@@ -323,66 +295,38 @@ void ak_fs_init_string(char *str, size_t len)
}
}
-
-void ak_fs_print_map_avail(const sha512sum* m)
-{
- printf(" .MA: %s\n", ak_fs_sha512sum_struct_read_as_string(m));
-}
-
-void ak_fs_print_map_all_avail(sha512sum** m, size_t s)
-{
- sha512sum *ptr = NULL;
- for (ptr = *m; ptr < *m+s; ++ptr)
- {
- ak_fs_print_map_avail(ptr);
- }
-}
-
-void ak_fs_print_filenames_from_map_store(akfs_map_v3** m, size_t s)
-{
- akfs_map_v3 *ptr = NULL;
- for (ptr = *m; ptr < *m+s; ++ptr)
- {
- if ( !ak_fs_map_v3_is_null(ptr) ) ak_fs_map_v3_print_filename(ptr);
- }
-}
-
-// char* ak_fs_fuse_list_filenames_from_map_store(akfs_map_v3** m, size_t s)
+// void ak_fs_print_map_avail(const sha512sum* m)
+// {
+// printf(" .MA: %s\n", ak_fs_sha512sum_struct_read_as_string(m));
+// }
+//
+// void ak_fs_print_map_all_avail(sha512sum** m, size_t s)
// {
-// akfs_map_v3 *ptr = NULL;
+// sha512sum *ptr = NULL;
// for (ptr = *m; ptr < *m+s; ++ptr)
// {
-// if ( !ak_fs_map_v3_is_null(ptr) ) ak_fs_map_v3_get_filename(ptr);
+// ak_fs_print_map_avail(ptr);
// }
// }
-void ak_fs_print_all_maps_from_map_store(akfs_map_v3** m, size_t s)
-{
- akfs_map_v3 *ptr = NULL;
- for (ptr = *m; ptr < *m+s; ++ptr)
- {
- if (!ak_fs_map_v3_is_null(ptr)) ak_fs_map_v3_print(ptr);
- }
-}
-
int ak_fs_ls()
{
- size_t ms_len = 100;
- size_t ma_len = 100;
- akfs_map_v3 map_store[ms_len];
- akfs_map_v3* mps_ptr = &map_store[0];
+ size_t len = ak_fs_maps_v3_found_in_fs();
+ printf("Found: %lu\n", len);
+ akfs_map_v3 map_store[len];
+ akfs_map_v3* maps_ptr = &map_store[0];
void* mps_start = &map_store[0];
(void)mps_start;
- sha512sum maps_avail[ma_len];
- sha512sum *mav_ptr = &maps_avail[0];
- void* mav_start = &map_store[0];
- (void)mav_start;
- ak_fs_map_v3_init_store(&mps_ptr, ms_len);
- ak_fs_sha512sum_init_avail(&mav_ptr, ma_len);
- ak_fs_print_all_maps_from_map_store(&mps_ptr, ms_len);
- ak_fs_get_available_maps_from_fs(&mav_ptr, ma_len);
- ak_fs_load_available_maps(&mav_ptr, ma_len, &mps_ptr, ms_len);
- ak_fs_print_loaded_maps(&mps_ptr, ms_len);
- ak_fs_print_filenames_from_map_store(&mps_ptr, ms_len);
+ ak_fs_maps_v3_init(&maps_ptr, len);
+ ak_fs_maps_v3_print(&maps_ptr, len);
+
+ // TODO Rename the following to "ak_fs_resolve_map_v3_array" or close to it
+ ak_fs_map_v3_resolve_maps(&maps_ptr, len);
+
+ // TODO Decide what we should be printing
+ // Possibly, something like "maphex(6)_filename" so we can put multiple
+ // files with the same name into the list
+ ak_fs_maps_v3_print(&maps_ptr, len);
+ ak_fs_maps_v3_print_filenames(&maps_ptr, len);
return 0;
}
diff --git a/c_implementation/src/akfs_defuse.c b/c_implementation/src/ak_fs_defuse.c
index da0c3d0..10617cc 100644
--- a/c_implementation/src/akfs_defuse.c
+++ b/c_implementation/src/ak_fs_defuse.c
@@ -37,36 +37,37 @@ static int akfs_fuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler
if (strcmp(path, "/") != 0) // Only support root dir
return -ENOENT;
- filler(buf, ".", NULL, 0, 0); // Current dir
- filler(buf, "..", NULL, 0, 0); // Parent dir
- filler(buf, "hello", NULL, 0, 0); // Our file
- size_t ms_len = 100;
- size_t ma_len = 100;
+ filler(buf, ".", NULL, 0, 0);
+ filler(buf, "..", NULL, 0, 0);
+
+ // example file
+ filler(buf, "hello", NULL, 0, 0);
+
+ // ak fs integration
+ size_t ms_len = ak_fs_maps_v3_found_in_fs();
akfs_map_v3 map_store[ms_len];
akfs_map_v3* mps_ptr = &map_store[0];
void* mps_start = &map_store[0];
(void)mps_start;
- sha512sum maps_avail[ma_len];
- sha512sum *mav_ptr = &maps_avail[0];
- void* mav_start = &map_store[0];
- (void)mav_start;
- ak_fs_map_v3_init_store(&mps_ptr, ms_len);
- ak_fs_sha512sum_init_avail(&mav_ptr, ma_len);
- ak_fs_get_available_maps_from_fs(&mav_ptr, ma_len);
- ak_fs_load_available_maps(&mav_ptr, ma_len, &mps_ptr, ms_len);
+ ak_fs_maps_v3_init(&mps_ptr, ms_len);
+ ak_fs_map_v3_resolve_maps(&mps_ptr, ms_len);
akfs_map_v3 *ptr = NULL;
for (ptr = mps_ptr; ptr < mps_ptr + ms_len; ++ptr)
{
- if ( !ak_fs_map_v3_is_null(ptr) ) ak_fs_map_v3_print_filename(ptr);
- filler(buf, ak_fs_map_v3_get_filename(ptr), NULL, 0, 0);
+ if ( ak_fs_map_v3_is_null(ptr) )
+ {
+ ak_fs_map_v3_print_filename(ptr);
+ filler(buf, ak_fs_map_v3_get_filename(ptr), NULL, 0, 0);
+ }
}
- return 0;
+
+ return 0;
}
// Called to get file attributes (metadata)
static int akfs_fuse_getattr(const char *path, struct stat *st, struct fuse_file_info *fi)
{
- (void) fi; // Unused
+ (void) fi;
st->st_uid = getuid();
st->st_gid = getgid();
st->st_atime = st->st_mtime = time(NULL);
diff --git a/c_implementation/src/akfs_main.c b/c_implementation/src/ak_fs_main.c
index f1660cf..f1660cf 100644
--- a/c_implementation/src/akfs_main.c
+++ b/c_implementation/src/ak_fs_main.c
diff --git a/c_implementation/src/ak_fs_map_v3.c b/c_implementation/src/ak_fs_map_v3.c
new file mode 100644
index 0000000..1b26d89
--- /dev/null
+++ b/c_implementation/src/ak_fs_map_v3.c
@@ -0,0 +1,232 @@
+#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);
+}
+
+bool ak_fs_map_v3_compare(akfs_map_v3* a, akfs_map_v3* b)
+{
+ return (
+ (ak_fs_sha512sum_compare(&a->oh, &b->oh) == true) &&
+ (ak_fs_sha512sum_compare(&a->rh, &b->rh) == true) &&
+ (ak_fs_sha512sum_compare(&a->mh, &b->mh) == true) &&
+ (strcmp(a->filename, b->filename) == 0)
+ );
+}
+
+
+bool ak_fs_map_v3_is_null(akfs_map_v3* m)
+{
+ akfs_map_v3 n;
+ ak_fs_map_v3_init(&n);
+ if ( ak_fs_map_v3_compare(m, &n) )
+ {
+ ak_log_debug(__func__, "true");
+ }
+ else
+ {
+ ak_log_debug(__func__, "false");
+ }
+ return ak_fs_map_v3_compare(m, &n);
+}
+
+void ak_fs_map_v3_print_map_hash(akfs_map_v3 *map)
+{
+ if( !ak_fs_sha512sum_is_null(&(map->mh)) )
+ {
+ char str[129] = {0};
+ char* s = &str[0];
+ ak_fs_sha512sum_struct_to_string(&(map->mh), s);
+ printf("%s", s);
+ }
+ else
+ {
+ ak_log_debug(__func__,"hash is null");
+ }
+}
+
+void ak_fs_map_v3_print_original_hash(akfs_map_v3 *map)
+{
+ if (!ak_fs_sha512sum_is_null(&(map->oh)))
+ {
+ printf("%s", ak_fs_sha512sum_struct_read_as_string(&(map->oh)));
+ }
+ else
+ {
+ ak_log_debug(__func__,"hash is null");
+ }
+}
+
+void ak_fs_map_v3_print_root_hash(akfs_map_v3 *map)
+{
+ if (!ak_fs_sha512sum_is_null(&(map->rh)))
+ {
+ printf("%s", ak_fs_sha512sum_struct_read_as_string(&(map->rh)));
+ }
+ else
+ {
+ ak_log_debug(__func__,"hash is null");
+ }
+}
+
+sha512sum* ak_fs_map_v3_get_map_hash(akfs_map_v3 *map)
+{
+ return &(map->mh);
+}
+
+char* ak_fs_map_v3_get_root_hash(akfs_map_v3 *map)
+{
+ if (!ak_fs_sha512sum_is_null(&(map->rh)))
+ {
+ return ak_fs_sha512sum_struct_read_as_string(&(map->rh));
+ }
+ else
+ {
+ return "";
+ }
+}
+
+char* ak_fs_map_v3_get_filename(akfs_map_v3 *map)
+{
+ return map->filename;
+}
+
+void ak_fs_map_v3_print_filename(akfs_map_v3 *map)
+{
+ printf(" .fn: %s\n", ak_fs_map_v3_get_filename(map));
+}
+
+void ak_fs_map_v3_print(akfs_map_v3 *map)
+{
+ printf("map_v3 {\n");
+ printf("\n .mh: ");
+ ak_fs_map_v3_print_map_hash(map);
+ printf("\n .oh: ");
+ ak_fs_map_v3_print_original_hash(map);
+ printf("\n .rh: ");
+ ak_fs_map_v3_print_root_hash(map);
+ printf("\n .fn: ");
+ ak_fs_map_v3_print_filename(map);
+ printf("\n}\n");
+}
+
+void ak_fs_map_v3_print_as_json(akfs_map_v3 *map)
+{
+ printf("{\"type\":\"map_v3\",");
+ printf("\"map\":\"");
+ ak_fs_map_v3_print_map_hash(map);
+ printf("\",");
+ printf("{\"original\":\"");
+ ak_fs_map_v3_print_original_hash(map);
+ printf("\",");
+ printf("{\"root\":\"");
+ ak_fs_map_v3_print_root_hash(map);
+ printf("\",");
+ printf("{\"filename\":\"");
+ ak_fs_map_v3_print_filename(map);
+ printf("\"");
+ printf("}\n");
+}
+
+int ak_fs_map_v3_open_from_file(akfs_map_v3 * map)
+{
+ ak_log_debug(__func__, "Started");
+ if (map==0x0)
+ {
+ ak_log_debug(__func__, "Zeropointer");
+ return 1;
+ }
+ FILE *fd;
+ char *full_path = {0};
+ asprintf(&full_path,
+ "%s/%s",
+ ak_fs_maps_v3_get_dir(),
+ ak_fs_sha512sum_struct_read_as_string(ak_fs_map_v3_get_map_hash(map))
+ );
+ // printf("Trying path: %s\n", full_path);
+ fd = fopen(full_path, "rb");
+ if (!fd)
+ {
+ // perror("fopen");
+ ak_log_debug(__func__, "File not found or other error");
+ return 1;
+ }
+ struct stat sb;
+ if (stat(full_path, &sb) == -1) {
+ perror("stat");
+ fclose(fd);
+ 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_open_map_v3_file(char* maphash, akfs_map_v3 * map)
+{
+ ak_log_debug(__func__, "Started");
+ if (map==0x0)
+ {
+ 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");
+ ak_log_debug(__func__, "file not found");
+ return 1;
+ }
+ struct stat sb;
+ if (stat(full_path, &sb) == -1) {
+ perror("stat");
+ fclose(fd);
+ 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;
+}
diff --git a/c_implementation/src/akfs_map_v4.c b/c_implementation/src/ak_fs_map_v4.c
index 3fea244..3fea244 100644
--- a/c_implementation/src/akfs_map_v4.c
+++ b/c_implementation/src/ak_fs_map_v4.c
diff --git a/c_implementation/src/ak_fs_maps_v3.c b/c_implementation/src/ak_fs_maps_v3.c
new file mode 100644
index 0000000..9b047b0
--- /dev/null
+++ b/c_implementation/src/ak_fs_maps_v3.c
@@ -0,0 +1,63 @@
+#include <libakfs.h>
+#include <stdlib.h>
+#include <dirent.h>
+
+const char* ak_fs_maps_v3_get_dir()
+{
+ return getenv("AK_MAPSDIR");
+}
+
+void ak_fs_maps_v3_init(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_maps_v3_print_map_hashes(akfs_map_v3** m, size_t s)
+{
+ akfs_map_v3 *ptr = NULL;
+ for (ptr = *m; ptr < *m+s; ++ptr)
+ {
+ if ( !ak_fs_map_v3_is_null(ptr) ) ak_fs_map_v3_print_map_hash(ptr);
+ }
+}
+
+void ak_fs_maps_v3_print_filenames(akfs_map_v3** m, size_t s)
+{
+ akfs_map_v3 *ptr = NULL;
+ for (ptr = *m; ptr < *m+s; ++ptr)
+ {
+ if ( ptr != NULL ) ak_fs_map_v3_print_filename(ptr);
+ }
+}
+
+void ak_fs_maps_v3_print(akfs_map_v3 **map_store, size_t length)
+{
+ akfs_map_v3 *ptr = NULL;
+ for ( ptr = *map_store; ptr < *map_store + length; ++ptr)
+ {
+ ak_fs_map_v3_print(ptr);
+ ak_fs_map_v3_print_as_json(ptr);
+ }
+}
+
+
+size_t ak_fs_maps_v3_found_in_fs()
+{
+ DIR *d;
+ size_t counter = 0;
+ d = opendir(ak_fs_maps_v3_get_dir());
+ if (d)
+ {
+ const struct dirent *dir;
+ while ((dir = readdir(d)) != NULL )
+ {
+ if (ak_fs_verify_input_is_hash(dir->d_name)) counter++;
+ }
+ }
+ closedir(d);
+ return counter;
+}
diff --git a/c_implementation/src/akfs_sha512sum.c b/c_implementation/src/ak_fs_sha512sum.c
index 6db6397..2e10544 100644
--- a/c_implementation/src/akfs_sha512sum.c
+++ b/c_implementation/src/ak_fs_sha512sum.c
@@ -1,4 +1,5 @@
#include <libakfs.h>
+#include <libaklog.h>
#include <stdlib.h>
#include <assert.h>
@@ -40,6 +41,7 @@ char* ak_fs_sha512sum_struct_read_as_string(const sha512sum *ptr)
{
char *str = malloc(129*sizeof(char));
ak_fs_sha512sum_struct_to_string(ptr, str);
+ ak_log_debug(__func__, str);
return str;
}
diff --git a/c_implementation/src/aklog.c b/c_implementation/src/ak_log.c
index 260621c..e3af865 100644
--- a/c_implementation/src/aklog.c
+++ b/c_implementation/src/ak_log.c
@@ -85,24 +85,24 @@ void ak_log_print_log_line(const char* line)
}
timeInfo = localtime(&ts);
strftime(ts_string, sizeof(ts_string), "%Y%m%d_%H%M%S", timeInfo);
- printf("%s", ts_string);
- printf(" \033[1;32m");
+ fprintf(stderr, "%s", ts_string);
+ fprintf(stderr, " \033[1;32m");
for ( int k = sa[1]+1; k < sa[2]; ++k)
{
- printf("%c", line[k]);
+ fprintf(stderr, "%c", line[k]);
}
- printf("\033[0m \033[1;31m");
+ fprintf(stderr, "\033[0m \033[1;31m");
for ( int k = sa[2]+1; k < sa[3]; ++k)
{
- printf("%c", line[k]);
+ fprintf(stderr, "%c", line[k]);
}
- printf("\033[0m ");
+ fprintf(stderr, "\033[0m ");
for ( size_t k = sa[3]+1; k < strlen(line); ++k)
{
- printf("%c", line[k]);
+ fprintf(stderr, "%c", line[k]);
}
- printf("\033[0m");
- printf("\n");
+ fprintf(stderr, "\033[0m");
+ fprintf(stderr, "\n");
}
void ak_log_follow()
@@ -238,31 +238,3 @@ void ak_log_test(const char* program, char* message)
{
ak_log_message(program, TEST, message);
}
-
-static int ak_log_usage()
-{
- ak_log_info(__func__, "Available commands:");
- ak_log_info(__func__, " ak_log");
- return 1;
-}
-
-int ak_log_main(int argc, char **argv)
-{
- int option;
- while ( (option = getopt(argc, argv, ":h|:help")) != -1 )
- {
- printf("%d\n", option);
- switch(option)
- {
- case 'h':
- return ak_log_usage();
- case ':':
- printf("kek\n");
- return 1;
- case '?':
- printf("lol\n");
- return 2;
- }
- }
- return 0;
-}
diff --git a/c_implementation/src/ak_log_main.c b/c_implementation/src/ak_log_main.c
new file mode 100644
index 0000000..abeb691
--- /dev/null
+++ b/c_implementation/src/ak_log_main.c
@@ -0,0 +1,32 @@
+#include <getopt.h>
+#include <libaklog.h>
+
+static int ak_log_usage()
+{
+ ak_log_info(__func__, "Available commands:");
+ ak_log_info(__func__, " ak_log");
+ return 1;
+}
+
+int ak_log_main(int argc, char **argv)
+{
+ int option;
+ while ( (option = getopt(argc, argv, ":h|:help")) != -1 )
+ {
+ switch(option)
+ {
+ case 'h':
+ return ak_log_usage();
+ case ':':
+ return 1;
+ case '?':
+ return 2;
+ }
+ }
+ return 0;
+}
+
+int main(int argc, char** argv)
+{
+ return ak_log_main(argc, argv);
+}
diff --git a/c_implementation/src/aklogcatter.c b/c_implementation/src/ak_logcatter.c
index c002eda..c002eda 100644
--- a/c_implementation/src/aklogcatter.c
+++ b/c_implementation/src/ak_logcatter.c
diff --git a/c_implementation/src/aksettings.c b/c_implementation/src/ak_settings.c
index af390cb..324eda2 100644
--- a/c_implementation/src/aksettings.c
+++ b/c_implementation/src/ak_settings.c
@@ -76,7 +76,7 @@ void ak_settings_free_settings() {
settings_count = 0;
}
-int ak_settings_find_setting(const char *key) {
+static int ak_settings_find_setting(const char *key) {
for (int i = 0; i < settings_count; i++) {
if (strcmp(settings[i].key, key) == 0) {
return i;
diff --git a/c_implementation/src/akutils.c b/c_implementation/src/ak_utils.c
index d58e0a3..d58e0a3 100644
--- a/c_implementation/src/akutils.c
+++ b/c_implementation/src/ak_utils.c
diff --git a/c_implementation/src/akfs_map_v3.c b/c_implementation/src/akfs_map_v3.c
deleted file mode 100644
index a422b6c..0000000
--- a/c_implementation/src/akfs_map_v3.c
+++ /dev/null
@@ -1,147 +0,0 @@
-#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);
- }
-}
-
-bool ak_fs_map_v3_is_null(akfs_map_v3* m)
-{
- akfs_map_v3 n;
- ak_fs_map_v3_init(&n);
- return ak_fs_map_v3_compare(m, &n);
-}
-
-void ak_fs_map_v3_print_original_hash(akfs_map_v3 *map)
-{
- if (!ak_fs_map_v3_is_null(map))
- {
- char str[129];
- ak_fs_sha512sum_struct_to_string(&(map->oh), str);
- printf(" .oh: %s\n", str);
- }
- 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 str[129];
- ak_fs_sha512sum_struct_to_string(&(map->rh), str);
- printf(" .rh: %s\n", str );
- }
- 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("%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 str[129];
- ak_fs_sha512sum_struct_to_string(&(map->mh), str);
- printf(" .mh: %s\n", str );
- }
-}
-
-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);