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"); |
| 28 | fprintf(stderr, "usage: fs_get_stats cur_perms is_dir filename\n"); |
| 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"); |
| 33 | fprintf(stderr, "\n"); |
| 34 | } |
| 35 | |
| 36 | int |
| 37 | main(int argc, const char *argv[]) |
| 38 | { |
| 39 | char *endptr; |
| 40 | char is_dir = 0; |
| 41 | unsigned perms = 0; |
| 42 | unsigned uid = (unsigned)-1; |
| 43 | unsigned gid = (unsigned)-1; |
| 44 | |
| 45 | if (argc < 4) { |
| 46 | ERROR("Invalid arguments\n"); |
| 47 | print_help(); |
| 48 | exit(-1); |
| 49 | } |
| 50 | |
| 51 | perms = (unsigned)strtoul(argv[1], &endptr, 0); |
| 52 | if (!endptr || (endptr == argv[1]) || (*endptr != '\0')) { |
| 53 | ERROR("current permissions must be a number. Got '%s'.\n", argv[1]); |
| 54 | exit(-1); |
| 55 | } |
| 56 | |
| 57 | if (!strcmp(argv[2], "1")) |
| 58 | is_dir = 1; |
| 59 | |
| 60 | fs_config(argv[3], is_dir, &uid, &gid, &perms); |
| 61 | fprintf(stdout, "%d %d 0%o\n", uid, gid, perms); |
| 62 | |
| 63 | return 0; |
| 64 | } |