2 * Copyright (c) 2009 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Antonio Huete <tuxillo@quantumachine.net>
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 <libhammer.h>
40 void show_info(char *path);
41 static double percent(int64_t value, int64_t total);
46 struct statfs *stfsbuf;
47 int mntsize, i, first = 1;
51 mntsize = getmntinfo(&stfsbuf, MNT_NOWAIT);
53 for (i = 0; i < mntsize; i++) {
54 fstype = stfsbuf[i].f_fstypename;
55 path = stfsbuf[i].f_mntonname;
56 if ((strcmp(fstype, "hammer")) == 0) {
60 fprintf(stdout, "\n");
65 fprintf(stdout, "No mounted filesystems found\n");
73 libhammer_volinfo_t hvi;
74 libhammer_pfsinfo_t pi, pi_first;
75 int64_t usedbigblocks;
76 int64_t usedbytes, rsvbytes;
77 int64_t totalbytes, freebytes;
84 usedbytes = totalbytes = rsvbytes = freebytes = 0;
86 hvi = libhammer_get_volinfo(path);
88 perror("libhammer_get_volinfo");
92 /* Find out the UUID strings */
93 uuid_to_string(&hvi->vol_fsid, &fsid, NULL);
95 /* Volume information */
96 fprintf(stdout, "Volume identification\n");
97 fprintf(stdout, "\tLabel %s\n", hvi->vol_name);
98 fprintf(stdout, "\tNo. Volumes %d\n", hvi->nvolumes);
99 fprintf(stdout, "\tFSID %s\n", fsid);
100 fprintf(stdout, "\tHAMMER Version %d\n", hvi->version);
102 /* Big blocks information */
103 usedbigblocks = hvi->bigblocks - hvi->freebigblocks;
105 fprintf(stdout, "Big block information\n");
106 fprintf(stdout, "\tTotal %10jd\n", (intmax_t)hvi->bigblocks);
107 fprintf(stdout, "\tUsed %10jd (%.2lf%%)\n"
108 "\tReserved %10jd (%.2lf%%)\n"
109 "\tFree %10jd (%.2lf%%)\n",
110 (intmax_t)usedbigblocks,
111 percent(usedbigblocks, hvi->bigblocks),
112 (intmax_t)hvi->rsvbigblocks,
113 percent(hvi->rsvbigblocks, hvi->bigblocks),
114 (intmax_t)(hvi->freebigblocks - hvi->rsvbigblocks),
115 percent(hvi->freebigblocks - hvi->rsvbigblocks,
117 fprintf(stdout, "Space information\n");
119 /* Space information */
120 totalbytes = (hvi->bigblocks << HAMMER_LARGEBLOCK_BITS);
121 usedbytes = (usedbigblocks << HAMMER_LARGEBLOCK_BITS);
122 rsvbytes = (hvi->rsvbigblocks << HAMMER_LARGEBLOCK_BITS);
123 freebytes = ((hvi->freebigblocks - hvi->rsvbigblocks)
124 << HAMMER_LARGEBLOCK_BITS);
126 fprintf(stdout, "\tNo. Inodes %10jd\n", (intmax_t)hvi->inodes);
127 humanize_number(buf, sizeof(buf) - (totalbytes < 0 ? 0 : 1),
128 totalbytes, "", HN_AUTOSCALE, HN_DECIMAL | HN_NOSPACE | HN_B);
129 fprintf(stdout, "\tTotal size %6s (%jd bytes)\n",
130 buf, (intmax_t)totalbytes);
132 humanize_number(buf, sizeof(buf) - (usedbytes < 0 ? 0 : 1),
133 usedbytes, "", HN_AUTOSCALE, HN_DECIMAL | HN_NOSPACE | HN_B);
134 fprintf(stdout, "\tUsed %6s (%.2lf%%)\n", buf,
135 percent(usedbytes, totalbytes));
137 humanize_number(buf, sizeof(buf) - (rsvbytes < 0 ? 0 : 1),
138 rsvbytes, "", HN_AUTOSCALE, HN_DECIMAL | HN_NOSPACE | HN_B);
139 fprintf(stdout, "\tReserved %6s (%.2lf%%)\n", buf,
140 percent(rsvbytes, totalbytes));
142 humanize_number(buf, sizeof(buf) - (freebytes < 0 ? 0 : 1),
143 freebytes, "", HN_AUTOSCALE, HN_DECIMAL | HN_NOSPACE | HN_B);
144 fprintf(stdout, "\tFree %6s (%.2lf%%)\n", buf,
145 percent(freebytes, totalbytes));
147 /* Pseudo-filesystem information */
148 fprintf(stdout, "PFS information\n");
149 fprintf(stdout, "\tPFS ID Mode Snaps Mounted on\n");
151 /* Iterate all the PFSs found */
152 pi_first = libhammer_get_first_pfs(hvi);
153 for (pi = pi_first; pi != NULL; pi = libhammer_get_next_pfs(pi)) {
154 fprintf(stdout, "\t%6d %-6s",
155 pi->pfs_id, (pi->ismaster ? "MASTER" : "SLAVE"));
157 snprintf(buf, 6, "%d", pi->snapcount);
158 fprintf(stdout, " %6s ", (pi->head.error && pi->snapcount == 0) ? "-" : buf);
161 fprintf(stdout, "%s", pi->mountedon);
163 fprintf(stdout, "not mounted");
165 fprintf(stdout, "\n");
170 libhammer_free_volinfo(hvi);
175 percent(int64_t value, int64_t total)
177 /* Avoid divide-by-zero */
181 return ((value * 100.0) / (double)total);