make_ext4fs_main.c revision c2470654d4b4db09a7052fc5fa108ac21f1b1948
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 ] [ -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 52 while ((opt = getopt(argc, argv, "l:j:b:g:i:I:L:a:fwzJsc")) != -1) { 53 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; 82 case 'w': 83 wipe = 1; 84 break; 85 case 'z': 86 gzip = 1; 87 break; 88 case 'J': 89 info.no_journal = 1; 90 break; 91 case 'c': 92 crc = 1; 93 break; 94 case 's': 95 sparse = 1; 96 break; 97 default: /* '?' */ 98 usage(argv[0]); 99 exit(EXIT_FAILURE); 100 } 101 } 102 103 if (gzip && sparse) { 104 fprintf(stderr, "Cannot specify both gzip and sparse\n"); 105 usage(argv[0]); 106 exit(EXIT_FAILURE); 107 } 108 109 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 121 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 138 return make_ext4fs_internal(filename, directory, mountpoint, android, gzip, 139 sparse, crc, wipe); 140} 141