2 * Copyright (c) 2007 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
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>
37 #include <vfs/hammer/hammer_mount.h>
49 static void test_master_id(int master_id);
50 static void extract_volumes(struct hammer_mount_info *info, char **av, int ac);
51 static void free_volumes(struct hammer_mount_info *info);
52 static void usage(void);
54 #define hwarnx(format, args...) warnx("WARNING: "format,## args)
56 #define MOPT_HAMMEROPTS \
57 { "history", 1, HMNT_NOHISTORY, 1 }, \
58 { "master=", 0, HMNT_MASTERID, 1 }, \
59 { "mirror", 1, HMNT_NOMIRROR, 1 }
61 static struct mntopt mopts[] = { MOPT_STDOPTS, MOPT_HAMMEROPTS,
62 MOPT_UPDATE, MOPT_NULL };
65 main(int ac, char **av)
67 struct hammer_mount_info info;
76 bzero(&info, sizeof(info));
78 while ((ch = getopt(ac, av, "o:T:u")) != -1) {
81 info.asof = strtoull(optarg, NULL, 0);
84 getmntopts(optarg, mopts, &mount_flags, &info.hflags);
87 * Handle extended flags with parameters.
89 if (info.hflags & HMNT_MASTERID) {
90 ptr = strstr(optarg, "master=");
92 info.master_id = strtol(ptr + 7, NULL, 0);
93 test_master_id(info.master_id);
96 if (info.hflags & HMNT_NOMIRROR) {
97 ptr = strstr(optarg, "nomirror");
103 init_flags |= MNT_UPDATE;
113 mount_flags |= init_flags;
116 * Only the mount point need be specified in update mode.
118 if (init_flags & MNT_UPDATE) {
124 if (mount(vfc.vfc_name, mountpt, mount_flags, &info)) {
125 err(1, "mountpoint %s", mountpt);
137 * Mount arguments: vol [vol...] mountpt
139 extract_volumes(&info, av, ac - 1);
140 mountpt = av[ac - 1];
143 * Load the hammer module if necessary (this bit stolen from
146 error = getvfsbyname("hammer", &vfc);
147 if (error && vfsisloadable("hammer")) {
148 if (vfsload("hammer") != 0) {
149 err(1, "vfsload(hammer)");
153 error = getvfsbyname("hammer", &vfc);
156 errx(1, "hammer filesystem is not available");
160 if (mount(vfc.vfc_name, mountpt, mount_flags, &info)) {
171 test_master_id(int master_id)
175 hwarnx("A master id of 0 is the default, "
176 "explicit settings should use 1-15");
179 hwarnx("A master id of -1 is nomirror mode, "
180 "equivalent to -o nomirror option");
182 case 1 ... 15: /* gcc */
183 /* Expected values via -o master= option */
186 /* This will eventually fail in hammer_vfs_mount() */
187 hwarnx("A master id of %d is not supported", master_id);
193 * Extract a volume list
197 extract_volumes(struct hammer_mount_info *info, char **av, int ac)
201 char **ary, *ptr, *next, *orig;
203 #define _extend_ary(ary, arymax) ({ \
205 realloc(ary, (arymax) * sizeof(char *)); \
207 ary = calloc(arymax, sizeof(char *));
211 ary = _extend_ary(ary, arymax);
212 if (strchr(*av, ':') == NULL) {
213 ary[idx++] = strdup(*av);
215 orig = next = strdup(*av);
216 while ((ptr = next) != NULL) {
218 ary = _extend_ary(ary, arymax);
219 if ((next = strchr(ptr, ':')) != NULL)
221 ary[idx++] = strdup(ptr);
228 info->nvolumes = idx;
234 free_volumes(struct hammer_mount_info *info)
238 for (i = 0; i < info->nvolumes; i++)
239 free(info->volumes[i]);
247 fprintf(stderr, "usage: mount_hammer [-o options] [-T transaction-id] "
248 "special ... node\n");
249 fprintf(stderr, " mount_hammer [-o options] [-T transaction-id] "
250 "special[:special]* node\n");
251 fprintf(stderr, " mount_hammer -u [-o options] node\n");