blob: d616c6d4bdde04dfac560828bfab6ac1377e31d8 [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
Anatol Pomazau89ddaab2012-01-11 15:12:27 -080017#include <unistd.h>
Anatol Pomazau354350e2012-02-03 18:20:07 -080018#include <libgen.h>
Doug Zongker263eefd2010-06-29 17:23:14 -070019
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 Sumrall107a9f12011-06-29 20:28:30 -070036 fprintf(stderr, " [ -z | -s ] [ -t ] [ -w ] [ -c ] [ -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;
Ken Sumrall107a9f12011-06-29 20:28:30 -070051 int init_itabs = 0;
Doug Zongker263eefd2010-06-29 17:23:14 -070052
Ken Sumrall107a9f12011-06-29 20:28:30 -070053 while ((opt = getopt(argc, argv, "l:j:b:g:i:I:L:a:fwzJsct")) != -1) {
Doug Zongker263eefd2010-06-29 17:23:14 -070054 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;
Colin Crossc2470652011-01-26 16:39:46 -080083 case 'w':
84 wipe = 1;
85 break;
Doug Zongker263eefd2010-06-29 17:23:14 -070086 case 'z':
87 gzip = 1;
88 break;
Colin Crosse4b5ae82010-08-03 14:10:07 -070089 case 'J':
90 info.no_journal = 1;
91 break;
Colin Cross757ace52010-12-29 13:57:01 -080092 case 'c':
93 crc = 1;
94 break;
Ken Sumrall75249ed2010-08-13 16:04:49 -070095 case 's':
96 sparse = 1;
97 break;
Ken Sumrall107a9f12011-06-29 20:28:30 -070098 case 't':
99 init_itabs = 1;
100 break;
Doug Zongker263eefd2010-06-29 17:23:14 -0700101 default: /* '?' */
102 usage(argv[0]);
103 exit(EXIT_FAILURE);
104 }
105 }
106
Ken Sumrall75249ed2010-08-13 16:04:49 -0700107 if (gzip && sparse) {
108 fprintf(stderr, "Cannot specify both gzip and sparse\n");
109 usage(argv[0]);
110 exit(EXIT_FAILURE);
111 }
112
Colin Crossc2470652011-01-26 16:39:46 -0800113 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
Doug Zongker263eefd2010-06-29 17:23:14 -0700125 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
Anatol Pomazau354350e2012-02-03 18:20:07 -0800142 return make_ext4fs_internal(filename, directory, mountpoint, android, gzip,
Ken Sumrall107a9f12011-06-29 20:28:30 -0700143 sparse, crc, wipe, init_itabs);
Doug Zongker263eefd2010-06-29 17:23:14 -0700144}