2 * Copyright (C) 2015 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <private/android_filesystem_config.h>
25 * This program expects android_device_dirs and android_device_files
26 * to be defined in the supplied android_filesystem_config.h file in
27 * the device/<vendor>/<product> $(TARGET_DEVICE_DIR). Then generates
28 * the binary format used in the /system/etc/fs_config_dirs and
29 * the /system/etc/fs_config_files to be used by the runtimes.
31 #include "android_filesystem_config.h"
33 #ifdef NO_ANDROID_FILESYSTEM_CONFIG_DEVICE_DIRS
34 static const struct fs_path_config android_device_dirs[] = {
38 #ifdef NO_ANDROID_FILESYSTEM_CONFIG_DEVICE_FILES
39 static const struct fs_path_config android_device_files[] = {
40 #ifdef NO_ANDROID_FILESYSTEM_CONFIG_DEVICE_DIRS
41 { 0, AID_ROOT, AID_ROOT, 0, "system/etc/fs_config_dirs" },
43 { 0, AID_ROOT, AID_ROOT, 0, "system/etc/fs_config_files" },
49 "Generate binary content for fs_config_dirs (-D) and fs_config_files (-F)\n"
50 "from device-specific android_filesystem_config.h override\n\n"
51 "Usage: fs_config_generate -D|-F [-o output-file]\n");
54 int main(int argc, char** argv) {
55 const struct fs_path_config *pc;
56 const struct fs_path_config *end;
57 bool dir = false, file = false;
61 while((opt = getopt(argc, argv, "DFho:")) != -1) {
65 fprintf(stderr, "Must specify only -D or -F\n");
73 fprintf(stderr, "Must specify only -F or -D\n");
81 fprintf(stderr, "Specify only one output file\n");
85 fp = fopen(optarg, "wb");
87 fprintf(stderr, "Can not open \"%s\"\n", optarg);
101 fprintf(stderr, "Must specify either -F or -D\n");
107 pc = android_device_dirs;
108 end = &android_device_dirs[sizeof(android_device_dirs) / sizeof(android_device_dirs[0])];
110 pc = android_device_files;
111 end = &android_device_files[sizeof(android_device_files) / sizeof(android_device_files[0])];
113 for(; (pc < end) && pc->prefix; pc++) {
115 ssize_t len = fs_config_generate(buffer, sizeof(buffer), pc);
117 fprintf(stderr, "Entry too large\n");
120 if (fwrite(buffer, 1, len, fp) != (size_t)len) {
121 fprintf(stderr, "Write failure\n");