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 %jd\n", (intmax_t)info
.bigblocks
);
103 fprintf(stdout
, "\tUsed\t %jd (%.2lf%%)\n\tReserved "
104 "%jd (%.2lf%%)\n\tFree\t "
106 (intmax_t)usedbigblocks
,
107 percent(usedbigblocks
, info
.bigblocks
),
108 (intmax_t)info
.rsvbigblocks
,
109 percent(info
.rsvbigblocks
, info
.bigblocks
),
110 (intmax_t)(info
.freebigblocks
- info
.rsvbigblocks
),
111 percent(info
.freebigblocks
- info
.rsvbigblocks
,
113 fprintf(stdout
, "Space information\n");
115 /* Space information */
116 bytes
= (info
.bigblocks
<< HAMMER_LARGEBLOCK_BITS
);
117 humanize_number(buf
, sizeof(buf
) - (bytes
< 0 ? 0 : 1), bytes
, "", HN_AUTOSCALE
, HN_DECIMAL
| HN_NOSPACE
| HN_B
);
118 fprintf(stdout
, "\tTotal size %6s (%jd bytes)\n",
119 buf
, (intmax_t)bytes
);
121 bytes
= (usedbigblocks
<< HAMMER_LARGEBLOCK_BITS
);
122 humanize_number(buf
, sizeof(buf
) - (bytes
< 0 ? 0 : 1), bytes
, "", HN_AUTOSCALE
, HN_DECIMAL
| HN_NOSPACE
| HN_B
);
123 fprintf(stdout
, "\tUsed space %6s\n", buf
);
125 bytes
= (info
.rsvbigblocks
<< HAMMER_LARGEBLOCK_BITS
);
126 humanize_number(buf
, sizeof(buf
) - (bytes
< 0 ? 0 : 1), bytes
, "", HN_AUTOSCALE
, HN_DECIMAL
| HN_NOSPACE
| HN_B
);
127 fprintf(stdout
, "\tReserved space %6s\n", buf
);
129 bytes
= ((info
.freebigblocks
- info
.rsvbigblocks
) << HAMMER_LARGEBLOCK_BITS
);
130 humanize_number(buf
, sizeof(buf
) - (bytes
< 0 ? 0 : 1), bytes
, "", HN_AUTOSCALE
, HN_DECIMAL
| HN_NOSPACE
| HN_B
);
131 fprintf(stdout
, "\tFree space %6s\n\n", buf
);
134 double percent(int64_t value
, int64_t total
) {
136 /* Avoid divide-by-zero */
140 return ((value
* 100.0) / (double)total
);