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
38 void show_info(char *path);
39 double percent(int64_t value, int64_t total);
44 struct statfs *stfsbuf;
49 mntsize = getmntinfo(&stfsbuf, MNT_NOWAIT);
51 for (i=0; i < mntsize; i++) {
52 fstype = stfsbuf[i].f_fstypename;
53 path = stfsbuf[i].f_mntonname;
54 if ((strcmp(fstype, "hammer")) == 0)
59 fprintf(stdout, "No mounted filesystems found\n");
63 void show_info(char *path) {
65 int64_t usedbigblocks, bytes;
66 struct hammer_ioc_info info;
75 bzero(&info, sizeof(struct hammer_ioc_info));
77 /* Try to get a file descriptor based on the path given */
78 fd = open(path, O_RDONLY);
84 if ((ioctl(fd, HAMMERIOC_GET_INFO, &info)) < 0) {
89 /* Find out the UUID strings */
90 uuid_to_string(&info.vol_fsid, &fsid, NULL);
92 /* Volume information */
93 fprintf(stdout, "Volume identification\n");
94 fprintf(stdout, "\tLabel %s\n", info.vol_name);
95 fprintf(stdout, "\tNo. Volumes %d\n", info.nvolumes);
96 fprintf(stdout, "\tFSID %s\n", fsid);
98 /* Big blocks information */
99 usedbigblocks = info.bigblocks - info.freebigblocks;
101 fprintf(stdout, "Big block information\n");
102 fprintf(stdout, "\tTotal\t %lld\n", info.bigblocks);
103 fprintf(stdout, "\tUsed\t %lld (%.2lf%%)\n\tReserved %lld (%.2lf%%)\n\tFree\t %lld (%.2lf%%)\n",
104 usedbigblocks, percent(usedbigblocks, info.bigblocks),
105 info.rsvbigblocks, percent(info.rsvbigblocks, info.bigblocks),
106 (info.freebigblocks - info.rsvbigblocks),
107 percent(info.freebigblocks - info.rsvbigblocks, info.bigblocks));
108 fprintf(stdout, "Space information\n");
110 /* Space information */
111 bytes = (info.bigblocks << HAMMER_LARGEBLOCK_BITS);
112 humanize_number(buf, sizeof(buf) - (bytes < 0 ? 0 : 1), bytes, "", HN_AUTOSCALE, HN_DECIMAL | HN_NOSPACE | HN_B);
113 fprintf(stdout, "\tTotal size %6s (%lld bytes)\n", buf, bytes);
115 bytes = (usedbigblocks << HAMMER_LARGEBLOCK_BITS);
116 humanize_number(buf, sizeof(buf) - (bytes < 0 ? 0 : 1), bytes, "", HN_AUTOSCALE, HN_DECIMAL | HN_NOSPACE | HN_B);
117 fprintf(stdout, "\tUsed space %6s\n", buf);
119 bytes = (info.rsvbigblocks << HAMMER_LARGEBLOCK_BITS);
120 humanize_number(buf, sizeof(buf) - (bytes < 0 ? 0 : 1), bytes, "", HN_AUTOSCALE, HN_DECIMAL | HN_NOSPACE | HN_B);
121 fprintf(stdout, "\tReserved space %6s\n", buf);
123 bytes = ((info.freebigblocks - info.rsvbigblocks) << HAMMER_LARGEBLOCK_BITS);
124 humanize_number(buf, sizeof(buf) - (bytes < 0 ? 0 : 1), bytes, "", HN_AUTOSCALE, HN_DECIMAL | HN_NOSPACE | HN_B);
125 fprintf(stdout, "\tFree space %6s\n\n", buf);
128 double percent(int64_t value, int64_t total) {
130 /* Avoid divide-by-zero */
134 return ((value * 100.0) / (double)total);