diff options
author | Mark Salyzyn | 2016-07-06 12:31:05 -0500 |
---|---|---|
committer | Mark Salyzyn | 2016-07-06 12:45:11 -0500 |
commit | 768cbb04044ebd8b800ca69cb00397ad93072c4d (patch) | |
tree | 952fc931e6c6cacd38513719aed1740c6cd9b1d3 | |
parent | 80beb506cf84410608a006cef70198919e0808b7 (diff) | |
download | platform-system-core-768cbb04044ebd8b800ca69cb00397ad93072c4d.tar.gz platform-system-core-768cbb04044ebd8b800ca69cb00397ad93072c4d.tar.xz platform-system-core-768cbb04044ebd8b800ca69cb00397ad93072c4d.zip |
libcutils: canned_fs_config.c drop tabs
- replace tabs with spaces, get indent right
- Sort header order as per Android coding standard
Change-Id: I634f6f716a368ce5565ccc880c51406042f312bf
-rw-r--r-- | libcutils/canned_fs_config.c | 156 |
1 files changed, 81 insertions, 75 deletions
diff --git a/libcutils/canned_fs_config.c b/libcutils/canned_fs_config.c index 580085750..e0e6a3457 100644 --- a/libcutils/canned_fs_config.c +++ b/libcutils/canned_fs_config.c | |||
@@ -14,22 +14,22 @@ | |||
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include <inttypes.h> | ||
18 | #include <stdio.h> | ||
19 | #include <string.h> | ||
20 | #include <errno.h> | 17 | #include <errno.h> |
18 | #include <inttypes.h> | ||
21 | #include <limits.h> | 19 | #include <limits.h> |
20 | #include <stdio.h> | ||
22 | #include <stdlib.h> | 21 | #include <stdlib.h> |
22 | #include <string.h> | ||
23 | 23 | ||
24 | #include <private/android_filesystem_config.h> | 24 | #include <private/android_filesystem_config.h> |
25 | #include <private/canned_fs_config.h> | 25 | #include <private/canned_fs_config.h> |
26 | 26 | ||
27 | typedef struct { | 27 | typedef struct { |
28 | const char* path; | 28 | const char* path; |
29 | unsigned uid; | 29 | unsigned uid; |
30 | unsigned gid; | 30 | unsigned gid; |
31 | unsigned mode; | 31 | unsigned mode; |
32 | uint64_t capabilities; | 32 | uint64_t capabilities; |
33 | } Path; | 33 | } Path; |
34 | 34 | ||
35 | static Path* canned_data = NULL; | 35 | static Path* canned_data = NULL; |
@@ -37,81 +37,87 @@ static int canned_alloc = 0; | |||
37 | static int canned_used = 0; | 37 | static int canned_used = 0; |
38 | 38 | ||
39 | static int path_compare(const void* a, const void* b) { | 39 | static int path_compare(const void* a, const void* b) { |
40 | return strcmp(((Path*)a)->path, ((Path*)b)->path); | 40 | return strcmp(((Path*)a)->path, ((Path*)b)->path); |
41 | } | 41 | } |
42 | 42 | ||
43 | int load_canned_fs_config(const char* fn) { | 43 | int load_canned_fs_config(const char* fn) { |
44 | FILE* f = fopen(fn, "r"); | 44 | char line[PATH_MAX + 200]; |
45 | if (f == NULL) { | 45 | FILE* f; |
46 | fprintf(stderr, "failed to open %s: %s\n", fn, strerror(errno)); | 46 | |
47 | return -1; | 47 | f = fopen(fn, "r"); |
48 | } | 48 | if (f == NULL) { |
49 | 49 | fprintf(stderr, "failed to open %s: %s\n", fn, strerror(errno)); | |
50 | char line[PATH_MAX + 200]; | 50 | return -1; |
51 | while (fgets(line, sizeof(line), f)) { | 51 | } |
52 | while (canned_used >= canned_alloc) { | 52 | |
53 | canned_alloc = (canned_alloc+1) * 2; | 53 | while (fgets(line, sizeof(line), f)) { |
54 | canned_data = (Path*) realloc(canned_data, canned_alloc * sizeof(Path)); | 54 | Path* p; |
55 | } | 55 | char* token; |
56 | Path* p = canned_data + canned_used; | 56 | |
57 | p->path = strdup(strtok(line, " ")); | 57 | while (canned_used >= canned_alloc) { |
58 | p->uid = atoi(strtok(NULL, " ")); | 58 | canned_alloc = (canned_alloc+1) * 2; |
59 | p->gid = atoi(strtok(NULL, " ")); | 59 | canned_data = (Path*) realloc(canned_data, canned_alloc * sizeof(Path)); |
60 | p->mode = strtol(strtok(NULL, " "), NULL, 8); // mode is in octal | 60 | } |
61 | p->capabilities = 0; | 61 | p = canned_data + canned_used; |
62 | 62 | p->path = strdup(strtok(line, " ")); | |
63 | char* token = NULL; | 63 | p->uid = atoi(strtok(NULL, " ")); |
64 | do { | 64 | p->gid = atoi(strtok(NULL, " ")); |
65 | token = strtok(NULL, " "); | 65 | p->mode = strtol(strtok(NULL, " "), NULL, 8); // mode is in octal |
66 | if (token && strncmp(token, "capabilities=", 13) == 0) { | 66 | p->capabilities = 0; |
67 | p->capabilities = strtoll(token+13, NULL, 0); | 67 | |
68 | break; | 68 | do { |
69 | } | 69 | token = strtok(NULL, " "); |
70 | } while (token); | 70 | if (token && strncmp(token, "capabilities=", 13) == 0) { |
71 | 71 | p->capabilities = strtoll(token+13, NULL, 0); | |
72 | canned_used++; | 72 | break; |
73 | } | 73 | } |
74 | 74 | } while (token); | |
75 | fclose(f); | 75 | |
76 | 76 | canned_used++; | |
77 | qsort(canned_data, canned_used, sizeof(Path), path_compare); | 77 | } |
78 | printf("loaded %d fs_config entries\n", canned_used); | 78 | |
79 | 79 | fclose(f); | |
80 | return 0; | 80 | |
81 | qsort(canned_data, canned_used, sizeof(Path), path_compare); | ||
82 | printf("loaded %d fs_config entries\n", canned_used); | ||
83 | |||
84 | return 0; | ||
81 | } | 85 | } |
82 | 86 | ||
83 | static const int kDebugCannedFsConfig = 0; | 87 | static const int kDebugCannedFsConfig = 0; |
84 | 88 | ||
85 | void canned_fs_config(const char* path, int dir, const char* target_out_path, | 89 | void canned_fs_config(const char* path, int dir, const char* target_out_path, |
86 | unsigned* uid, unsigned* gid, unsigned* mode, uint64_t* capabilities) { | 90 | unsigned* uid, unsigned* gid, unsigned* mode, uint64_t* capabilities) { |
87 | Path key; | 91 | Path key, *p; |
92 | |||
88 | key.path = path; | 93 | key.path = path; |
89 | if (path[0] == '/') | 94 | if (path[0] == '/') key.path++; // canned paths lack the leading '/' |
90 | key.path++; // canned paths lack the leading '/' | 95 | p = (Path*) bsearch(&key, canned_data, canned_used, sizeof(Path), path_compare); |
91 | Path* p = (Path*) bsearch(&key, canned_data, canned_used, sizeof(Path), path_compare); | 96 | if (p == NULL) { |
92 | if (p == NULL) { | 97 | fprintf(stderr, "failed to find [%s] in canned fs_config\n", path); |
93 | fprintf(stderr, "failed to find [%s] in canned fs_config\n", path); | 98 | exit(1); |
94 | exit(1); | 99 | } |
95 | } | 100 | *uid = p->uid; |
96 | *uid = p->uid; | 101 | *gid = p->gid; |
97 | *gid = p->gid; | 102 | *mode = p->mode; |
98 | *mode = p->mode; | 103 | *capabilities = p->capabilities; |
99 | *capabilities = p->capabilities; | 104 | |
100 | 105 | if (kDebugCannedFsConfig) { | |
101 | if (kDebugCannedFsConfig) { | 106 | // for debugging, run the built-in fs_config and compare the results. |
102 | // for debugging, run the built-in fs_config and compare the results. | 107 | |
103 | 108 | unsigned c_uid, c_gid, c_mode; | |
104 | unsigned c_uid, c_gid, c_mode; | 109 | uint64_t c_capabilities; |
105 | uint64_t c_capabilities; | 110 | |
106 | fs_config(path, dir, target_out_path, &c_uid, &c_gid, &c_mode, &c_capabilities); | 111 | fs_config(path, dir, target_out_path, &c_uid, &c_gid, &c_mode, &c_capabilities); |
107 | 112 | ||
108 | if (c_uid != *uid) printf("%s uid %d %d\n", path, *uid, c_uid); | 113 | if (c_uid != *uid) printf("%s uid %d %d\n", path, *uid, c_uid); |
109 | if (c_gid != *gid) printf("%s gid %d %d\n", path, *gid, c_gid); | 114 | if (c_gid != *gid) printf("%s gid %d %d\n", path, *gid, c_gid); |
110 | if (c_mode != *mode) printf("%s mode 0%o 0%o\n", path, *mode, c_mode); | 115 | if (c_mode != *mode) printf("%s mode 0%o 0%o\n", path, *mode, c_mode); |
111 | if (c_capabilities != *capabilities) | 116 | if (c_capabilities != *capabilities) { |
112 | printf("%s capabilities %" PRIx64 " %" PRIx64 "\n", | 117 | printf("%s capabilities %" PRIx64 " %" PRIx64 "\n", |
113 | path, | 118 | path, |
114 | *capabilities, | 119 | *capabilities, |
115 | c_capabilities); | 120 | c_capabilities); |
116 | } | 121 | } |
122 | } | ||
117 | } | 123 | } |