-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinode.c
More file actions
36 lines (30 loc) · 806 Bytes
/
inode.c
File metadata and controls
36 lines (30 loc) · 806 Bytes
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
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <linux/bpf.h>
#include <sys/syscall.h>
#include <sys/types.h>
int32_t add_path(int32_t map_fd, const char* path, const char* host_path) {
int fd = open(path, O_RDONLY);
if (fd <= 0) {
fprintf(stderr, "%s:%d - open error: %d\n", __FILE__, __LINE__, errno);
return errno;
}
char buf[4096];
snprintf(buf, 4096, "%s", host_path);
union bpf_attr attr;
memset(&attr, 0, sizeof(attr));
attr.map_fd = map_fd;
attr.key = (unsigned long long)&fd;
attr.value = (unsigned long long)buf;
attr.flags = BPF_NOEXIST;
long res = syscall(SYS_bpf, BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr));
if (res == -EEXIST) {
res = 0;
}
close(fd);
return res;
}