all the python scripts are for python2, and fedora31 requires to be specific
[vsys-scripts.git] / root-context / dcookie.c
1 /* dcookie retrieval vsys entry, required by Chopstix.
2  * The lookup_dcookie system call retrieves a pathname */
3
4 #define __NR_LOOKUP_DCOOKIE 253
5
6 #include <sys/syscall.h>
7 /*#include <asm/page.h>*/
8 #include <stdint.h>
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <errno.h>
12 #include <string.h>
13
14 #define INT64_MAXSZ     "18446744073709551615Z"
15
16 int lookup_dcookie(uint64_t cookie, char * buf, size_t size)
17 {
18                 return syscall(__NR_LOOKUP_DCOOKIE, cookie, buf, size);
19 }
20
21 int main(int argc,char *argv[]) {
22                 /* fs/dcookie.c uses PAGE_SIZE */
23                 char path_buf[16384],dcookie_buf[sizeof(INT64_MAXSZ)];
24
25                 /* In case nothing happens */
26                 path_buf[0]='\0';
27
28                 while (fgets(dcookie_buf, sizeof(dcookie_buf),stdin)) {
29                         if (lookup_dcookie(atoll(dcookie_buf), path_buf, sizeof(path_buf))>0) { 
30                                         printf("%s\n",path_buf);
31                         }
32                         else {
33                                         printf("%% Not found\n");
34                         }
35                 }
36 }