2 * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 #include <ext4_mkfs.h>
42 #include "../blockdev/linux/ext4_filedev.h"
43 #include "../blockdev/windows/io_raw.h"
45 /**@brief Input stream name.*/
46 const char *input_name = NULL;
48 /**@brief Block device handle.*/
49 static struct ext4_blockdev *bd;
51 /**@brief Indicates that input is windows partition.*/
52 static bool winpart = false;
54 static const char *usage = " \n\
55 Welcome in lwext4_mkfs tool . \n\
56 Copyright (c) 2015 Grzegorz Kostka (kostka.grzegorz@gmail.com) \n\
58 [-i] --input - input file name (or blockdevice) \n\
59 [-w] --wpart - windows partition mode \n\
63 static bool open_linux(void)
65 ext4_filedev_filename(input_name);
66 bd = ext4_filedev_get();
68 printf("open_filedev: fail\n");
74 static bool open_windows(void)
77 ext4_io_raw_filename(input_name);
78 bd = ext4_io_raw_dev_get();
80 printf("open_winpartition: fail\n");
85 printf("open_winpartition: this mode should be used only under windows "
91 static bool open_filedev(void)
105 static bool parse_opt(int argc, char **argv)
107 int option_index = 0;
110 static struct option long_options[] = {
111 {"input", required_argument, 0, 'i'},
112 {"wpart", no_argument, 0, 'w'},
115 while (-1 != (c = getopt_long(argc, argv, "i:w",
116 long_options, &option_index))) {
133 int main(int argc, char **argv)
135 if (!parse_opt(argc, argv))
141 static struct ext4_mkfs_info info;
142 int r = ext4_mkfs(bd, &info);