this repo has no description
1#include <stdio.h>
2#include <string.h>
3#include <fcntl.h>
4#include <sys/ioctl.h>
5
6const char* TESTDIR = "/tmp";
7//const char* TESTDIR = "/run/user/1000";
8
9int main(int argc, const char** argv)
10{
11 int lkm = open("/dev/mach", O_RDWR);
12 if (lkm == -1)
13 {
14 perror("open dev mach");
15 return 1;
16 }
17 int dfd = open(TESTDIR, O_RDONLY | O_DIRECTORY);
18 if (dfd == -1)
19 {
20 perror("open dfd");
21 return 1;
22 }
23
24 int rv = ioctl(lkm, NR_vchroot, dfd);
25 if (rv == -1)
26 {
27 perror("NR_vchroot");
28 return 1;
29 }
30
31 struct vchroot_expand_args expand;
32
33 //strcpy(expand.path, "link_to_dir_in_root/file"); // link_to_...
34 strcpy(expand.path, "/test2/file");
35 // strcpy(expand.path, "/proc/self/mounts");
36 expand.flags = 0;
37 expand.dfd = -100;
38
39 rv = ioctl(lkm, NR_vchroot_expand, &expand);
40 if (rv == -1)
41 {
42 perror("NR_vchroot_expand");
43 return 1;
44 }
45
46 printf("Path expanded to %s\n", expand.path);
47
48// int testfilefd = open(expand.path, O_RDONLY);
49// int testfilefd = open("/tmp/dev/null", O_RDONLY);
50 int testfilefd = 0;
51 if (testfilefd == -1)
52 {
53 perror("open test file");
54 return 1;
55 }
56
57 struct vchroot_fdpath_args fdpath;
58
59 fdpath.fd = testfilefd;
60 fdpath.path = malloc(512);
61 fdpath.maxlen = 512;
62
63 rv = ioctl(lkm, NR_vchroot_fdpath, &fdpath);
64 if (rv == -1)
65 {
66 perror("NR_vchroot_fdpath");
67 return 1;
68 }
69
70 printf("Reported fdpath: %s\n", fdpath.path);
71
72 return 0;
73
74}
75