1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2024-10-30 11:54:01 -04:00

Remove PFA code

This commit is contained in:
Alex Kotov 2020-11-30 23:44:44 +05:00
parent 8599102102
commit 377e05f4f8
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
3 changed files with 0 additions and 144 deletions

View file

@ -1,55 +1,10 @@
#ifndef KERNAUX_INCLUDED_PFA #ifndef KERNAUX_INCLUDED_PFA
#define KERNAUX_INCLUDED_PFA 1 #define KERNAUX_INCLUDED_PFA 1
#include <kernaux/stdlib.h>
#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 #ifdef __cplusplus
extern "C" { extern "C" {
#endif #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 #ifdef __cplusplus
} }
#endif #endif

View file

@ -1,75 +1,3 @@
#include "config.h" #include "config.h"
#include <kernaux/pfa.h> #include <kernaux/pfa.h>
#include <kernaux/stdlib.h>
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;
}

View file

@ -4,32 +4,5 @@
int main() 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; return 0;
} }