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