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
37 #include <libhammer.h>
41 void show_info(char *path
);
42 static double percent(int64_t value
, int64_t total
);
45 hammer_cmd_info(char **av
, int ac
)
47 struct statfs
*stfsbuf
;
48 int mntsize
, i
, first
= 1;
62 mntsize
= getmntinfo(&stfsbuf
, MNT_NOWAIT
);
64 for (i
= 0; i
< mntsize
; i
++) {
65 fstype
= stfsbuf
[i
].f_fstypename
;
66 path
= stfsbuf
[i
].f_mntonname
;
67 if ((strcmp(fstype
, "hammer")) == 0) {
76 printf("No mounted HAMMER filesystems found\n");
78 printf("No mounted filesystems found\n");
86 libhammer_fsinfo_t fip
;
87 libhammer_pfsinfo_t pi
, pi_first
;
88 struct hammer_ioc_volume_list ioc
;
89 int64_t usedbigblocks
;
90 int64_t usedbytes
, rsvbytes
;
91 int64_t totalbytes
, freebytes
;
94 char rootvol
[MAXPATHLEN
];
100 usedbytes
= totalbytes
= rsvbytes
= freebytes
= 0;
102 fip
= libhammer_get_fsinfo(path
);
104 errx(1, "libhammer_get_fsinfo");
106 /* Find out the UUID strings */
107 uuid_to_string(&fip
->vol_fsid
, &fsid
, NULL
);
109 /* Get the volume paths */
110 if (hammer_fs_to_vol(path
, &ioc
) == -1)
111 errx(1, "Failed to get volume paths");
113 /* Get the root volume path */
114 if (hammer_fs_to_rootvol(path
, rootvol
, sizeof(rootvol
)) == -1)
115 errx(1, "Failed to get root volume path");
117 /* Volume information */
118 printf("Volume identification\n");
119 printf("\tLabel %s\n", fip
->vol_name
);
120 printf("\tNo. Volumes %d\n", fip
->nvolumes
);
121 printf("\tHAMMER Volumes ");
122 for (i
= 0; i
< ioc
.nvols
; i
++) {
123 printf("%s", ioc
.vols
[i
].device_name
);
124 if (i
!= ioc
.nvols
- 1)
128 printf("\tRoot Volume %s\n", rootvol
);
129 printf("\tFSID %s\n", fsid
);
130 printf("\tHAMMER Version %d\n", fip
->version
);
132 /* Big-blocks information */
133 usedbigblocks
= fip
->bigblocks
- fip
->freebigblocks
;
135 printf("Big-block information\n");
136 printf("\tTotal %10jd\n", (intmax_t)fip
->bigblocks
);
137 printf("\tUsed %10jd (%.2lf%%)\n"
138 "\tReserved %10jd (%.2lf%%)\n"
139 "\tFree %10jd (%.2lf%%)\n",
140 (intmax_t)usedbigblocks
,
141 percent(usedbigblocks
, fip
->bigblocks
),
142 (intmax_t)fip
->rsvbigblocks
,
143 percent(fip
->rsvbigblocks
, fip
->bigblocks
),
144 (intmax_t)(fip
->freebigblocks
- fip
->rsvbigblocks
),
145 percent(fip
->freebigblocks
- fip
->rsvbigblocks
, fip
->bigblocks
));
146 printf("Space information\n");
148 /* Space information */
149 totalbytes
= (fip
->bigblocks
<< HAMMER_BIGBLOCK_BITS
);
150 usedbytes
= (usedbigblocks
<< HAMMER_BIGBLOCK_BITS
);
151 rsvbytes
= (fip
->rsvbigblocks
<< HAMMER_BIGBLOCK_BITS
);
152 freebytes
= ((fip
->freebigblocks
- fip
->rsvbigblocks
)
153 << HAMMER_BIGBLOCK_BITS
);
155 printf("\tNo. Inodes %10jd\n", (intmax_t)fip
->inodes
);
156 humanize_number(buf
, sizeof(buf
) - (totalbytes
< 0 ? 0 : 1),
157 totalbytes
, "", HN_AUTOSCALE
, HN_DECIMAL
| HN_NOSPACE
| HN_B
);
158 printf("\tTotal size %6s (%jd bytes)\n",
159 buf
, (intmax_t)totalbytes
);
161 humanize_number(buf
, sizeof(buf
) - (usedbytes
< 0 ? 0 : 1),
162 usedbytes
, "", HN_AUTOSCALE
, HN_DECIMAL
| HN_NOSPACE
| HN_B
);
163 printf("\tUsed %6s (%.2lf%%)\n", buf
,
164 percent(usedbytes
, totalbytes
));
166 humanize_number(buf
, sizeof(buf
) - (rsvbytes
< 0 ? 0 : 1),
167 rsvbytes
, "", HN_AUTOSCALE
, HN_DECIMAL
| HN_NOSPACE
| HN_B
);
168 printf("\tReserved %6s (%.2lf%%)\n", buf
,
169 percent(rsvbytes
, totalbytes
));
171 humanize_number(buf
, sizeof(buf
) - (freebytes
< 0 ? 0 : 1),
172 freebytes
, "", HN_AUTOSCALE
, HN_DECIMAL
| HN_NOSPACE
| HN_B
);
173 printf("\tFree %6s (%.2lf%%)\n", buf
,
174 percent(freebytes
, totalbytes
));
176 /* Pseudo-filesystem information */
177 printf("PFS information\n");
178 printf("\t PFS# Mode Snaps\n");
180 /* Iterate all the PFSs found */
181 pi_first
= libhammer_get_first_pfs(fip
);
182 for (pi
= pi_first
; pi
!= NULL
; pi
= libhammer_get_next_pfs(pi
)) {
184 pi
->pfs_id
, (pi
->ismaster
? "MASTER" : "SLAVE"));
186 snprintf(buf
, 6, "%d", pi
->snapcount
);
187 printf(" %6s", (pi
->head
.error
&& pi
->snapcount
== 0) ? "-" : buf
);
188 if (pi
->pfs_id
== HAMMER_ROOT_PFSID
)
189 printf(" (root PFS)");
195 libhammer_free_fsinfo(fip
);
200 percent(int64_t value
, int64_t total
)
202 /* Avoid divide-by-zero */
206 return ((value
* 100.0) / (double)total
);