-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmem_prot.c
38 lines (32 loc) · 899 Bytes
/
mem_prot.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* Copyright: Sima Alexandru (312CA) 2023
*/
#include <string.h>
#include "io.h"
#include "mem_prot.h"
uint8_t parse_perm_str(char *perm_str)
{
uint8_t perm = PROT_NONE;
perm_str = strtok(perm_str, "\n| ");
while (perm_str) {
CHECK_PERM_STRING(perm_str, perm, PROT_READ);
CHECK_PERM_STRING(perm_str, perm, PROT_WRITE);
CHECK_PERM_STRING(perm_str, perm, PROT_EXEC);
CHECK_PERM_STRING(perm_str, perm, PROT_NONE);
perm_str = strtok(NULL, "\n| ");
}
return perm;
}
void get_perm_str(uint8_t perm, char perm_str[PERM_LEN + 1])
{
// Se pleaca de la permisiuni complete, apoi se sterg cele
// nesetate (`perm` & bit_permisiune == 0).
memcpy(perm_str, "RWX", PERM_LEN + 1);
for (uint8_t i = 0; i < PERM_LEN; ++i)
if (~perm & (0b1 << i))
perm_str[PERM_LEN - i - 1] = '-';
}
uint8_t check_perm(miniblock_t *miniblock, enum perm_bits perm)
{
return miniblock->perm & perm;
}