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
34 * $DragonFly: src/sbin/hammer/hammer.c,v 1.25 2008/06/24 02:42:48 dillon Exp $
41 static void hammer_parsedevs(const char *blkdevs);
42 static void sigalrm(int signo);
43 static void usage(int exit_code);
48 const char *CyclePath;
52 main(int ac, char **av)
59 while ((ch = getopt(ac, av, "c:dhf:rs:t:v")) != -1) {
80 timeout = strtol(optarg, NULL, 0);
98 signal(SIGALRM, sigalrm);
102 if (strcmp(av[0], "synctid") == 0) {
103 hammer_cmd_synctid(av + 1, ac - 1);
106 if (strcmp(av[0], "namekey") == 0) {
111 key = (int64_t)(crc32(av[1], strlen(av[1])) & 0x7FFFFFFF) << 32;
113 key |= 0x100000000LL;
114 printf("0x%016llx\n", key);
117 if (strcmp(av[0], "namekey32") == 0) {
122 key = crc32(av[1], strlen(av[1])) & 0x7FFFFFFF;
125 printf("0x%08x\n", key);
128 if (strcmp(av[0], "pseudofs") == 0) {
129 hammer_cmd_pseudofs(av + 1, ac - 1);
132 if (strcmp(av[0], "prune") == 0) {
133 hammer_cmd_softprune(av + 1, ac - 1, 0);
136 if (strcmp(av[0], "prune-everything") == 0) {
137 hammer_cmd_softprune(av + 1, ac - 1, 1);
140 if (strcmp(av[0], "bstats") == 0) {
141 hammer_cmd_bstats(av + 1, ac - 1);
144 if (strcmp(av[0], "iostats") == 0) {
145 hammer_cmd_iostats(av + 1, ac - 1);
149 if (strncmp(av[0], "history", 7) == 0) {
150 hammer_cmd_history(av[0] + 7, av + 1, ac - 1);
153 if (strncmp(av[0], "reblock", 7) == 0) {
154 if (strcmp(av[0], "reblock") == 0)
155 hammer_cmd_reblock(av + 1, ac - 1, -1);
156 else if (strcmp(av[0], "reblock-btree") == 0)
157 hammer_cmd_reblock(av + 1, ac - 1, HAMMER_IOC_DO_BTREE);
158 else if (strcmp(av[0], "reblock-inodes") == 0)
159 hammer_cmd_reblock(av + 1, ac - 1, HAMMER_IOC_DO_INODES);
160 else if (strcmp(av[0], "reblock-dirs") == 0)
161 hammer_cmd_reblock(av + 1, ac - 1, HAMMER_IOC_DO_DIRS);
162 else if (strcmp(av[0], "reblock-data") == 0)
163 hammer_cmd_reblock(av + 1, ac - 1, HAMMER_IOC_DO_DATA);
169 uuid_name_lookup(&Hammer_FSType, "DragonFly HAMMER", &status);
170 if (status != uuid_s_ok) {
171 errx(1, "uuids file does not have the DragonFly "
172 "HAMMER filesystem type");
175 if (strcmp(av[0], "show") == 0) {
176 hammer_off_t node_offset = (hammer_off_t)-1;
178 hammer_parsedevs(blkdevs);
180 sscanf(av[1], "%llx", &node_offset);
181 hammer_cmd_show(node_offset, 0, NULL, NULL);
184 if (strcmp(av[0], "blockmap") == 0) {
185 hammer_parsedevs(blkdevs);
186 hammer_cmd_blockmap();
196 hammer_parsedevs(const char *blkdevs)
201 if (blkdevs == NULL) {
202 errx(1, "A -f blkdevs specification is required "
206 copy = strdup(blkdevs);
207 while ((volname = copy) != NULL) {
208 if ((copy = strchr(copy, ':')) != NULL)
210 setup_volume(-1, volname, 0, O_RDONLY);
216 sigalrm(int signo __unused)
218 /* do nothing (interrupts HAMMER ioctl) */
227 "hammer [-t timeout] [-c cyclefile] ....\n"
228 "hammer prune <softlink-dir>\n"
229 "hammer prune-everything <filesystem>\n"
230 "hammer bstats <interval>\n"
231 "hammer iostats <interval>\n"
232 "hammer reblock[-btree/inodes/dirs/data] "
233 "<filesystem> [pack%%]\n"
234 "hammer pseudofs <dirpath>\n"
235 "hammer history[@offset[,len]] <file-1>...<file-N>\n"
236 "hammer -f blkdevs [-r] show\n"
237 "hammer -f blkdevs blockmap\n"