The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 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 | |
| 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 | |
| 23 | void |
| 24 | print_help(void) |
| 25 | { |
| 26 | fprintf(stderr, "fs_get_stats: retrieve the target file stats " |
| 27 | "for the specified file\n"); |
Thierry Strudel | 74a81e6 | 2015-07-09 09:54:55 -0700 | [diff] [blame] | 28 | fprintf(stderr, "usage: fs_get_stats cur_perms is_dir filename targetout\n"); |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 29 | 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 Strudel | 74a81e6 | 2015-07-09 09:54:55 -0700 | [diff] [blame] | 33 | fprintf(stderr, "\ttargetout - The target out path to query device specific FS configs\n"); |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 34 | fprintf(stderr, "\n"); |
| 35 | } |
| 36 | |
| 37 | int |
| 38 | main(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 Strudel | 74a81e6 | 2015-07-09 09:54:55 -0700 | [diff] [blame] | 46 | if (argc < 5) { |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 47 | 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 Kralevich | fa79809 | 2013-02-20 12:43:51 -0800 | [diff] [blame] | 61 | uint64_t capabilities; |
Thierry Strudel | 74a81e6 | 2015-07-09 09:54:55 -0700 | [diff] [blame] | 62 | fs_config(argv[3], is_dir, argv[4], &uid, &gid, &perms, &capabilities); |
The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 63 | fprintf(stdout, "%d %d 0%o\n", uid, gid, perms); |
| 64 | |
| 65 | return 0; |
| 66 | } |