7 #include "libbcachefs/bcachefs_ioctl.h"
8 #include "libbcachefs/opts.h"
11 #include "libbcachefs.h"
13 static void print_fs_usage(const char *path, enum units units)
18 struct bchfs_handle fs = bcache_fs_open(path);
19 struct bch_ioctl_usage *u = bchu_usage(fs);
21 uuid_unparse(fs.uuid.b, uuid);
22 printf("Filesystem %s:\n", uuid);
24 printf("%-20s%12s\n", "Size:", pr_units(u->fs.capacity, units));
25 printf("%-20s%12s\n", "Used:", pr_units(u->fs.used, units));
27 printf("%-20s%12s%12s%12s%12s\n",
28 "By replicas:", "1x", "2x", "3x", "4x");
30 for (j = BCH_DATA_BTREE; j < BCH_DATA_NR; j++) {
31 printf_pad(20, " %s:", bch2_data_types[j]);
33 for (i = 0; i < BCH_REPLICAS_MAX; i++)
34 printf("%12s", pr_units(u->fs.sectors[j][i], units));
38 printf_pad(20, " %s:", "reserved");
39 for (i = 0; i < BCH_REPLICAS_MAX; i++)
40 printf("%12s", pr_units(u->fs.persistent_reserved[i], units));
43 printf("%-20s%12s\n", " online reserved:", pr_units(u->fs.online_reserved, units));
45 for (i = 0; i < u->nr_devices; i++) {
46 struct bch_ioctl_dev_usage *d = u->devs + i;
53 printf_pad(20, "Device %u usage:", i);
54 name = !d->dev ? strdup("(offline)")
56 ?: strdup("(device not found)");
58 printf("%24s%12s\n", name, bch2_dev_state[d->state]);
61 printf("%-20s%12s%12s%12s\n",
62 "", "data", "buckets", "fragmented");
64 for (j = BCH_DATA_SB; j < BCH_DATA_NR; j++) {
65 u64 frag = max((s64) d->buckets[j] * d->bucket_size -
66 (s64) d->sectors[j], 0LL);
68 printf_pad(20, " %s:", bch2_data_types[j]);
69 printf("%12s%12llu%12s\n",
70 pr_units(d->sectors[j], units),
72 pr_units(frag, units));
80 int cmd_fs_usage(int argc, char *argv[])
82 enum units units = BYTES;
86 while ((opt = getopt(argc, argv, "h")) != -1)
89 units = HUMAN_READABLE;
95 print_fs_usage(".", units);
97 while ((fs = arg_pop()))
98 print_fs_usage(fs, units);