1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <unistd.h>
5
6 #include <private/android_filesystem_config.h>
7 #include <private/fs_config.h>
8
9 #define DO_DEBUG 1
10
11 #define ERROR(fmt,args...) \
12 do { \
13 fprintf(stderr, "%s:%d: ERROR: " fmt, \
14 __FILE__, __LINE__, ##args); \
15 } while (0)
16
17 #if DO_DEBUG
18 #define DEBUG(fmt,args...) \
19 do { fprintf(stderr, "DEBUG: " fmt, ##args); } while(0)
20 #else
21 #define DEBUG(x...) do {} while(0)
22 #endif
23
24 void
print_help(void)25 print_help(void)
26 {
27 fprintf(stderr, "fs_get_stats: retrieve the target file stats "
28 "for the specified file\n");
29 fprintf(stderr, "usage: fs_get_stats cur_perms is_dir filename targetout\n");
30 fprintf(stderr, "\tcur_perms - The current permissions of "
31 "the file\n");
32 fprintf(stderr, "\tis_dir - Is filename is a dir, 1. Otherwise, 0.\n");
33 fprintf(stderr, "\tfilename - The filename to lookup\n");
34 fprintf(stderr, "\ttargetout - The target out path to query device specific FS configs\n");
35 fprintf(stderr, "\n");
36 }
37
38 int
main(int argc,const char * argv[])39 main(int argc, const char *argv[])
40 {
41 char *endptr;
42 char is_dir = 0;
43 unsigned perms = 0;
44 unsigned uid = (unsigned)-1;
45 unsigned gid = (unsigned)-1;
46
47 if (argc < 5) {
48 ERROR("Invalid arguments\n");
49 print_help();
50 exit(-1);
51 }
52
53 perms = (unsigned)strtoul(argv[1], &endptr, 0);
54 if (!endptr || (endptr == argv[1]) || (*endptr != '\0')) {
55 ERROR("current permissions must be a number. Got '%s'.\n", argv[1]);
56 exit(-1);
57 }
58
59 if (!strcmp(argv[2], "1"))
60 is_dir = 1;
61
62 uint64_t capabilities;
63 fs_config(argv[3], is_dir, argv[4], &uid, &gid, &perms, &capabilities);
64 fprintf(stdout, "%d %d 0%o\n", uid, gid, perms);
65
66 return 0;
67 }
68