2 * Copyright 2008-2017 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Marco Minutoli, mminutoli@gmail.com
7 * Axel Dörfler, axeld@pinc-software.de
14 #include <DiskSystem.h>
16 #include "FsCreator.h"
19 extern "C" const char* __progname
;
20 static const char* kProgramName
= __progname
;
23 /*! Print program help on the right stream */
27 fprintf(out
? stdout
: stderr
,
28 "Usage: %s <options> <device> <volume name>\n"
31 " -t, --type <fs> - set type of file system to create\n\n"
32 " -l, --list-types - list file systems that support initializing\n"
33 " -h, --help - print this help text\n"
34 " -o, --options <opt> - set fs specific options\n"
35 " -q, --dont-ask - do not ask before initializing\n"
36 " -v, --verbose - set verbose output\n"
39 " mkfs -t bfs -o 'block_size 4096; noindex' ./test.image Data\n"
40 "\tThis will initialize \"test.image\" with BFS with a block\n"
41 "\tsize of 4096 bytes, without index, and named \"Data\".\n",
46 /*! Print program help and exit */
48 print_help_exit(bool out
)
58 const char* kFormat
= "%-10s %-25s %s\n";
59 BDiskDeviceRoster roster
;
60 BDiskSystem diskSystem
;
62 printf("Installed file systems that support initializing:\n\n");
63 printf(kFormat
, "Name", "Pretty Name", "Module");
64 printf(kFormat
, "--", "--", "--");
66 while (roster
.GetNextDiskSystem(&diskSystem
) == B_OK
) {
67 if (!diskSystem
.SupportsInitializing()
68 || !diskSystem
.IsFileSystem())
71 printf(kFormat
, diskSystem
.ShortName(), diskSystem
.PrettyName(),
78 main(int argc
, char* const* argv
)
80 const struct option kLongOptions
[] = {
81 { "help", 0, NULL
, 'h' },
82 { "options", 0, NULL
, 'o' },
83 { "type", 1, NULL
, 't' },
84 { "list-types", 0, NULL
, 'l' },
85 { "verbose", 0, NULL
, 'v' },
86 { "dont-ask", 0, NULL
, 'q' },
89 const char* kShortOptions
= "t:o:lhvq";
91 // parse argument list
92 const char* fsType
= "bfs";
93 const char* fsOptions
= NULL
;
98 int nextOption
= getopt_long(argc
, argv
, kShortOptions
, kLongOptions
,
100 if (nextOption
== -1)
103 switch (nextOption
) {
104 case 't': // -t or --type
107 case 'h': // -h or --help
108 print_help_exit(true);
110 case 'v': // -v or --verbose
113 case 'o': // -o or --options
116 case 'q': // -q or --quick
119 case 'l': // list types
122 case '?': // invalid option
124 case -1: // done with options
126 default: // everything else
132 // the device name should be the first non-option element
133 // right before the volume name
134 if (optind
> argc
- 1)
135 print_help_exit(false);
137 const char* device
= argv
[optind
];
138 const char* volumeName
= NULL
;
139 if (optind
== argc
- 2)
140 volumeName
= argv
[argc
- 1];
142 if (!strncmp(device
, "/dev", 4))
143 volumeName
= "Unnamed";
145 volumeName
= "Unnamed Image";
148 FsCreator
creator(device
, fsType
, volumeName
, fsOptions
, quick
, verbose
);
149 return creator
.Run() ? 0 : 1;