Remove unused mountpoint support
[project/make_ext4fs.git] / make_ext4fs_main.c
1 /*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 #include <fcntl.h>
18 #include <libgen.h>
19 #include <stdio.h>
20 #include <unistd.h>
21
22 #if defined(__linux__)
23 #include <linux/fs.h>
24 #elif defined(__APPLE__) && defined(__MACH__)
25 #include <sys/disk.h>
26 #endif
27
28 #include "ext4_utils.h"
29 #include "canned_fs_config.h"
30
31 extern struct fs_info info;
32
33
34 static void usage(char *path)
35 {
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");
42 }
43
44 int main(int argc, char **argv)
45 {
46 int opt;
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;
51 int gzip = 0;
52 int sparse = 0;
53 int crc = 0;
54 int wipe = 0;
55 int fd;
56 int exitcode;
57 int verbose = 0;
58 time_t fixed_time = -1;
59 FILE* block_list_file = NULL;
60
61 while ((opt = getopt(argc, argv, "l:j:b:g:i:I:L:T:C:B:fwzJsctv")) != -1) {
62 switch (opt) {
63 case 'l':
64 info.len = parse_num(optarg);
65 break;
66 case 'j':
67 info.journal_blocks = parse_num(optarg);
68 break;
69 case 'b':
70 info.block_size = parse_num(optarg);
71 break;
72 case 'g':
73 info.blocks_per_group = parse_num(optarg);
74 break;
75 case 'i':
76 info.inodes = parse_num(optarg);
77 break;
78 case 'I':
79 info.inode_size = parse_num(optarg);
80 break;
81 case 'L':
82 info.label = optarg;
83 break;
84 case 'f':
85 force = 1;
86 break;
87 case 'w':
88 wipe = 1;
89 break;
90 case 'z':
91 gzip = 1;
92 break;
93 case 'J':
94 info.no_journal = 1;
95 break;
96 case 'c':
97 crc = 1;
98 break;
99 case 's':
100 sparse = 1;
101 break;
102 case 't':
103 fprintf(stderr, "Warning: -t (initialize inode tables) is deprecated\n");
104 break;
105 case 'v':
106 verbose = 1;
107 break;
108 case 'T':
109 fixed_time = strtoll(optarg, NULL, 0);
110 break;
111 case 'C':
112 fs_config_file = optarg;
113 break;
114 case 'B':
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));
118 exit(EXIT_FAILURE);
119 }
120 break;
121 default: /* '?' */
122 usage(argv[0]);
123 exit(EXIT_FAILURE);
124 }
125 }
126
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);
130 exit(EXIT_FAILURE);
131 }
132 fs_config_func = canned_fs_config;
133 }
134
135 if (wipe && sparse) {
136 fprintf(stderr, "Cannot specifiy both wipe and sparse\n");
137 usage(argv[0]);
138 exit(EXIT_FAILURE);
139 }
140
141 if (wipe && gzip) {
142 fprintf(stderr, "Cannot specifiy both wipe and gzip\n");
143 usage(argv[0]);
144 exit(EXIT_FAILURE);
145 }
146
147 if (optind >= argc) {
148 fprintf(stderr, "Expected filename after options\n");
149 usage(argv[0]);
150 exit(EXIT_FAILURE);
151 }
152
153 filename = argv[optind++];
154
155 if (optind < argc)
156 directory = argv[optind++];
157
158 if (optind < argc) {
159 fprintf(stderr, "Unexpected argument: %s\n", argv[optind]);
160 usage(argv[0]);
161 exit(EXIT_FAILURE);
162 }
163
164 if (strcmp(filename, "-")) {
165 fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
166 if (fd < 0) {
167 perror("open");
168 return EXIT_FAILURE;
169 }
170 } else {
171 fd = STDOUT_FILENO;
172 }
173
174 exitcode = make_ext4fs_internal(fd, directory, fs_config_func, gzip,
175 sparse, crc, wipe, verbose, fixed_time, block_list_file);
176 close(fd);
177 if (block_list_file)
178 fclose(block_list_file);
179 if (exitcode && strcmp(filename, "-"))
180 unlink(filename);
181 return exitcode;
182 }