OSDN Git Service

bd7442e0ad75ca764afd8af7811ae3bbbb6d677d
[android-x86/system-extras.git] / ext4_utils / 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 <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
28 extern struct fs_info info;
29
30
31 static 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 ] [ -J ]\n");
37         fprintf(stderr, "    <filename> [<directory>]\n");
38 }
39
40 int 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
51         while ((opt = getopt(argc, argv, "l:j:b:g:i:I:L:a:fzJsc")) != -1) {
52                 switch (opt) {
53                 case 'l':
54                         info.len = parse_num(optarg);
55                         break;
56                 case 'j':
57                         info.journal_blocks = parse_num(optarg);
58                         break;
59                 case 'b':
60                         info.block_size = parse_num(optarg);
61                         break;
62                 case 'g':
63                         info.blocks_per_group = parse_num(optarg);
64                         break;
65                 case 'i':
66                         info.inodes = parse_num(optarg);
67                         break;
68                 case 'I':
69                         info.inode_size = parse_num(optarg);
70                         break;
71                 case 'L':
72                         info.label = optarg;
73                         break;
74                 case 'f':
75                         force = 1;
76                         break;
77                 case 'a':
78                         android = 1;
79                         mountpoint = optarg;
80                         break;
81                 case 'z':
82                         gzip = 1;
83                         break;
84                 case 'J':
85                         info.no_journal = 1;
86                         break;
87                 case 'c':
88                         crc = 1;
89                         break;
90                 case 's':
91                         sparse = 1;
92                         break;
93                 default: /* '?' */
94                         usage(argv[0]);
95                         exit(EXIT_FAILURE);
96                 }
97         }
98
99         if (gzip && sparse) {
100                 fprintf(stderr, "Cannot specify both gzip and sparse\n");
101                 usage(argv[0]);
102                 exit(EXIT_FAILURE);
103         }
104
105         if (optind >= argc) {
106                 fprintf(stderr, "Expected filename after options\n");
107                 usage(argv[0]);
108                 exit(EXIT_FAILURE);
109         }
110
111         filename = argv[optind++];
112
113         if (optind < argc)
114                 directory = argv[optind++];
115
116         if (optind < argc) {
117                 fprintf(stderr, "Unexpected argument: %s\n", argv[optind]);
118                 usage(argv[0]);
119                 exit(EXIT_FAILURE);
120         }
121
122         return make_ext4fs_internal(filename, directory, mountpoint, android, gzip,
123                         sparse, crc);
124 }