2 * Copyright (C) 2010 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 #if defined(__linux__)
24 #elif defined(__APPLE__) && defined(__MACH__)
29 #include <private/android_filesystem_config.h>
33 #include <selinux/selinux.h>
34 #include <selinux/label.h>
36 #include <selinux/android.h>
39 struct selabel_handle;
42 #include "make_ext4fs.h"
43 #include "ext4_utils.h"
44 #include "canned_fs_config.h"
46 #ifndef USE_MINGW /* O_BINARY is windows-specific flag */
50 extern struct fs_info info;
53 static void usage(char *path)
55 fprintf(stderr, "%s [ -l <len> ] [ -j <journal size> ] [ -b <block_size> ]\n", basename(path));
56 fprintf(stderr, " [ -g <blocks per group> ] [ -i <inodes> ] [ -I <inode size> ]\n");
57 fprintf(stderr, " [ -L <label> ] [ -f ] [ -a <android mountpoint> ] [ -u ]\n");
58 fprintf(stderr, " [ -S file_contexts ] [ -C fs_config ] [ -T timestamp ]\n");
59 fprintf(stderr, " [ -z | -s ] [ -w ] [ -c ] [ -J ] [ -v ] [ -B <block_list_file> ]\n");
60 fprintf(stderr, " <filename> [[<directory>] <target_out_directory>]\n");
63 int main(int argc, char **argv)
66 const char *filename = NULL;
67 const char *directory = NULL;
68 const char *target_out_directory = NULL;
69 char *mountpoint = NULL;
70 fs_config_func_t fs_config_func = NULL;
71 const char *fs_config_file = NULL;
80 time_t fixed_time = -1;
81 struct selabel_handle *sehnd = NULL;
82 FILE* block_list_file = NULL;
84 struct selinux_opt seopts[] = { { SELABEL_OPT_PATH, "" } };
87 while ((opt = getopt(argc, argv, "l:j:b:g:i:I:L:a:S:T:C:B:fwzJsctvu")) != -1) {
90 info.len = parse_num(optarg);
93 info.journal_blocks = parse_num(optarg);
96 info.block_size = parse_num(optarg);
99 info.blocks_per_group = parse_num(optarg);
102 info.inodes = parse_num(optarg);
105 info.inode_size = parse_num(optarg);
117 fprintf(stderr, "can't set android permissions - built without android support\n");
141 fprintf(stderr, "Warning: -t (initialize inode tables) is deprecated\n");
145 seopts[0].value = optarg;
146 sehnd = selabel_open(SELABEL_CTX_FILE, seopts, 1);
157 fixed_time = strtoll(optarg, NULL, 0);
160 fs_config_file = optarg;
163 block_list_file = fopen(optarg, "w");
164 if (block_list_file == NULL) {
165 fprintf(stderr, "failed to open block_list_file: %s\n", strerror(errno));
176 // Use only if -S option not requested
177 if (!sehnd && mountpoint) {
178 sehnd = selinux_android_file_context_handle();
187 if (fs_config_file) {
188 if (load_canned_fs_config(fs_config_file) < 0) {
189 fprintf(stderr, "failed to load %s\n", fs_config_file);
192 fs_config_func = canned_fs_config;
193 } else if (mountpoint) {
194 fs_config_func = fs_config;
197 if (wipe && sparse) {
198 fprintf(stderr, "Cannot specifiy both wipe and sparse\n");
204 fprintf(stderr, "Cannot specifiy both wipe and gzip\n");
209 if (optind >= argc) {
210 fprintf(stderr, "Expected filename after options\n");
215 filename = argv[optind++];
218 directory = argv[optind++];
221 target_out_directory = argv[optind++];
224 fprintf(stderr, "Unexpected argument: %s\n", argv[optind]);
229 if (strcmp(filename, "-")) {
230 fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
239 exitcode = make_ext4fs_internal(fd, directory, target_out_directory, mountpoint, fs_config_func, gzip,
240 sparse, crc, wipe, real_uuid, sehnd, verbose, fixed_time, block_list_file);
243 fclose(block_list_file);
244 if (exitcode && strcmp(filename, "-"))