blob: 8742e611f25c835774ffba9e9211258f52f4da5e [file] [log] [blame]
Doug Zongker263eefd2010-06-29 17:23:14 -07001/*
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");
Ken Sumrall75249ed2010-08-13 16:04:49 -070036 fprintf(stderr, " [ -z | -s ] [ -J ]\n");
Doug Zongker263eefd2010-06-29 17:23:14 -070037 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;
Ken Sumrall75249ed2010-08-13 16:04:49 -070048 int sparse = 0;
Colin Cross757ace52010-12-29 13:57:01 -080049 int crc = 0;
Colin Crossc2470652011-01-26 16:39:46 -080050 int wipe = 0;
Doug Zongker263eefd2010-06-29 17:23:14 -070051
Colin Crossc2470652011-01-26 16:39:46 -080052 while ((opt = getopt(argc, argv, "l:j:b:g:i:I:L:a:fwzJsc")) != -1) {
Doug Zongker263eefd2010-06-29 17:23:14 -070053 switch (opt) {
54 case 'l':
55 info.len = parse_num(optarg);
56 break;
57 case 'j':
58 info.journal_blocks = parse_num(optarg);
59 break;
60 case 'b':
61 info.block_size = parse_num(optarg);
62 break;
63 case 'g':
64 info.blocks_per_group = parse_num(optarg);
65 break;
66 case 'i':
67 info.inodes = parse_num(optarg);
68 break;
69 case 'I':
70 info.inode_size = parse_num(optarg);
71 break;
72 case 'L':
73 info.label = optarg;
74 break;
75 case 'f':
76 force = 1;
77 break;
78 case 'a':
79 android = 1;
80 mountpoint = optarg;
81 break;
Colin Crossc2470652011-01-26 16:39:46 -080082 case 'w':
83 wipe = 1;
84 break;
Doug Zongker263eefd2010-06-29 17:23:14 -070085 case 'z':
86 gzip = 1;
87 break;
Colin Crosse4b5ae82010-08-03 14:10:07 -070088 case 'J':
89 info.no_journal = 1;
90 break;
Colin Cross757ace52010-12-29 13:57:01 -080091 case 'c':
92 crc = 1;
93 break;
Ken Sumrall75249ed2010-08-13 16:04:49 -070094 case 's':
95 sparse = 1;
96 break;
Doug Zongker263eefd2010-06-29 17:23:14 -070097 default: /* '?' */
98 usage(argv[0]);
99 exit(EXIT_FAILURE);
100 }
101 }
102
Ken Sumrall75249ed2010-08-13 16:04:49 -0700103 if (gzip && sparse) {
104 fprintf(stderr, "Cannot specify both gzip and sparse\n");
105 usage(argv[0]);
106 exit(EXIT_FAILURE);
107 }
108
Colin Crossc2470652011-01-26 16:39:46 -0800109 if (wipe && sparse) {
110 fprintf(stderr, "Cannot specifiy both wipe and sparse\n");
111 usage(argv[0]);
112 exit(EXIT_FAILURE);
113 }
114
115 if (wipe && gzip) {
116 fprintf(stderr, "Cannot specifiy both wipe and gzip\n");
117 usage(argv[0]);
118 exit(EXIT_FAILURE);
119 }
120
Doug Zongker263eefd2010-06-29 17:23:14 -0700121 if (optind >= argc) {
122 fprintf(stderr, "Expected filename after options\n");
123 usage(argv[0]);
124 exit(EXIT_FAILURE);
125 }
126
127 filename = argv[optind++];
128
129 if (optind < argc)
130 directory = argv[optind++];
131
132 if (optind < argc) {
133 fprintf(stderr, "Unexpected argument: %s\n", argv[optind]);
134 usage(argv[0]);
135 exit(EXIT_FAILURE);
136 }
137
Ken Sumrall983fb192011-01-19 17:15:42 -0800138 return make_ext4fs_internal(filename, directory, mountpoint, android, gzip,
Colin Crossc2470652011-01-26 16:39:46 -0800139 sparse, crc, wipe);
Doug Zongker263eefd2010-06-29 17:23:14 -0700140}