2 * Copyright 2008 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",
41 /*! Print program help and exit */
43 print_help_exit(bool out
)
53 const char* kFormat
= "%-10s %-25s %s\n";
54 BDiskDeviceRoster roster
;
55 BDiskSystem diskSystem
;
57 printf("Installed file systems that support initializing:\n\n");
58 printf(kFormat
, "Name", "Pretty Name", "Module");
59 printf(kFormat
, "--", "--", "--");
61 while (roster
.GetNextDiskSystem(&diskSystem
) == B_OK
) {
62 if (!diskSystem
.SupportsInitializing()
63 || !diskSystem
.IsFileSystem())
66 printf(kFormat
, diskSystem
.ShortName(), diskSystem
.PrettyName(),
73 main(int argc
, char* const* argv
)
75 const struct option kLongOptions
[] = {
76 { "help", 0, NULL
, 'h' },
77 { "options", 0, NULL
, 'o' },
78 { "type", 1, NULL
, 't' },
79 { "list-types", 0, NULL
, 'l' },
80 { "verbose", 0, NULL
, 'v' },
81 { "dont-ask", 0, NULL
, 'q' },
84 const char* kShortOptions
= "t:o:lhvq";
86 // parse argument list
87 const char* fsType
= "bfs";
88 const char* fsOptions
= NULL
;
93 int nextOption
= getopt_long(argc
, argv
, kShortOptions
, kLongOptions
,
99 case 't': // -t or --type
102 case 'h': // -h or --help
103 print_help_exit(true);
105 case 'v': // -v or --verbose
108 case 'o': // -o or --options
111 case 'q': // -q or --quick
114 case 'l': // list types
117 case '?': // invalid option
119 case -1: // done with options
121 default: // everything else
127 // the device name should be the first non-option element
128 // right before the volume name
129 if (optind
> argc
- 1)
130 print_help_exit(false);
132 const char* device
= argv
[optind
];
133 const char* volumeName
= NULL
;
134 if (optind
== argc
- 2)
135 volumeName
= argv
[argc
- 1];
137 if (!strncmp(device
, "/dev", 4))
138 volumeName
= "Unnamed";
140 volumeName
= "Unnamed Image";
143 FsCreator
creator(device
, fsType
, volumeName
, fsOptions
, quick
, verbose
);
144 return creator
.Run() ? 0 : 1;