make_ext4fs_main.c revision e4b5ae8ab07e698b95f004c9226000b02f853abc
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, "    <filename> [<directory>]\n");
37}
38
39int main(int argc, char **argv)
40{
41        int opt;
42        const char *filename = NULL;
43        const char *directory = NULL;
44        char *mountpoint = "";
45        int android = 0;
46        int gzip = 0;
47
48        while ((opt = getopt(argc, argv, "l:j:b:g:i:I:L:a:fzJ")) != -1) {
49                switch (opt) {
50                case 'l':
51                        info.len = parse_num(optarg);
52                        break;
53                case 'j':
54                        info.journal_blocks = parse_num(optarg);
55                        break;
56                case 'b':
57                        info.block_size = parse_num(optarg);
58                        break;
59                case 'g':
60                        info.blocks_per_group = parse_num(optarg);
61                        break;
62                case 'i':
63                        info.inodes = parse_num(optarg);
64                        break;
65                case 'I':
66                        info.inode_size = parse_num(optarg);
67                        break;
68                case 'L':
69                        info.label = optarg;
70                        break;
71                case 'f':
72                        force = 1;
73                        break;
74                case 'a':
75                        android = 1;
76                        mountpoint = optarg;
77                        break;
78                case 'z':
79                        gzip = 1;
80                        break;
81		case 'J':
82			info.no_journal = 1;
83			break;
84                default: /* '?' */
85                        usage(argv[0]);
86                        exit(EXIT_FAILURE);
87                }
88        }
89
90        if (optind >= argc) {
91                fprintf(stderr, "Expected filename after options\n");
92                usage(argv[0]);
93                exit(EXIT_FAILURE);
94        }
95
96        filename = argv[optind++];
97
98        if (optind < argc)
99                directory = argv[optind++];
100
101        if (optind < argc) {
102                fprintf(stderr, "Unexpected argument: %s\n", argv[optind]);
103                usage(argv[0]);
104                exit(EXIT_FAILURE);
105        }
106
107        return make_ext4fs(filename, directory, mountpoint, android, gzip);
108}
109