7 #include "libbcachefs/bcachefs_ioctl.h"
8 #include "libbcachefs/opts.h"
11 #include "libbcachefs.h"
13 static inline int printf_pad(unsigned pad, const char * fmt, ...)
19 ret = vprintf(fmt, args);
28 static void print_fs_usage(const char *path, enum units units)
33 struct bchfs_handle fs = bcache_fs_open(path);
34 struct bch_ioctl_usage *u = bchu_usage(fs);
36 uuid_unparse(fs.uuid.b, uuid);
37 printf("Filesystem %s:\n", uuid);
39 printf("%-20s%12s\n", "Size:", pr_units(u->fs.capacity, units));
40 printf("%-20s%12s\n", "Used:", pr_units(u->fs.used, units));
42 printf("%-20s%12s%12s%12s%12s\n",
43 "By replicas:", "1x", "2x", "3x", "4x");
45 for (j = BCH_DATA_BTREE; j < BCH_DATA_NR; j++) {
46 printf_pad(20, " %s:", bch2_data_types[j]);
48 for (i = 0; i < BCH_REPLICAS_MAX; i++)
49 printf("%12s", pr_units(u->fs.sectors[j][i], units));
53 printf_pad(20, " %s:", "reserved");
54 for (i = 0; i < BCH_REPLICAS_MAX; i++)
55 printf("%12s", pr_units(u->fs.persistent_reserved[i], units));
58 printf("%-20s%12s\n", " online reserved:", pr_units(u->fs.online_reserved, units));
60 for (i = 0; i < u->nr_devices; i++) {
61 struct bch_ioctl_dev_usage *d = u->devs + i;
68 printf_pad(20, "Device %u usage:", i);
69 name = !d->dev ? strdup("(offline)")
71 ?: strdup("(device not found)");
73 printf("%24s%12s\n", name, bch2_dev_state[d->state]);
76 printf("%-20s%12s%12s%12s\n",
77 "", "data", "buckets", "fragmented");
79 for (j = BCH_DATA_SB; j < BCH_DATA_NR; j++) {
80 u64 frag = max((s64) d->buckets[j] * d->bucket_size -
81 (s64) d->sectors[j], 0LL);
83 printf_pad(20, " %s:", bch2_data_types[j]);
84 printf("%12s%12llu%12s\n",
85 pr_units(d->sectors[j], units),
87 pr_units(frag, units));
95 int cmd_fs_usage(int argc, char *argv[])
97 enum units units = BYTES;
101 while ((opt = getopt(argc, argv, "h")) != -1)
104 units = HUMAN_READABLE;
108 if (argc - optind < 1) {
109 print_fs_usage(".", units);
111 for (i = optind; i < argc; i++)
112 print_fs_usage(argv[i], units);