1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2025-03-31 17:25:22 -04:00

Implement PFA initialization

This commit is contained in:
Alex Kotov 2020-11-30 23:07:18 +05:00
parent 67d9ac7e2f
commit 16fd74f0ca
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
2 changed files with 36 additions and 1 deletions

View file

@ -3,10 +3,10 @@
#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_PAGE_SIZE (4 * 1024)
#define KERNAUX_PFA_ZONE_PAGES_COUNT_MAX (1024 * 1024)
#define KERNAUX_PFA_ZONE_PAGE_LIST_SIZE (KERNAUX_PFA_ZONE_PAGES_COUNT_MAX / 8)

View file

@ -1,6 +1,7 @@
#include "config.h"
#include <kernaux/pfa.h>
#include <kernaux/stdlib.h>
kernaux_bool KernAux_PFA_initialize_start(
struct KernAux_PFA *const pfa
@ -14,6 +15,8 @@ kernaux_bool KernAux_PFA_initialize_start(
}
pfa->zones_count = 0;
return KERNAUX_TRUE;
}
kernaux_bool KernAux_PFA_initialize_add_zone(
@ -29,6 +32,34 @@ kernaux_bool KernAux_PFA_initialize_add_zone(
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(
@ -37,4 +68,8 @@ kernaux_bool KernAux_PFA_initialize_finish(
if (pfa->initialized) {
return KERNAUX_FALSE;
}
pfa->initialized = KERNAUX_TRUE;
return KERNAUX_TRUE;
}