summaryrefslogtreecommitdiff
path: root/c_src/libbcachefs.h
diff options
context:
space:
mode:
Diffstat (limited to 'c_src/libbcachefs.h')
-rw-r--r--c_src/libbcachefs.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/c_src/libbcachefs.h b/c_src/libbcachefs.h
index 05720573..5c7ef6c7 100644
--- a/c_src/libbcachefs.h
+++ b/c_src/libbcachefs.h
@@ -168,6 +168,35 @@ static inline struct bch_ioctl_fs_usage *bchu_fs_usage(struct bchfs_handle fs)
}
}
+static inline struct bch_ioctl_query_accounting *bchu_fs_accounting(struct bchfs_handle fs,
+ unsigned typemask)
+{
+ unsigned accounting_u64s = 128;
+ struct bch_ioctl_query_accounting *ret = NULL;
+
+ while (1) {
+ ret = xrealloc(ret, sizeof(*ret) + accounting_u64s * sizeof(u64));
+
+ memset(ret, 0, sizeof(*ret));
+
+ ret->accounting_u64s = accounting_u64s;
+ ret->accounting_types_mask = typemask;
+
+ if (!ioctl(fs.ioctl_fd, BCH_IOCTL_QUERY_ACCOUNTING, ret))
+ return ret;
+
+ if (errno == ENOTTY)
+ return NULL;
+
+ if (errno == ERANGE) {
+ accounting_u64s *= 2;
+ continue;
+ }
+
+ die("BCH_IOCTL_USAGE error: %m");
+ }
+}
+
static inline struct bch_ioctl_dev_usage_v2 *bchu_dev_usage(struct bchfs_handle fs,
unsigned idx)
{