From 377e05f4f89bc12aa0112daefdc0270ac49d79f7 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Mon, 30 Nov 2020 23:44:44 +0500 Subject: [PATCH] Remove PFA code --- include/kernaux/pfa.h | 45 --------------------------- src/pfa.c | 72 ------------------------------------------- tests/test_pfa.c | 27 ---------------- 3 files changed, 144 deletions(-) diff --git a/include/kernaux/pfa.h b/include/kernaux/pfa.h index d624008..afde02d 100644 --- a/include/kernaux/pfa.h +++ b/include/kernaux/pfa.h @@ -1,55 +1,10 @@ #ifndef KERNAUX_INCLUDED_PFA #define KERNAUX_INCLUDED_PFA 1 -#include - -#define KERNAUX_PFA_PAGE_SIZE (4 * 1024) -#define KERNAUX_PFA_ZONES_COUNT_MAX 10 -#define KERNAUX_PFA_ZONE_NAME_SIZE_MAX 256 -#define KERNAUX_PFA_ZONE_NAME_SLEN_MAX (KERNAUX_PFA_ZONE_NAME_SIZE_MAX - 1) -#define KERNAUX_PFA_ZONE_PAGES_COUNT_MAX (1024 * 1024) -#define KERNAUX_PFA_ZONE_PAGE_LIST_SIZE (KERNAUX_PFA_ZONE_PAGES_COUNT_MAX / 8) - #ifdef __cplusplus extern "C" { #endif -struct KernAux_PFA_Zone { - char name[KERNAUX_PFA_ZONE_NAME_SIZE_MAX]; - - unsigned long long start; - unsigned long long end; - unsigned long long size; - - unsigned char pages[KERNAUX_PFA_ZONE_PAGE_LIST_SIZE]; - unsigned int pages_count; -}; - -struct KernAux_PFA { - kernaux_bool initialized; - - struct KernAux_PFA_Zone zones[KERNAUX_PFA_ZONES_COUNT_MAX]; - unsigned int zones_count; -}; - -kernaux_bool KernAux_PFA_initialize_start( - struct KernAux_PFA *pfa -) -__attribute__((nonnull)); - -kernaux_bool KernAux_PFA_initialize_add_zone( - struct KernAux_PFA *pfa, - const char *name, - unsigned long long start, - unsigned long long end -) -__attribute__((nonnull)); - -kernaux_bool KernAux_PFA_initialize_finish( - struct KernAux_PFA *pfa -) -__attribute__((nonnull)); - #ifdef __cplusplus } #endif diff --git a/src/pfa.c b/src/pfa.c index 0e36ca1..549a5db 100644 --- a/src/pfa.c +++ b/src/pfa.c @@ -1,75 +1,3 @@ #include "config.h" #include -#include - -kernaux_bool KernAux_PFA_initialize_start( - struct KernAux_PFA *const pfa -) { - if (pfa->initialized) { - return KERNAUX_FALSE; - } - - for (unsigned long long i = 0; i < sizeof(*pfa); ++i) { - *((unsigned char*)pfa + i) = 0; - } - - pfa->zones_count = 0; - - return KERNAUX_TRUE; -} - -kernaux_bool KernAux_PFA_initialize_add_zone( - struct KernAux_PFA *const pfa, - const char *const name, - const unsigned long long start, - const unsigned long long end -) { - if (pfa->initialized) { - return KERNAUX_FALSE; - } - - if (pfa->zones_count >= KERNAUX_PFA_ZONES_COUNT_MAX) { - return KERNAUX_FALSE; - } - - if (start >= end) { - return KERNAUX_FALSE; - } - - if (start % KERNAUX_PFA_PAGE_SIZE != 0) { - return KERNAUX_FALSE; - } - - if ((end + 1) % KERNAUX_PFA_PAGE_SIZE != 0) { - return KERNAUX_FALSE; - } - - const unsigned int name_slen = kernaux_strlen(name); - - if (name_slen > KERNAUX_PFA_ZONE_NAME_SLEN_MAX) { - return KERNAUX_FALSE; - } - - struct KernAux_PFA_Zone *const zone = &pfa->zones[pfa->zones_count++]; - - kernaux_strncpy(zone->name, name, name_slen); - - zone->start = start; - zone->end = end; - zone->size = end - start + 1; - - return KERNAUX_TRUE; -} - -kernaux_bool KernAux_PFA_initialize_finish( - struct KernAux_PFA *const pfa -) { - if (pfa->initialized) { - return KERNAUX_FALSE; - } - - pfa->initialized = KERNAUX_TRUE; - - return KERNAUX_TRUE; -} diff --git a/tests/test_pfa.c b/tests/test_pfa.c index 83b305f..ad60ae7 100644 --- a/tests/test_pfa.c +++ b/tests/test_pfa.c @@ -4,32 +4,5 @@ int main() { - struct KernAux_PFA pfa; - - assert(KernAux_PFA_initialize_start(&pfa)); - - assert(KernAux_PFA_initialize_add_zone( - &pfa, - "foo", - 0, - 16 * 1024 * 1024 - 1 - )); - - assert(KernAux_PFA_initialize_add_zone( - &pfa, - "bar", - 16 * 1024 * 1024, - 896 * 1024 * 1024 - 1 - )); - - assert(KernAux_PFA_initialize_add_zone( - &pfa, - "car", - 896 * 1024 * 1024, - (unsigned long long)4 * 1024 * 1024 * 1024 - 1 - )); - - assert(KernAux_PFA_initialize_finish(&pfa)); - return 0; }