The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | |
Vincent Donnefort | 99ab521 | 2023-01-04 10:33:18 +0000 | [diff] [blame^] | 2 | #include <error.h> |
| 3 | #include <errno.h> |
Vincent Donnefort | 7f01774 | 2022-12-20 11:22:26 +0000 | [diff] [blame] | 4 | #include <getopt.h> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 5 | #include <stdio.h> |
| 6 | #include <stdlib.h> |
| 7 | #include <unistd.h> |
| 8 | #include <string.h> |
Doug Zongker | f2c3a83 | 2012-05-03 15:55:56 -0700 | [diff] [blame] | 9 | #include <ctype.h> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 10 | |
| 11 | #include <sys/types.h> |
| 12 | #include <sys/stat.h> |
Vincent Donnefort | c297135 | 2022-12-20 11:25:49 +0000 | [diff] [blame] | 13 | #include <sys/sysmacros.h> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 14 | #include <dirent.h> |
| 15 | |
| 16 | #include <stdarg.h> |
| 17 | #include <fcntl.h> |
| 18 | |
Vincent Donnefort | 99ab521 | 2023-01-04 10:33:18 +0000 | [diff] [blame^] | 19 | #include <linux/kdev_t.h> |
| 20 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 21 | #include <private/android_filesystem_config.h> |
Tom Cherry | 6ad4d0a | 2020-03-04 13:35:28 -0800 | [diff] [blame] | 22 | #include <private/fs_config.h> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 23 | |
| 24 | /* NOTES |
| 25 | ** |
| 26 | ** - see buffer-format.txt from the linux kernel docs for |
| 27 | ** an explanation of this file format |
| 28 | ** - dotfiles are ignored |
| 29 | ** - directories named 'root' are ignored |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 30 | */ |
| 31 | |
Mateus Azis | 023f67b | 2022-07-12 15:38:47 -0700 | [diff] [blame] | 32 | static void die(const char* why, ...) { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 33 | va_list ap; |
| 34 | |
| 35 | va_start(ap, why); |
| 36 | fprintf(stderr,"error: "); |
| 37 | vfprintf(stderr, why, ap); |
| 38 | fprintf(stderr,"\n"); |
| 39 | va_end(ap); |
| 40 | exit(1); |
| 41 | } |
| 42 | |
Doug Zongker | f2c3a83 | 2012-05-03 15:55:56 -0700 | [diff] [blame] | 43 | struct fs_config_entry { |
| 44 | char* name; |
| 45 | int uid, gid, mode; |
| 46 | }; |
| 47 | |
| 48 | static struct fs_config_entry* canned_config = NULL; |
Mateus Azis | 023f67b | 2022-07-12 15:38:47 -0700 | [diff] [blame] | 49 | static const char* target_out_path = NULL; |
Doug Zongker | f2c3a83 | 2012-05-03 15:55:56 -0700 | [diff] [blame] | 50 | |
| 51 | /* Each line in the canned file should be a path plus three ints (uid, |
| 52 | * gid, mode). */ |
Doug Zongker | a865f6d | 2012-05-04 16:45:35 -0700 | [diff] [blame] | 53 | #ifdef PATH_MAX |
Doug Zongker | f2c3a83 | 2012-05-03 15:55:56 -0700 | [diff] [blame] | 54 | #define CANNED_LINE_LENGTH (PATH_MAX+100) |
Doug Zongker | a865f6d | 2012-05-04 16:45:35 -0700 | [diff] [blame] | 55 | #else |
| 56 | #define CANNED_LINE_LENGTH (1024) |
| 57 | #endif |
Doug Zongker | f2c3a83 | 2012-05-03 15:55:56 -0700 | [diff] [blame] | 58 | |
Tao Bao | 3b5fbd8 | 2016-10-07 10:20:52 -0700 | [diff] [blame] | 59 | #define TRAILER "TRAILER!!!" |
| 60 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 61 | static int verbose = 0; |
| 62 | static int total_size = 0; |
| 63 | |
| 64 | static void fix_stat(const char *path, struct stat *s) |
| 65 | { |
Nick Kralevich | e9e74f3 | 2013-02-07 14:22:12 -0800 | [diff] [blame] | 66 | uint64_t capabilities; |
Doug Zongker | f2c3a83 | 2012-05-03 15:55:56 -0700 | [diff] [blame] | 67 | if (canned_config) { |
| 68 | // Use the list of file uid/gid/modes loaded from the file |
| 69 | // given with -f. |
| 70 | |
| 71 | struct fs_config_entry* empty_path_config = NULL; |
| 72 | struct fs_config_entry* p; |
| 73 | for (p = canned_config; p->name; ++p) { |
| 74 | if (!p->name[0]) { |
| 75 | empty_path_config = p; |
| 76 | } |
| 77 | if (strcmp(p->name, path) == 0) { |
| 78 | s->st_uid = p->uid; |
| 79 | s->st_gid = p->gid; |
| 80 | s->st_mode = p->mode | (s->st_mode & ~07777); |
| 81 | return; |
| 82 | } |
| 83 | } |
| 84 | s->st_uid = empty_path_config->uid; |
| 85 | s->st_gid = empty_path_config->gid; |
| 86 | s->st_mode = empty_path_config->mode | (s->st_mode & ~07777); |
| 87 | } else { |
| 88 | // Use the compiled-in fs_config() function. |
Mark Salyzyn | 5ce7575 | 2014-05-15 15:05:25 -0700 | [diff] [blame] | 89 | unsigned st_mode = s->st_mode; |
Tao Bao | 3b5fbd8 | 2016-10-07 10:20:52 -0700 | [diff] [blame] | 90 | int is_dir = S_ISDIR(s->st_mode) || strcmp(path, TRAILER) == 0; |
| 91 | fs_config(path, is_dir, target_out_path, &s->st_uid, &s->st_gid, &st_mode, &capabilities); |
Mark Salyzyn | 5ce7575 | 2014-05-15 15:05:25 -0700 | [diff] [blame] | 92 | s->st_mode = (typeof(s->st_mode)) st_mode; |
Doug Zongker | f2c3a83 | 2012-05-03 15:55:56 -0700 | [diff] [blame] | 93 | } |
Vincent Donnefort | c297135 | 2022-12-20 11:25:49 +0000 | [diff] [blame] | 94 | |
| 95 | if (S_ISREG(s->st_mode) || S_ISDIR(s->st_mode) || S_ISLNK(s->st_mode)) { |
| 96 | s->st_rdev = 0; |
| 97 | } |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | static void _eject(struct stat *s, char *out, int olen, char *data, unsigned datasize) |
| 101 | { |
| 102 | // Nothing is special about this value, just picked something in the |
| 103 | // approximate range that was being used already, and avoiding small |
| 104 | // values which may be special. |
| 105 | static unsigned next_inode = 300000; |
| 106 | |
| 107 | while(total_size & 3) { |
| 108 | total_size++; |
| 109 | putchar(0); |
| 110 | } |
| 111 | |
| 112 | fix_stat(out, s); |
| 113 | // fprintf(stderr, "_eject %s: mode=0%o\n", out, s->st_mode); |
| 114 | |
| 115 | printf("%06x%08x%08x%08x%08x%08x%08x" |
| 116 | "%08x%08x%08x%08x%08x%08x%08x%s%c", |
| 117 | 0x070701, |
| 118 | next_inode++, // s.st_ino, |
| 119 | s->st_mode, |
| 120 | 0, // s.st_uid, |
| 121 | 0, // s.st_gid, |
| 122 | 1, // s.st_nlink, |
| 123 | 0, // s.st_mtime, |
| 124 | datasize, |
| 125 | 0, // volmajor |
| 126 | 0, // volminor |
Vincent Donnefort | c297135 | 2022-12-20 11:25:49 +0000 | [diff] [blame] | 127 | major(s->st_rdev), |
| 128 | minor(s->st_rdev), |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 129 | olen + 1, |
| 130 | 0, |
| 131 | out, |
| 132 | 0 |
| 133 | ); |
| 134 | |
| 135 | total_size += 6 + 8*13 + olen + 1; |
| 136 | |
Doug Zongker | f2c3a83 | 2012-05-03 15:55:56 -0700 | [diff] [blame] | 137 | if(strlen(out) != (unsigned int)olen) die("ACK!"); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 138 | |
| 139 | while(total_size & 3) { |
| 140 | total_size++; |
| 141 | putchar(0); |
| 142 | } |
| 143 | |
| 144 | if(datasize) { |
| 145 | fwrite(data, datasize, 1, stdout); |
| 146 | total_size += datasize; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | static void _eject_trailer() |
| 151 | { |
| 152 | struct stat s; |
| 153 | memset(&s, 0, sizeof(s)); |
Tao Bao | 3b5fbd8 | 2016-10-07 10:20:52 -0700 | [diff] [blame] | 154 | _eject(&s, TRAILER, 10, 0, 0); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 155 | |
| 156 | while(total_size & 0xff) { |
| 157 | total_size++; |
| 158 | putchar(0); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | static void _archive(char *in, char *out, int ilen, int olen); |
| 163 | |
| 164 | static int compare(const void* a, const void* b) { |
| 165 | return strcmp(*(const char**)a, *(const char**)b); |
| 166 | } |
| 167 | |
| 168 | static void _archive_dir(char *in, char *out, int ilen, int olen) |
| 169 | { |
| 170 | int i, t; |
| 171 | DIR *d; |
| 172 | struct dirent *de; |
| 173 | |
| 174 | if(verbose) { |
| 175 | fprintf(stderr,"_archive_dir('%s','%s',%d,%d)\n", |
| 176 | in, out, ilen, olen); |
| 177 | } |
| 178 | |
| 179 | d = opendir(in); |
| 180 | if(d == 0) die("cannot open directory '%s'", in); |
| 181 | |
| 182 | int size = 32; |
| 183 | int entries = 0; |
| 184 | char** names = malloc(size * sizeof(char*)); |
| 185 | if (names == NULL) { |
| 186 | fprintf(stderr, "failed to allocate dir names array (size %d)\n", size); |
| 187 | exit(1); |
| 188 | } |
| 189 | |
| 190 | while((de = readdir(d)) != 0){ |
| 191 | /* xxx: feature? maybe some dotfiles are okay */ |
| 192 | if(de->d_name[0] == '.') continue; |
| 193 | |
| 194 | /* xxx: hack. use a real exclude list */ |
| 195 | if(!strcmp(de->d_name, "root")) continue; |
| 196 | |
| 197 | if (entries >= size) { |
| 198 | size *= 2; |
| 199 | names = realloc(names, size * sizeof(char*)); |
| 200 | if (names == NULL) { |
| 201 | fprintf(stderr, "failed to reallocate dir names array (size %d)\n", |
| 202 | size); |
| 203 | exit(1); |
| 204 | } |
| 205 | } |
| 206 | names[entries] = strdup(de->d_name); |
| 207 | if (names[entries] == NULL) { |
| 208 | fprintf(stderr, "failed to strdup name \"%s\"\n", |
| 209 | de->d_name); |
| 210 | exit(1); |
| 211 | } |
| 212 | ++entries; |
| 213 | } |
| 214 | |
| 215 | qsort(names, entries, sizeof(char*), compare); |
| 216 | |
| 217 | for (i = 0; i < entries; ++i) { |
| 218 | t = strlen(names[i]); |
| 219 | in[ilen] = '/'; |
| 220 | memcpy(in + ilen + 1, names[i], t + 1); |
| 221 | |
| 222 | if(olen > 0) { |
| 223 | out[olen] = '/'; |
| 224 | memcpy(out + olen + 1, names[i], t + 1); |
| 225 | _archive(in, out, ilen + t + 1, olen + t + 1); |
| 226 | } else { |
| 227 | memcpy(out, names[i], t + 1); |
| 228 | _archive(in, out, ilen + t + 1, t); |
| 229 | } |
| 230 | |
| 231 | in[ilen] = 0; |
| 232 | out[olen] = 0; |
| 233 | |
| 234 | free(names[i]); |
| 235 | } |
| 236 | free(names); |
Elliott Hughes | 14e28d3 | 2013-10-29 14:12:46 -0700 | [diff] [blame] | 237 | |
| 238 | closedir(d); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | static void _archive(char *in, char *out, int ilen, int olen) |
| 242 | { |
| 243 | struct stat s; |
| 244 | |
| 245 | if(verbose) { |
| 246 | fprintf(stderr,"_archive('%s','%s',%d,%d)\n", |
| 247 | in, out, ilen, olen); |
| 248 | } |
| 249 | |
| 250 | if(lstat(in, &s)) die("could not stat '%s'\n", in); |
| 251 | |
| 252 | if(S_ISREG(s.st_mode)){ |
| 253 | char *tmp; |
| 254 | int fd; |
| 255 | |
| 256 | fd = open(in, O_RDONLY); |
| 257 | if(fd < 0) die("cannot open '%s' for read", in); |
| 258 | |
| 259 | tmp = (char*) malloc(s.st_size); |
| 260 | if(tmp == 0) die("cannot allocate %d bytes", s.st_size); |
| 261 | |
| 262 | if(read(fd, tmp, s.st_size) != s.st_size) { |
| 263 | die("cannot read %d bytes", s.st_size); |
| 264 | } |
| 265 | |
| 266 | _eject(&s, out, olen, tmp, s.st_size); |
| 267 | |
| 268 | free(tmp); |
| 269 | close(fd); |
| 270 | } else if(S_ISDIR(s.st_mode)) { |
| 271 | _eject(&s, out, olen, 0, 0); |
| 272 | _archive_dir(in, out, ilen, olen); |
| 273 | } else if(S_ISLNK(s.st_mode)) { |
| 274 | char buf[1024]; |
| 275 | int size; |
| 276 | size = readlink(in, buf, 1024); |
| 277 | if(size < 0) die("cannot read symlink '%s'", in); |
| 278 | _eject(&s, out, olen, buf, size); |
Vincent Donnefort | c297135 | 2022-12-20 11:25:49 +0000 | [diff] [blame] | 279 | } else if(S_ISBLK(s.st_mode) || S_ISCHR(s.st_mode) || |
| 280 | S_ISFIFO(s.st_mode) || S_ISSOCK(s.st_mode)) { |
| 281 | _eject(&s, out, olen, NULL, 0); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 282 | } else { |
| 283 | die("Unknown '%s' (mode %d)?\n", in, s.st_mode); |
| 284 | } |
| 285 | } |
| 286 | |
Mateus Azis | 023f67b | 2022-07-12 15:38:47 -0700 | [diff] [blame] | 287 | static void archive(const char* start, const char* prefix) { |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 288 | char in[8192]; |
| 289 | char out[8192]; |
| 290 | |
| 291 | strcpy(in, start); |
| 292 | strcpy(out, prefix); |
| 293 | |
| 294 | _archive_dir(in, out, strlen(in), strlen(out)); |
| 295 | } |
| 296 | |
Doug Zongker | f2c3a83 | 2012-05-03 15:55:56 -0700 | [diff] [blame] | 297 | static void read_canned_config(char* filename) |
| 298 | { |
| 299 | int allocated = 8; |
| 300 | int used = 0; |
| 301 | |
| 302 | canned_config = |
| 303 | (struct fs_config_entry*)malloc(allocated * sizeof(struct fs_config_entry)); |
| 304 | |
| 305 | char line[CANNED_LINE_LENGTH]; |
| 306 | FILE* f = fopen(filename, "r"); |
Mateus Azis | 023f67b | 2022-07-12 15:38:47 -0700 | [diff] [blame] | 307 | if (f == NULL) die("failed to open canned file '%s'", filename); |
Doug Zongker | f2c3a83 | 2012-05-03 15:55:56 -0700 | [diff] [blame] | 308 | |
| 309 | while (fgets(line, CANNED_LINE_LENGTH, f) != NULL) { |
| 310 | if (!line[0]) break; |
| 311 | if (used >= allocated) { |
| 312 | allocated *= 2; |
| 313 | canned_config = (struct fs_config_entry*)realloc( |
| 314 | canned_config, allocated * sizeof(struct fs_config_entry)); |
Mikhail Lappo | 2646491 | 2017-03-23 22:17:27 +0100 | [diff] [blame] | 315 | if (canned_config == NULL) die("failed to reallocate memory"); |
Doug Zongker | f2c3a83 | 2012-05-03 15:55:56 -0700 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | struct fs_config_entry* cc = canned_config + used; |
| 319 | |
| 320 | if (isspace(line[0])) { |
| 321 | cc->name = strdup(""); |
| 322 | cc->uid = atoi(strtok(line, " \n")); |
| 323 | } else { |
| 324 | cc->name = strdup(strtok(line, " \n")); |
| 325 | cc->uid = atoi(strtok(NULL, " \n")); |
| 326 | } |
| 327 | cc->gid = atoi(strtok(NULL, " \n")); |
| 328 | cc->mode = strtol(strtok(NULL, " \n"), NULL, 8); |
| 329 | ++used; |
| 330 | } |
| 331 | if (used >= allocated) { |
| 332 | ++allocated; |
| 333 | canned_config = (struct fs_config_entry*)realloc( |
| 334 | canned_config, allocated * sizeof(struct fs_config_entry)); |
Mikhail Lappo | 2646491 | 2017-03-23 22:17:27 +0100 | [diff] [blame] | 335 | if (canned_config == NULL) die("failed to reallocate memory"); |
Doug Zongker | f2c3a83 | 2012-05-03 15:55:56 -0700 | [diff] [blame] | 336 | } |
| 337 | canned_config[used].name = NULL; |
| 338 | |
| 339 | fclose(f); |
| 340 | } |
| 341 | |
Vincent Donnefort | 99ab521 | 2023-01-04 10:33:18 +0000 | [diff] [blame^] | 342 | static void devnodes_desc_error(const char* filename, unsigned long line_num, |
| 343 | const char* msg) |
| 344 | { |
| 345 | error(EXIT_FAILURE, 0, "failed to read nodes desc file '%s' line %lu: %s", |
| 346 | filename, line_num, msg); |
| 347 | } |
| 348 | |
| 349 | static int append_devnodes_desc_dir(char* path, char* args) |
| 350 | { |
| 351 | struct stat s; |
| 352 | |
| 353 | if (sscanf(args, "%o %d %d", &s.st_mode, &s.st_uid, &s.st_gid) != 3) return -1; |
| 354 | |
| 355 | s.st_mode |= S_IFDIR; |
| 356 | |
| 357 | _eject(&s, path, strlen(path), NULL, 0); |
| 358 | |
| 359 | return 0; |
| 360 | } |
| 361 | |
| 362 | static int append_devnodes_desc_nod(char* path, char* args) |
| 363 | { |
| 364 | int minor, major; |
| 365 | struct stat s; |
| 366 | char dev; |
| 367 | |
| 368 | if (sscanf(args, "%o %d %d %c %d %d", &s.st_mode, &s.st_uid, &s.st_gid, |
| 369 | &dev, &major, &minor) != 6) return -1; |
| 370 | |
| 371 | s.st_rdev = MKDEV(major, minor); |
| 372 | switch (dev) { |
| 373 | case 'b': |
| 374 | s.st_mode |= S_IFBLK; |
| 375 | break; |
| 376 | case 'c': |
| 377 | s.st_mode |= S_IFCHR; |
| 378 | break; |
| 379 | default: |
| 380 | return -1; |
| 381 | } |
| 382 | |
| 383 | _eject(&s, path, strlen(path), NULL, 0); |
| 384 | |
| 385 | return 0; |
| 386 | } |
| 387 | |
| 388 | static void append_devnodes_desc(const char* filename) |
| 389 | { |
| 390 | FILE* f = fopen(filename, "re"); |
| 391 | if (!f) error(EXIT_FAILURE, errno, |
| 392 | "failed to open nodes description file '%s'", filename); |
| 393 | |
| 394 | char *line, *args, *type, *path; |
| 395 | unsigned long line_num = 0; |
| 396 | size_t allocated_len; |
| 397 | |
| 398 | while (getline(&line, &allocated_len, f) != -1) { |
| 399 | char* type; |
| 400 | |
| 401 | line_num++; |
| 402 | |
| 403 | if (*line == '#') continue; |
| 404 | |
| 405 | if (!(type = strtok(line, " \t"))) { |
| 406 | devnodes_desc_error(filename, line_num, "a type is missing"); |
| 407 | } |
| 408 | |
| 409 | if (*type == '\n') continue; |
| 410 | |
| 411 | if (!(path = strtok(NULL, " \t"))) { |
| 412 | devnodes_desc_error(filename, line_num, "a path is missing"); |
| 413 | } |
| 414 | |
| 415 | if (!(args = strtok(NULL, "\n"))) { |
| 416 | devnodes_desc_error(filename, line_num, "args are missing"); |
| 417 | } |
| 418 | |
| 419 | if (!strcmp(type, "dir")) { |
| 420 | if (append_devnodes_desc_dir(path, args)) { |
| 421 | devnodes_desc_error(filename, line_num, "bad arguments for dir"); |
| 422 | } |
| 423 | } else if (!strcmp(type, "nod")) { |
| 424 | if (append_devnodes_desc_nod(path, args)) { |
| 425 | devnodes_desc_error(filename, line_num, "bad arguments for nod"); |
| 426 | } |
| 427 | } else { |
| 428 | devnodes_desc_error(filename, line_num, "type unknown"); |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | free(line); |
| 433 | fclose(f); |
| 434 | } |
| 435 | |
Vincent Donnefort | 7f01774 | 2022-12-20 11:22:26 +0000 | [diff] [blame] | 436 | static const struct option long_options[] = { |
| 437 | { "dirname", required_argument, NULL, 'd' }, |
| 438 | { "file", required_argument, NULL, 'f' }, |
| 439 | { "help", no_argument, NULL, 'h' }, |
Vincent Donnefort | 99ab521 | 2023-01-04 10:33:18 +0000 | [diff] [blame^] | 440 | { "nodes", required_argument, NULL, 'n' }, |
Vincent Donnefort | 7f01774 | 2022-12-20 11:22:26 +0000 | [diff] [blame] | 441 | { NULL, 0, NULL, 0 }, |
| 442 | }; |
| 443 | |
| 444 | static void usage(void) |
| 445 | { |
| 446 | fprintf(stderr, |
Vincent Donnefort | 99ab521 | 2023-01-04 10:33:18 +0000 | [diff] [blame^] | 447 | "Usage: mkbootfs [-n FILE] [-d DIR|-F FILE] DIR...\n" |
Vincent Donnefort | 7f01774 | 2022-12-20 11:22:26 +0000 | [diff] [blame] | 448 | "\n" |
| 449 | "\t-d, --dirname=DIR: fs-config directory\n" |
| 450 | "\t-f, --file=FILE: Canned configuration file\n" |
| 451 | "\t-h, --help: Print this help\n" |
Vincent Donnefort | 99ab521 | 2023-01-04 10:33:18 +0000 | [diff] [blame^] | 452 | "\t-n, --nodes=FILE: Dev nodes description file\n" |
| 453 | "\nDev nodes description:\n" |
| 454 | "\t[dir|nod] [perms] [uid] [gid] [c|b] [minor] [major]\n" |
| 455 | "\tExample:\n" |
| 456 | "\t\t# My device nodes\n" |
| 457 | "\t\tdir dev 0755 0 0\n" |
| 458 | "\t\tnod dev/null 0600 0 0 c 1 5\n" |
Vincent Donnefort | 7f01774 | 2022-12-20 11:22:26 +0000 | [diff] [blame] | 459 | ); |
| 460 | } |
Doug Zongker | f2c3a83 | 2012-05-03 15:55:56 -0700 | [diff] [blame] | 461 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 462 | int main(int argc, char *argv[]) |
| 463 | { |
Vincent Donnefort | 7f01774 | 2022-12-20 11:22:26 +0000 | [diff] [blame] | 464 | int opt, unused; |
| 465 | |
Vincent Donnefort | 99ab521 | 2023-01-04 10:33:18 +0000 | [diff] [blame^] | 466 | while ((opt = getopt_long(argc, argv, "hd:f:n:", long_options, &unused)) != -1) { |
Vincent Donnefort | 7f01774 | 2022-12-20 11:22:26 +0000 | [diff] [blame] | 467 | switch (opt) { |
| 468 | case 'd': |
| 469 | target_out_path = argv[optind - 1]; |
| 470 | break; |
| 471 | case 'f': |
| 472 | read_canned_config(argv[optind - 1]); |
| 473 | break; |
| 474 | case 'h': |
| 475 | usage(); |
| 476 | return 0; |
Vincent Donnefort | 99ab521 | 2023-01-04 10:33:18 +0000 | [diff] [blame^] | 477 | case 'n': |
| 478 | append_devnodes_desc(argv[optind - 1]); |
| 479 | break; |
Vincent Donnefort | 7f01774 | 2022-12-20 11:22:26 +0000 | [diff] [blame] | 480 | default: |
| 481 | usage(); |
| 482 | die("Unknown option %s", argv[optind - 1]); |
| 483 | } |
Mateus Azis | 023f67b | 2022-07-12 15:38:47 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Vincent Donnefort | 7f01774 | 2022-12-20 11:22:26 +0000 | [diff] [blame] | 486 | int num_dirs = argc - optind; |
| 487 | argv += optind; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 488 | |
Vincent Donnefort | 7f01774 | 2022-12-20 11:22:26 +0000 | [diff] [blame] | 489 | if (num_dirs <= 0) { |
| 490 | usage(); |
| 491 | die("no directories to process?!"); |
Thierry Strudel | df33ffa | 2015-07-09 09:50:31 -0700 | [diff] [blame] | 492 | } |
| 493 | |
Vincent Donnefort | 7f01774 | 2022-12-20 11:22:26 +0000 | [diff] [blame] | 494 | while(num_dirs-- > 0){ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 495 | char *x = strchr(*argv, '='); |
| 496 | if(x != 0) { |
| 497 | *x++ = 0; |
| 498 | } else { |
| 499 | x = ""; |
| 500 | } |
| 501 | |
| 502 | archive(*argv, x); |
| 503 | |
| 504 | argv++; |
| 505 | } |
| 506 | |
| 507 | _eject_trailer(); |
| 508 | |
| 509 | return 0; |
| 510 | } |