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