-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcap_file.c
51 lines (33 loc) · 990 Bytes
/
cap_file.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
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define IOCTL_CF_PRB 0x4004e203
int main(int argc, char **argv)
{
char key[] = "test1";
char buf[32];
int fd = open("/cap/cf1", O_RDWR);
if(!fd) {
printf("cannot open /cap/cf1\n"); while(1);
} else
printf("fd = %d\n", fd);
int err = ioctl(fd, IOCTL_CF_PRB, key);
if (err != 0) {
printf( "Error: ioctl %d %s\n", __LINE__, strerror(err));
while(1);
}
int nsize = read(fd, buf, 32);
printf("read %d bytes ('%s') from cap_file with key '%s'\n", nsize, buf, key);
char send[] = "cap filler\n";
printf("let's write '%s' into cap_file and read result back\n", send);
lseek(fd, 0, SEEK_SET);
int wrote = write(fd, send, sizeof(send));
printf("wrote %d bytes\n", wrote);
lseek(fd, 0, SEEK_SET);
memset(buf, 0, 32);
int new_nsize = read(fd, buf, 32);
printf("read %d bytes ('%s') from cap_file with key '%s'\n", new_nsize, buf, key);
return 0;
}