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>
36 #include <sys/param.h>
45 #include "mkfs_hammer2.h"
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 /* XXX 0x7fffffffffffffff isn't limitation of HAMMER2 */
108 opt.FileSystemSize = getsize(optarg,
109 HAMMER2_FREEMAP_LEVEL1_SIZE,
110 0x7fffffffffffffff, 2);
125 errx(1, "You must specify at least one disk device");
126 if (ac > HAMMER2_MAX_VOLUMES)
127 errx(1, "The maximum number of volumes is %d",
128 HAMMER2_MAX_VOLUMES);
131 * Check default label type.
133 if (!label_specified) {
134 char c = av[0][strlen(av[0]) - 1];
136 opt.DefaultLabelType = HAMMER2_LABEL_BOOT;
138 opt.DefaultLabelType = HAMMER2_LABEL_ROOT;
140 opt.DefaultLabelType = HAMMER2_LABEL_DATA;
144 * Create Hammer2 filesystem.
146 hammer2_mkfs(ac, av, &opt);
149 * Cleanup option structure.
151 hammer2_mkfs_cleanup(&opt);
161 "usage: newfs_hammer2 [-b bootsize] [-r auxsize] "
162 "[-V version] [-L label ...] [-s size] special ...\n"