2 * Copyright (c) 2011-2015 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@dragonflybsd.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/types.h>
45 #include "mkfs_hammer2.h"
47 static void parse_fs_size(hammer2_mkfs_options_t
*, const char *);
48 static void usage(void);
51 main(int ac
, char **av
)
53 hammer2_mkfs_options_t opt
;
55 int label_specified
= 0;
58 * Initialize option structure.
60 hammer2_mkfs_init(&opt
);
65 while ((ch
= getopt(ac
, av
, "L:b:r:V:s:d")) != -1) {
68 opt
.BootAreaSize
= getsize(optarg
,
70 HAMMER2_BOOT_MAX_BYTES
, 2);
73 opt
.AuxAreaSize
= getsize(optarg
,
75 HAMMER2_AUX_MAX_BYTES
, 2);
78 opt
.Hammer2Version
= strtol(optarg
, NULL
, 0);
79 if (opt
.Hammer2Version
< HAMMER2_VOL_VERSION_MIN
||
80 opt
.Hammer2Version
>= HAMMER2_VOL_VERSION_WIP
) {
81 errx(1, "I don't understand how to format "
88 if (strcasecmp(optarg
, "none") == 0) {
91 if (opt
.NLabels
>= MAXLABELS
) {
92 errx(1, "Limit of %d local labels",
95 if (strlen(optarg
) == 0) {
96 errx(1, "Volume label '%s' cannot be 0-length",
99 if (strlen(optarg
) >= HAMMER2_INODE_MAXNAME
) {
100 errx(1, "Volume label '%s' is too long "
103 HAMMER2_INODE_MAXNAME
- 1);
105 opt
.Label
[opt
.NLabels
++] = strdup(optarg
);
108 parse_fs_size(&opt
, optarg
);
123 errx(1, "You must specify at least one disk device");
124 if (ac
> HAMMER2_MAX_VOLUMES
)
125 errx(1, "The maximum number of volumes is %d",
126 HAMMER2_MAX_VOLUMES
);
129 * Check default label type.
131 if (!label_specified
) {
132 char c
= av
[0][strlen(av
[0]) - 1];
134 opt
.DefaultLabelType
= HAMMER2_LABEL_BOOT
;
136 opt
.DefaultLabelType
= HAMMER2_LABEL_ROOT
;
138 opt
.DefaultLabelType
= HAMMER2_LABEL_DATA
;
142 * Create Hammer2 filesystem.
144 assert(opt
.CompType
== HAMMER2_COMP_DEFAULT
);
145 assert(opt
.CheckType
== HAMMER2_CHECK_DEFAULT
);
146 hammer2_mkfs(ac
, av
, &opt
);
149 * Cleanup option structure.
151 hammer2_mkfs_cleanup(&opt
);
158 parse_fs_size(hammer2_mkfs_options_t
*opt
, const char *arg
)
162 opt
->NFileSystemSizes
= 0;
165 while ((s
= p
) != NULL
) {
166 if ((p
= strchr(p
, ':')) != NULL
)
168 /* XXX 0x7fffffffffffffff isn't limitation of HAMMER2 */
169 opt
->FileSystemSize
[opt
->NFileSystemSizes
++] = getsize(s
,
170 HAMMER2_FREEMAP_LEVEL1_SIZE
,
171 0x7fffffffffffffff, 2);
172 if (opt
->NFileSystemSizes
>= HAMMER2_MAX_VOLUMES
)
183 "usage: newfs_hammer2 [-b bootsize] [-r auxsize] "
184 "[-V version] [-L label ...] [-s size] special ...\n"