1367431cfSMatthew Dillon /*
2367431cfSMatthew Dillon * Copyright (c) 2008 The DragonFly Project. All rights reserved.
3367431cfSMatthew Dillon *
4367431cfSMatthew Dillon * This code is derived from software contributed to The DragonFly Project
5367431cfSMatthew Dillon * by Matthew Dillon <dillon@backplane.com>
6367431cfSMatthew Dillon *
7367431cfSMatthew Dillon * Redistribution and use in source and binary forms, with or without
8367431cfSMatthew Dillon * modification, are permitted provided that the following conditions
9367431cfSMatthew Dillon * are met:
10367431cfSMatthew Dillon *
11367431cfSMatthew Dillon * 1. Redistributions of source code must retain the above copyright
12367431cfSMatthew Dillon * notice, this list of conditions and the following disclaimer.
13367431cfSMatthew Dillon * 2. Redistributions in binary form must reproduce the above copyright
14367431cfSMatthew Dillon * notice, this list of conditions and the following disclaimer in
15367431cfSMatthew Dillon * the documentation and/or other materials provided with the
16367431cfSMatthew Dillon * distribution.
17367431cfSMatthew Dillon * 3. Neither the name of The DragonFly Project nor the names of its
18367431cfSMatthew Dillon * contributors may be used to endorse or promote products derived
19367431cfSMatthew Dillon * from this software without specific, prior written permission.
20367431cfSMatthew Dillon *
21367431cfSMatthew Dillon * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22367431cfSMatthew Dillon * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23367431cfSMatthew Dillon * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24367431cfSMatthew Dillon * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25367431cfSMatthew Dillon * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26367431cfSMatthew Dillon * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27367431cfSMatthew Dillon * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28367431cfSMatthew Dillon * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29367431cfSMatthew Dillon * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30367431cfSMatthew Dillon * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31367431cfSMatthew Dillon * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32367431cfSMatthew Dillon * SUCH DAMAGE.
33367431cfSMatthew Dillon *
34367431cfSMatthew Dillon * $DragonFly: src/sbin/hammer/cmd_synctid.c,v 1.1 2008/05/13 20:49:34 dillon Exp $
35367431cfSMatthew Dillon */
36367431cfSMatthew Dillon
37367431cfSMatthew Dillon #include "hammer.h"
38367431cfSMatthew Dillon
39367431cfSMatthew Dillon static void synctid_usage(int exit_code);
40367431cfSMatthew Dillon
41367431cfSMatthew Dillon /*
42367431cfSMatthew Dillon * synctid <filesystem> [quick]
43367431cfSMatthew Dillon */
44367431cfSMatthew Dillon void
hammer_cmd_synctid(char ** av,int ac)45367431cfSMatthew Dillon hammer_cmd_synctid(char **av, int ac)
46367431cfSMatthew Dillon {
47367431cfSMatthew Dillon struct hammer_ioc_synctid synctid;
48367431cfSMatthew Dillon const char *filesystem;
49367431cfSMatthew Dillon int fd;
50367431cfSMatthew Dillon
51367431cfSMatthew Dillon bzero(&synctid, sizeof(synctid));
52367431cfSMatthew Dillon synctid.op = HAMMER_SYNCTID_SYNC2;
53367431cfSMatthew Dillon
54*88cdee70STomohiro Kusumi if (ac == 0 || ac > 2) {
55367431cfSMatthew Dillon synctid_usage(1);
56*88cdee70STomohiro Kusumi /* not reached */
57*88cdee70STomohiro Kusumi }
58367431cfSMatthew Dillon filesystem = av[0];
59367431cfSMatthew Dillon if (ac == 2) {
60*88cdee70STomohiro Kusumi if (strcmp(av[1], "quick") == 0) {
61367431cfSMatthew Dillon synctid.op = HAMMER_SYNCTID_SYNC1;
62*88cdee70STomohiro Kusumi } else {
63367431cfSMatthew Dillon synctid_usage(1);
64*88cdee70STomohiro Kusumi /* not reached */
65*88cdee70STomohiro Kusumi }
66367431cfSMatthew Dillon }
67367431cfSMatthew Dillon fd = open(filesystem, O_RDONLY);
68052fd72bSTomohiro Kusumi if (fd < 0) {
69367431cfSMatthew Dillon err(1, "Unable to open %s", filesystem);
70052fd72bSTomohiro Kusumi /* not reached */
71052fd72bSTomohiro Kusumi }
72052fd72bSTomohiro Kusumi if (ioctl(fd, HAMMERIOC_SYNCTID, &synctid) < 0) {
73f4bb1f26STomohiro Kusumi err(1, "Synctid %s failed", filesystem);
74052fd72bSTomohiro Kusumi /* not reached */
75052fd72bSTomohiro Kusumi } else {
76a276dc6bSMatthew Dillon printf("0x%016jx\n", (uintmax_t)synctid.tid);
77052fd72bSTomohiro Kusumi }
78367431cfSMatthew Dillon close(fd);
79367431cfSMatthew Dillon }
80367431cfSMatthew Dillon
81367431cfSMatthew Dillon static
82367431cfSMatthew Dillon void
synctid_usage(int exit_code)83367431cfSMatthew Dillon synctid_usage(int exit_code)
84367431cfSMatthew Dillon {
85367431cfSMatthew Dillon fprintf(stderr, "hammer synctid <filesystem> [quick]\n");
86367431cfSMatthew Dillon exit(exit_code);
87367431cfSMatthew Dillon }
88367431cfSMatthew Dillon
89