make_ext4fs_main.c revision ae4f7dccadfafc36470a3e6f3084c6cf3cc63415
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 <unistd.h>
18#include <libgen.h>
19
20#if defined(__linux__)
21#include <linux/fs.h>
22#elif defined(__APPLE__) && defined(__MACH__)
23#include <sys/disk.h>
24#endif
25
26#include "make_ext4fs.h"
27
28extern struct fs_info info;
29
30
31static void usage(char *path)
32{
33        fprintf(stderr, "%s [ -l <len> ] [ -j <journal size> ] [ -b <block_size> ]\n", basename(path));
34        fprintf(stderr, "    [ -g <blocks per group> ] [ -i <inodes> ] [ -I <inode size> ]\n");
35        fprintf(stderr, "    [ -L <label> ] [ -f ] [ -a <android mountpoint> ]\n");
36        fprintf(stderr, "    [ -z | -s ] [ -t ] [ -w ] [ -c ] [ -J ]\n");
37        fprintf(stderr, "    <filename> [<directory>]\n");
38}
39
40int main(int argc, char **argv)
41{
42        int opt;
43        const char *filename = NULL;
44        const char *directory = NULL;
45        char *mountpoint = "";
46        int android = 0;
47        int gzip = 0;
48        int sparse = 0;
49        int crc = 0;
50        int wipe = 0;
51        int init_itabs = 0;
52
53        while ((opt = getopt(argc, argv, "l:j:b:g:i:I:L:a:fwzJsct")) != -1) {
54                switch (opt) {
55                case 'l':
56                        info.len = parse_num(optarg);
57                        break;
58                case 'j':
59                        info.journal_blocks = parse_num(optarg);
60                        break;
61                case 'b':
62                        info.block_size = parse_num(optarg);
63                        break;
64                case 'g':
65                        info.blocks_per_group = parse_num(optarg);
66                        break;
67                case 'i':
68                        info.inodes = parse_num(optarg);
69                        break;
70                case 'I':
71                        info.inode_size = parse_num(optarg);
72                        break;
73                case 'L':
74                        info.label = optarg;
75                        break;
76                case 'f':
77                        force = 1;
78                        break;
79                case 'a':
80                        android = 1;
81                        mountpoint = optarg;
82                        break;
83                case 'w':
84                        wipe = 1;
85                        break;
86                case 'z':
87                        gzip = 1;
88                        break;
89		case 'J':
90			info.no_journal = 1;
91			break;
92		case 'c':
93			crc = 1;
94			break;
95                case 's':
96                        sparse = 1;
97                        break;
98                case 't':
99                        init_itabs = 1;
100                        break;
101                default: /* '?' */
102                        usage(argv[0]);
103                        exit(EXIT_FAILURE);
104                }
105        }
106
107	if (gzip && sparse) {
108                fprintf(stderr, "Cannot specify both gzip and sparse\n");
109                usage(argv[0]);
110                exit(EXIT_FAILURE);
111	}
112
113        if (wipe && sparse) {
114                fprintf(stderr, "Cannot specifiy both wipe and sparse\n");
115                usage(argv[0]);
116                exit(EXIT_FAILURE);
117        }
118
119        if (wipe && gzip) {
120                fprintf(stderr, "Cannot specifiy both wipe and gzip\n");
121                usage(argv[0]);
122                exit(EXIT_FAILURE);
123        }
124
125        if (optind >= argc) {
126                fprintf(stderr, "Expected filename after options\n");
127                usage(argv[0]);
128                exit(EXIT_FAILURE);
129        }
130
131        filename = argv[optind++];
132
133        if (optind < argc)
134                directory = argv[optind++];
135
136        if (optind < argc) {
137                fprintf(stderr, "Unexpected argument: %s\n", argv[optind]);
138                usage(argv[0]);
139                exit(EXIT_FAILURE);
140        }
141
142        return make_ext4fs_internal(filename, directory, mountpoint, android, gzip,
143                       sparse, crc, wipe, init_itabs);
144}
145