8
#include <linux/types.h>
11
#include <sys/ioctl.h>
16
#include <linux/gfs2_ondisk.h>
18
#include "gfs2_tool.h"
22
* anthropomorphize - make a uint64_t number more human
24
static const char *anthropomorphize(unsigned long long inhuman_value)
26
const char *symbols = " KMGTPE";
28
unsigned long long val = inhuman_value;
29
static char out_val[32];
31
memset(out_val, 0, sizeof(out_val));
32
for (i = 0; i < 6 && val > 1024; i++)
34
sprintf(out_val, "%llu%c", val, symbols[i]);
39
* printit - parse out and print values according to the output type
41
static void printit(unsigned long long block_size, const char *label,
42
unsigned long long total, unsigned long long used,
43
unsigned long long free, unsigned int percentage)
45
switch (output_type) {
47
printf(" %-15s%-15llu%-15llu%-15llu%u%%\n",
48
label, total, used, free, percentage);
51
printf(" %-15s%-15llu%-15llu%-15llu%u%%\n",
52
label, (total * block_size) / 1024,
53
(used * block_size) / 1024, (free * block_size) / 1024,
57
/* Need to do three separate printfs here because function
58
anthropomorphize re-uses the same static space. */
59
printf(" %-15s%-15s", label,
60
anthropomorphize(total * block_size));
61
printf("%-15s", anthropomorphize(used * block_size));
62
printf("%-15s%u%%\n", anthropomorphize(free * block_size),
69
* do_df_one - print out information about one filesystem
70
* @path: the path to the filesystem
77
unsigned int percentage;
78
unsigned int journals;
84
char buf[GFS2_DEFAULT_BSIZE], statfs_fn[PATH_MAX];
85
struct gfs2_statfs_change sc;
87
memset(&sbd, 0, sizeof(struct gfs2_sbd));
90
fs = mp2fsname(sbd.path_name);
92
sbd.device_fd = open(sbd.device_name, O_RDONLY);
93
if (sbd.device_fd < 0)
94
die("can't open %s: %s\n", path, strerror(errno));
96
sbd.bsize = GFS2_DEFAULT_BSIZE;
97
sbd.jsize = GFS2_DEFAULT_JSIZE;
98
sbd.rgsize = GFS2_DEFAULT_RGSIZE;
99
sbd.utsize = GFS2_DEFAULT_UTSIZE;
100
sbd.qcsize = GFS2_DEFAULT_QCSIZE;
101
osi_list_init(&sbd.rglist);
102
init_buf_list(&sbd, &sbd.buf_list, 128 << 20);
103
init_buf_list(&sbd, &sbd.nvbuf_list, 0xffffffff);
105
do_lseek(sbd.device_fd, 0x10 * sbd.bsize);
106
do_read(sbd.device_fd, buf, sbd.bsize); /* read in the superblock */
108
compute_constants(&sbd);
109
gfs2_sb_in(&sbd.sd_sb, buf); /* parse it out into the sb structure */
111
sbd.master_dir = gfs2_load_inode(&sbd,
112
sbd.sd_sb.sb_master_dir.no_addr);
114
gfs2_lookupi(sbd.master_dir, "rindex", 6, &sbd.md.riinode);
115
gfs2_lookupi(sbd.master_dir, "jindex", 6, &sbd.md.jiinode);
116
close(sbd.device_fd);
118
journals = sbd.md.jiinode->i_di.di_entries - 2;
120
rgrps = sbd.md.riinode->i_di.di_size;
121
if (rgrps % sizeof(struct gfs2_rindex))
122
die("bad rindex size\n");
123
rgrps /= sizeof(struct gfs2_rindex);
125
printf("%s:\n", path);
126
printf(" SB lock proto = \"%s\"\n", sbd.sd_sb.sb_lockproto);
127
printf(" SB lock table = \"%s\"\n", sbd.sd_sb.sb_locktable);
128
printf(" SB ondisk format = %u\n", sbd.sd_sb.sb_fs_format);
129
printf(" SB multihost format = %u\n", sbd.sd_sb.sb_multihost_format);
130
printf(" Block size = %u\n", sbd.sd_sb.sb_bsize);
131
printf(" Journals = %u\n", journals);
132
printf(" Resource Groups = %"PRIu64"\n", rgrps);
133
printf(" Mounted lock proto = \"%s\"\n",
134
((value = get_sysfs(fs, "args/lockproto"))[0])
135
? value : sbd.sd_sb.sb_lockproto);
136
printf(" Mounted lock table = \"%s\"\n",
137
((value = get_sysfs(fs, "args/locktable"))[0])
138
? value : sbd.sd_sb.sb_locktable);
139
printf(" Mounted host data = \"%s\"\n",
140
get_sysfs(fs, "args/hostdata"));
141
printf(" Journal number = %s\n", get_sysfs(fs, "lockstruct/jid"));
142
flags = get_sysfs_uint(fs, "lockstruct/flags");
143
printf(" Lock module flags = %x", flags);
145
printf(" Local flocks = %s\n",
146
(get_sysfs_uint(fs, "args/localflocks")) ? "TRUE" : "FALSE");
147
printf(" Local caching = %s\n",
148
(get_sysfs_uint(fs, "args/localcaching")) ? "TRUE" : "FALSE");
150
/* Read the master statfs file */
151
mount_gfs2_meta(&sbd);
153
sprintf(statfs_fn, "%s/statfs", sbd.metafs_path);
154
statfs_fd = open(statfs_fn, O_RDONLY);
155
do_read(statfs_fd, buf, sizeof(struct gfs2_statfs_change));
156
gfs2_statfs_change_in(&sc, (char *)&buf);
160
cleanup_metafs(&sbd);
163
switch (output_type) {
165
printf(" %-15s%-15s%-15s%-15s%-15s\n", "Type", "Total Blocks",
166
"Used Blocks", "Free Blocks", "use%");
169
printf(" %-15s%-15s%-15s%-15s%-15s\n", "Type", "Total K",
170
"Used K", "Free K", "use%");
173
printf(" %-15s%-15s%-15s%-15s%-15s\n", "Type", "Total",
174
"Used", "Free", "use%");
177
printf(" ------------------------------------------------------------------------\n");
179
percentage = sc.sc_total ?
180
(100.0 * (sc.sc_total - sc.sc_free)) / sc.sc_total + 0.5 : 0;
181
printit(sbd.sd_sb.sb_bsize, "data", sc.sc_total,
182
sc.sc_total - sc.sc_free, sc.sc_free, percentage);
184
percentage = (sc.sc_dinodes + sc.sc_free) ?
185
(100.0 * sc.sc_dinodes / (sc.sc_dinodes + sc.sc_free)) + 0.5 :
187
printit(sbd.sd_sb.sb_bsize, "inodes", sc.sc_dinodes + sc.sc_free,
188
sc.sc_dinodes, sc.sc_free, percentage);
193
* print_df - print out information about filesystems
200
print_df(int argc, char **argv)
205
if (!realpath(argv[optind], buf))
206
die("can't determine real path: %s\n", strerror(errno));
215
char buf[256], device[256], path[256], type[256];
218
file = fopen("/proc/mounts", "r");
220
die("can't open /proc/mounts: %s\n", strerror(errno));
222
while (fgets(buf, 256, file)) {
223
if (sscanf(buf, "%s %s %s", device, path, type) != 3)
225
if (strcmp(type, "gfs2") != 0)