make_ext4fs_main.c revision 263eefd9fb9608432636c903423e43848e69f39d
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:fz")) != -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 default: /* '?' */ 82 usage(argv[0]); 83 exit(EXIT_FAILURE); 84 } 85 } 86 87 if (optind >= argc) { 88 fprintf(stderr, "Expected filename after options\n"); 89 usage(argv[0]); 90 exit(EXIT_FAILURE); 91 } 92 93 filename = argv[optind++]; 94 95 if (optind < argc) 96 directory = argv[optind++]; 97 98 if (optind < argc) { 99 fprintf(stderr, "Unexpected argument: %s\n", argv[optind]); 100 usage(argv[0]); 101 exit(EXIT_FAILURE); 102 } 103 104 return make_ext4fs(filename, directory, mountpoint, android, gzip); 105} 106