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__)
28 #include "ext4_utils.h"
29 #include "canned_fs_config.h"
31 extern struct fs_info info
;
34 static void usage(char *path
)
36 fprintf(stderr
, "%s [ -l <len> ] [ -j <journal size> ] [ -b <block_size> ]\n", basename(path
));
37 fprintf(stderr
, " [ -g <blocks per group> ] [ -i <inodes> ] [ -I <inode size> ]\n");
38 fprintf(stderr
, " [ -L <label> ] [ -f ]\n");
39 fprintf(stderr
, " [ -S file_contexts ] [ -C fs_config ] [ -T timestamp ]\n");
40 fprintf(stderr
, " [ -z | -s ] [ -w ] [ -c ] [ -J ] [ -v ] [ -B <block_list_file> ]\n");
41 fprintf(stderr
, " <filename> [<directory>]\n");
44 int main(int argc
, char **argv
)
47 const char *filename
= NULL
;
48 const char *directory
= NULL
;
49 fs_config_func_t fs_config_func
= NULL
;
50 const char *fs_config_file
= NULL
;
58 time_t fixed_time
= -1;
59 FILE* block_list_file
= NULL
;
61 while ((opt
= getopt(argc
, argv
, "l:j:b:g:i:I:L:T:C:B:fwzJsctv")) != -1) {
64 info
.len
= parse_num(optarg
);
67 info
.journal_blocks
= parse_num(optarg
);
70 info
.block_size
= parse_num(optarg
);
73 info
.blocks_per_group
= parse_num(optarg
);
76 info
.inodes
= parse_num(optarg
);
79 info
.inode_size
= parse_num(optarg
);
103 fprintf(stderr
, "Warning: -t (initialize inode tables) is deprecated\n");
109 fixed_time
= strtoll(optarg
, NULL
, 0);
112 fs_config_file
= optarg
;
115 block_list_file
= fopen(optarg
, "w");
116 if (block_list_file
== NULL
) {
117 fprintf(stderr
, "failed to open block_list_file: %s\n", strerror(errno
));
127 if (fs_config_file
) {
128 if (load_canned_fs_config(fs_config_file
) < 0) {
129 fprintf(stderr
, "failed to load %s\n", fs_config_file
);
132 fs_config_func
= canned_fs_config
;
135 if (wipe
&& sparse
) {
136 fprintf(stderr
, "Cannot specifiy both wipe and sparse\n");
142 fprintf(stderr
, "Cannot specifiy both wipe and gzip\n");
147 if (optind
>= argc
) {
148 fprintf(stderr
, "Expected filename after options\n");
153 filename
= argv
[optind
++];
156 directory
= argv
[optind
++];
159 fprintf(stderr
, "Unexpected argument: %s\n", argv
[optind
]);
164 if (strcmp(filename
, "-")) {
165 fd
= open(filename
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0644);
174 exitcode
= make_ext4fs_internal(fd
, directory
, fs_config_func
, gzip
,
175 sparse
, crc
, wipe
, verbose
, fixed_time
, block_list_file
);
178 fclose(block_list_file
);
179 if (exitcode
&& strcmp(filename
, "-"))