Doug Zongker | 263eefd | 2010-06-29 17:23:14 -0700 | [diff] [blame] | 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"); |
Ken Sumrall | 75249ed | 2010-08-13 16:04:49 -0700 | [diff] [blame] | 36 | fprintf(stderr, " [ -z | -s ] [ -J ]\n"); |
Doug Zongker | 263eefd | 2010-06-29 17:23:14 -0700 | [diff] [blame] | 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; |
Ken Sumrall | 75249ed | 2010-08-13 16:04:49 -0700 | [diff] [blame] | 48 | int sparse = 0; |
Colin Cross | 757ace5 | 2010-12-29 13:57:01 -0800 | [diff] [blame] | 49 | int crc = 0; |
Colin Cross | c247065 | 2011-01-26 16:39:46 -0800 | [diff] [blame^] | 50 | int wipe = 0; |
Doug Zongker | 263eefd | 2010-06-29 17:23:14 -0700 | [diff] [blame] | 51 | |
Colin Cross | c247065 | 2011-01-26 16:39:46 -0800 | [diff] [blame^] | 52 | while ((opt = getopt(argc, argv, "l:j:b:g:i:I:L:a:fwzJsc")) != -1) { |
Doug Zongker | 263eefd | 2010-06-29 17:23:14 -0700 | [diff] [blame] | 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; |
Colin Cross | c247065 | 2011-01-26 16:39:46 -0800 | [diff] [blame^] | 82 | case 'w': |
| 83 | wipe = 1; |
| 84 | break; |
Doug Zongker | 263eefd | 2010-06-29 17:23:14 -0700 | [diff] [blame] | 85 | case 'z': |
| 86 | gzip = 1; |
| 87 | break; |
Colin Cross | e4b5ae8 | 2010-08-03 14:10:07 -0700 | [diff] [blame] | 88 | case 'J': |
| 89 | info.no_journal = 1; |
| 90 | break; |
Colin Cross | 757ace5 | 2010-12-29 13:57:01 -0800 | [diff] [blame] | 91 | case 'c': |
| 92 | crc = 1; |
| 93 | break; |
Ken Sumrall | 75249ed | 2010-08-13 16:04:49 -0700 | [diff] [blame] | 94 | case 's': |
| 95 | sparse = 1; |
| 96 | break; |
Doug Zongker | 263eefd | 2010-06-29 17:23:14 -0700 | [diff] [blame] | 97 | default: /* '?' */ |
| 98 | usage(argv[0]); |
| 99 | exit(EXIT_FAILURE); |
| 100 | } |
| 101 | } |
| 102 | |
Ken Sumrall | 75249ed | 2010-08-13 16:04:49 -0700 | [diff] [blame] | 103 | if (gzip && sparse) { |
| 104 | fprintf(stderr, "Cannot specify both gzip and sparse\n"); |
| 105 | usage(argv[0]); |
| 106 | exit(EXIT_FAILURE); |
| 107 | } |
| 108 | |
Colin Cross | c247065 | 2011-01-26 16:39:46 -0800 | [diff] [blame^] | 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 | |
Doug Zongker | 263eefd | 2010-06-29 17:23:14 -0700 | [diff] [blame] | 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 | |
Ken Sumrall | 983fb19 | 2011-01-19 17:15:42 -0800 | [diff] [blame] | 138 | return make_ext4fs_internal(filename, directory, mountpoint, android, gzip, |
Colin Cross | c247065 | 2011-01-26 16:39:46 -0800 | [diff] [blame^] | 139 | sparse, crc, wipe); |
Doug Zongker | 263eefd | 2010-06-29 17:23:14 -0700 | [diff] [blame] | 140 | } |