blob: 64ef0e23123670e91933209fa967a04ca285fe3c [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>
Tom Cherry7cff1fa2020-03-04 15:24:23 -08007#include <private/fs_config.h>
The Android Open Source Project88b60792009-03-03 19:28:42 -08008
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
24void
25print_help(void)
26{
27 fprintf(stderr, "fs_get_stats: retrieve the target file stats "
28 "for the specified file\n");
Thierry Strudel74a81e62015-07-09 09:54:55 -070029 fprintf(stderr, "usage: fs_get_stats cur_perms is_dir filename targetout\n");
The Android Open Source Project88b60792009-03-03 19:28:42 -080030 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");
Thierry Strudel74a81e62015-07-09 09:54:55 -070034 fprintf(stderr, "\ttargetout - The target out path to query device specific FS configs\n");
The Android Open Source Project88b60792009-03-03 19:28:42 -080035 fprintf(stderr, "\n");
36}
37
38int
39main(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
Thierry Strudel74a81e62015-07-09 09:54:55 -070047 if (argc < 5) {
The Android Open Source Project88b60792009-03-03 19:28:42 -080048 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
Nick Kralevichfa798092013-02-20 12:43:51 -080062 uint64_t capabilities;
Thierry Strudel74a81e62015-07-09 09:54:55 -070063 fs_config(argv[3], is_dir, argv[4], &uid, &gid, &perms, &capabilities);
The Android Open Source Project88b60792009-03-03 19:28:42 -080064 fprintf(stdout, "%d %d 0%o\n", uid, gid, perms);
65
66 return 0;
67}