2 * Copyright (C) 2018 Facebook
4 * This file is part of libbtrfsutil.
6 * libbtrfsutil is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * libbtrfsutil is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with libbtrfsutil. If not, see <http://www.gnu.org/licenses/>.
26 #define BTRFS_UTIL_VERSION_MAJOR 1
27 #define BTRFS_UTIL_VERSION_MINOR 0
28 #define BTRFS_UTIL_VERSION_PATCH 0
35 * enum btrfs_util_error - libbtrfsutil error codes.
37 * All functions in libbtrfsutil that can return an error return this type and
40 enum btrfs_util_error {
42 BTRFS_UTIL_ERROR_STOP_ITERATION,
43 BTRFS_UTIL_ERROR_NO_MEMORY,
44 BTRFS_UTIL_ERROR_INVALID_ARGUMENT,
45 BTRFS_UTIL_ERROR_NOT_BTRFS,
46 BTRFS_UTIL_ERROR_NOT_SUBVOLUME,
47 BTRFS_UTIL_ERROR_SUBVOLUME_NOT_FOUND,
48 BTRFS_UTIL_ERROR_OPEN_FAILED,
49 BTRFS_UTIL_ERROR_RMDIR_FAILED,
50 BTRFS_UTIL_ERROR_UNLINK_FAILED,
51 BTRFS_UTIL_ERROR_STAT_FAILED,
52 BTRFS_UTIL_ERROR_STATFS_FAILED,
53 BTRFS_UTIL_ERROR_SEARCH_FAILED,
54 BTRFS_UTIL_ERROR_INO_LOOKUP_FAILED,
55 BTRFS_UTIL_ERROR_SUBVOL_GETFLAGS_FAILED,
56 BTRFS_UTIL_ERROR_SUBVOL_SETFLAGS_FAILED,
57 BTRFS_UTIL_ERROR_SUBVOL_CREATE_FAILED,
58 BTRFS_UTIL_ERROR_SNAP_CREATE_FAILED,
59 BTRFS_UTIL_ERROR_SNAP_DESTROY_FAILED,
60 BTRFS_UTIL_ERROR_DEFAULT_SUBVOL_FAILED,
61 BTRFS_UTIL_ERROR_SYNC_FAILED,
62 BTRFS_UTIL_ERROR_START_SYNC_FAILED,
63 BTRFS_UTIL_ERROR_WAIT_SYNC_FAILED,
67 * btrfs_util_strerror() - Convert a libtrfsutil error code to a string
69 * @err: The error to convert.
71 * Return: Error description.
73 const char *btrfs_util_strerror(enum btrfs_util_error err);
76 * btrfs_util_sync() - Force a sync on a specific Btrfs filesystem.
77 * @path: Path on a Btrfs filesystem.
79 * Return: %BTRFS_UTIL_OK on success, non-zero error code on failure.
81 enum btrfs_util_error btrfs_util_sync(const char *path);
84 * btrfs_util_sync_fd() - See btrfs_util_sync().
86 enum btrfs_util_error btrfs_util_sync_fd(int fd);
89 * btrfs_util_start_sync() - Start a sync on a specific Btrfs filesystem but
91 * @path: Path on a Btrfs filesystem.
92 * @transid: Returned transaction ID which can be waited on with
93 * btrfs_util_wait_sync(). This can be %NULL.
95 * Return: %BTRFS_UTIL_OK on success, non-zero error code on failure.
97 enum btrfs_util_error btrfs_util_start_sync(const char *path,
101 * btrfs_util_start_sync_fd() - See btrfs_util_start_sync().
103 enum btrfs_util_error btrfs_util_start_sync_fd(int fd, uint64_t *transid);
106 * btrfs_util_wait_sync() - Wait for a transaction with a given ID to sync.
107 * @path: Path on a Btrfs filesystem.
108 * @transid: Transaction ID to wait for, or zero for the current transaction.
110 * Return: %BTRFS_UTIL_OK on success, non-zero error code on failure.
112 enum btrfs_util_error btrfs_util_wait_sync(const char *path, uint64_t transid);
115 * btrfs_util_wait_sync_fd() - See btrfs_util_wait_sync().
117 enum btrfs_util_error btrfs_util_wait_sync_fd(int fd, uint64_t transid);
120 * btrfs_util_is_subvolume() - Return whether a given path is a Btrfs subvolume.
121 * @path: Path to check.
123 * Return: %BTRFS_UTIL_OK if @path is a Btrfs subvolume,
124 * %BTRFS_UTIL_ERROR_NOT_BTRFS if @path is not on a Btrfs filesystem,
125 * %BTRFS_UTIL_ERROR_NOT_SUBVOLUME if @path is not a subvolume, non-zero error
126 * code on any other failure.
128 enum btrfs_util_error btrfs_util_is_subvolume(const char *path);
131 * btrfs_util_is_subvolume_fd() - See btrfs_util_is_subvolume().
133 enum btrfs_util_error btrfs_util_is_subvolume_fd(int fd);
136 * btrfs_util_subvolume_id() - Get the ID of the subvolume containing a path.
137 * @path: Path on a Btrfs filesystem.
138 * @id_ret: Returned subvolume ID.
140 * Return: %BTRFS_UTIL_OK on success, non-zero error code on failure.
142 enum btrfs_util_error btrfs_util_subvolume_id(const char *path,
146 * btrfs_util_subvolume_id_fd() - See btrfs_util_subvolume_id().
148 enum btrfs_util_error btrfs_util_subvolume_id_fd(int fd, uint64_t *id_ret);
150 struct btrfs_util_qgroup_inherit;
153 * btrfs_util_create_qgroup_inherit() - Create a qgroup inheritance specifier
154 * for btrfs_util_create_subvolume() or btrfs_util_create_snapshot().
155 * @flags: Must be zero.
156 * @ret: Returned qgroup inheritance specifier.
158 * The returned structure must be freed with
159 * btrfs_util_destroy_qgroup_inherit().
161 * Return: %BTRFS_UTIL_OK on success, non-zero error code on failure.
163 enum btrfs_util_error btrfs_util_create_qgroup_inherit(int flags,
164 struct btrfs_util_qgroup_inherit **ret);
167 * btrfs_util_destroy_qgroup_inherit() - Destroy a qgroup inheritance specifier
168 * previously created with btrfs_util_create_qgroup_inherit().
169 * @inherit: Specifier to destroy.
171 void btrfs_util_destroy_qgroup_inherit(struct btrfs_util_qgroup_inherit *inherit);
174 * btrfs_util_qgroup_inherit_add_group() - Add inheritance from a qgroup to a
175 * qgroup inheritance specifier.
176 * @inherit: Specifier to modify. May be reallocated.
177 * @qgroupid: ID of qgroup to inherit from.
179 * Return: %BTRFS_UTIL_OK on success, non-zero error code on failure.
181 enum btrfs_util_error btrfs_util_qgroup_inherit_add_group(struct btrfs_util_qgroup_inherit **inherit,
185 * btrfs_util_qgroup_inherit_get_groups() - Get the qgroups a qgroup inheritance
186 * specifier contains.
187 * @inherit: Qgroup inheritance specifier.
188 * @groups: Returned array of qgroup IDs.
189 * @n: Returned number of entries in the @groups array.
191 void btrfs_util_qgroup_inherit_get_groups(const struct btrfs_util_qgroup_inherit *inherit,
192 const uint64_t **groups, size_t *n);
198 #endif /* BTRFS_UTIL_H */