diff options
author | Omar Sandoval <osandov@fb.com> | 2018-01-18 13:09:32 -0800 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2018-02-24 01:37:17 +0100 |
commit | bad4208da33f3ef2adf9af2b06a597f2ce23d228 (patch) | |
tree | 691e65ddd839a3cb80fb79f288a4eb55b896f007 /libbtrfsutil/btrfsutil.h | |
parent | 23c01b3c1b0803950657f3f29914cd59f3554a84 (diff) |
libbtrfsutil: add qgroup inheritance helpers
We want to hide struct btrfs_qgroup_inherit from the user because that
comes from the Btrfs UAPI headers. Instead, wrap it in a struct
btrfs_util_qgroup_inherit and provide helpers to manipulate it. This
will be used for subvolume and snapshot creation.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'libbtrfsutil/btrfsutil.h')
-rw-r--r-- | libbtrfsutil/btrfsutil.h | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/libbtrfsutil/btrfsutil.h b/libbtrfsutil/btrfsutil.h index 867418f2..76bf0b60 100644 --- a/libbtrfsutil/btrfsutil.h +++ b/libbtrfsutil/btrfsutil.h @@ -20,6 +20,9 @@ #ifndef BTRFS_UTIL_H #define BTRFS_UTIL_H +#include <stddef.h> +#include <stdint.h> + #define BTRFS_UTIL_VERSION_MAJOR 1 #define BTRFS_UTIL_VERSION_MINOR 0 #define BTRFS_UTIL_VERSION_PATCH 0 @@ -69,6 +72,81 @@ enum btrfs_util_error { */ const char *btrfs_util_strerror(enum btrfs_util_error err); +/** + * btrfs_util_is_subvolume() - Return whether a given path is a Btrfs subvolume. + * @path: Path to check. + * + * Return: %BTRFS_UTIL_OK if @path is a Btrfs subvolume, + * %BTRFS_UTIL_ERROR_NOT_BTRFS if @path is not on a Btrfs filesystem, + * %BTRFS_UTIL_ERROR_NOT_SUBVOLUME if @path is not a subvolume, non-zero error + * code on any other failure. + */ +enum btrfs_util_error btrfs_util_is_subvolume(const char *path); + +/** + * btrfs_util_is_subvolume_fd() - See btrfs_util_is_subvolume(). + */ +enum btrfs_util_error btrfs_util_is_subvolume_fd(int fd); + +/** + * btrfs_util_subvolume_id() - Get the ID of the subvolume containing a path. + * @path: Path on a Btrfs filesystem. + * @id_ret: Returned subvolume ID. + * + * Return: %BTRFS_UTIL_OK on success, non-zero error code on failure. + */ +enum btrfs_util_error btrfs_util_subvolume_id(const char *path, + uint64_t *id_ret); + +/** + * btrfs_util_subvolume_id_fd() - See btrfs_util_subvolume_id(). + */ +enum btrfs_util_error btrfs_util_subvolume_id_fd(int fd, uint64_t *id_ret); + +struct btrfs_util_qgroup_inherit; + +/** + * btrfs_util_create_qgroup_inherit() - Create a qgroup inheritance specifier + * for btrfs_util_create_subvolume() or btrfs_util_create_snapshot(). + * @flags: Must be zero. + * @ret: Returned qgroup inheritance specifier. + * + * The returned structure must be freed with + * btrfs_util_destroy_qgroup_inherit(). + * + * Return: %BTRFS_UTIL_OK on success, non-zero error code on failure. + */ +enum btrfs_util_error btrfs_util_create_qgroup_inherit(int flags, + struct btrfs_util_qgroup_inherit **ret); + +/** + * btrfs_util_destroy_qgroup_inherit() - Destroy a qgroup inheritance specifier + * previously created with btrfs_util_create_qgroup_inherit(). + * @inherit: Specifier to destroy. + */ +void btrfs_util_destroy_qgroup_inherit(struct btrfs_util_qgroup_inherit *inherit); + +/** + * btrfs_util_qgroup_inherit_add_group() - Add inheritance from a qgroup to a + * qgroup inheritance specifier. + * @inherit: Specifier to modify. May be reallocated. + * @qgroupid: ID of qgroup to inherit from. + * + * Return: %BTRFS_UTIL_OK on success, non-zero error code on failure. + */ +enum btrfs_util_error btrfs_util_qgroup_inherit_add_group(struct btrfs_util_qgroup_inherit **inherit, + uint64_t qgroupid); + +/** + * btrfs_util_qgroup_inherit_get_groups() - Get the qgroups a qgroup inheritance + * specifier contains. + * @inherit: Qgroup inheritance specifier. + * @groups: Returned array of qgroup IDs. + * @n: Returned number of entries in the @groups array. + */ +void btrfs_util_qgroup_inherit_get_groups(const struct btrfs_util_qgroup_inherit *inherit, + const uint64_t **groups, size_t *n); + #ifdef __cplusplus } #endif |