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>
44 #include "mkfs_hammer2.h"
46 static void parse_fs_size(hammer2_mkfs_options_t
*, const char *);
47 static void usage(void);
50 main(int ac
, char **av
)
52 hammer2_mkfs_options_t opt
;
54 int label_specified
= 0;
57 * Initialize option structure.
59 hammer2_mkfs_init(&opt
);
64 while ((ch
= getopt(ac
, av
, "L:b:r:V:s:d")) != -1) {
67 opt
.BootAreaSize
= getsize(optarg
,
69 HAMMER2_BOOT_MAX_BYTES
, 2);
72 opt
.AuxAreaSize
= getsize(optarg
,
74 HAMMER2_AUX_MAX_BYTES
, 2);
77 opt
.Hammer2Version
= strtol(optarg
, NULL
, 0);
78 if (opt
.Hammer2Version
< HAMMER2_VOL_VERSION_MIN
||
79 opt
.Hammer2Version
>= HAMMER2_VOL_VERSION_WIP
) {
80 errx(1, "I don't understand how to format "
87 if (strcasecmp(optarg
, "none") == 0) {
90 if (opt
.NLabels
>= MAXLABELS
) {
91 errx(1, "Limit of %d local labels",
94 if (strlen(optarg
) == 0) {
95 errx(1, "Volume label '%s' cannot be 0-length",
98 if (strlen(optarg
) >= HAMMER2_INODE_MAXNAME
) {
99 errx(1, "Volume label '%s' is too long "
102 HAMMER2_INODE_MAXNAME
- 1);
104 opt
.Label
[opt
.NLabels
++] = strdup(optarg
);
107 parse_fs_size(&opt
, optarg
);
122 errx(1, "You must specify at least one disk device");
123 if (ac
> HAMMER2_MAX_VOLUMES
)
124 errx(1, "The maximum number of volumes is %d",
125 HAMMER2_MAX_VOLUMES
);
128 * Check default label type.
130 if (!label_specified
) {
131 char c
= av
[0][strlen(av
[0]) - 1];
133 opt
.DefaultLabelType
= HAMMER2_LABEL_BOOT
;
135 opt
.DefaultLabelType
= HAMMER2_LABEL_ROOT
;
137 opt
.DefaultLabelType
= HAMMER2_LABEL_DATA
;
141 * Create Hammer2 filesystem.
143 hammer2_mkfs(ac
, av
, &opt
);
146 * Cleanup option structure.
148 hammer2_mkfs_cleanup(&opt
);
155 parse_fs_size(hammer2_mkfs_options_t
*opt
, const char *arg
)
159 opt
->NFileSystemSizes
= 0;
162 while ((s
= p
) != NULL
) {
163 if ((p
= strchr(p
, ':')) != NULL
)
165 /* XXX 0x7fffffffffffffff isn't limitation of HAMMER2 */
166 opt
->FileSystemSize
[opt
->NFileSystemSizes
++] = getsize(s
,
167 HAMMER2_FREEMAP_LEVEL1_SIZE
,
168 0x7fffffffffffffff, 2);
169 if (opt
->NFileSystemSizes
>= HAMMER2_MAX_VOLUMES
)
180 "usage: newfs_hammer2 [-b bootsize] [-r auxsize] "
181 "[-V version] [-L label ...] [-s size] special ...\n"