Line data Source code
1 4 : GQuark bd_btrfs_error_quark (void) {
2 4 : return g_quark_from_static_string ("g-bd-btrfs-error-quark");
3 : }
4 :
5 : /**
6 : * BDBtrfsDeviceInfo:
7 : * @id: ID of the device
8 : * @path: path of the device
9 : * @size: size of the device
10 : * @used: size of the used space
11 : */
12 : /**
13 : * bd_btrfs_device_info_copy: (skip)
14 : * @info: (nullable): %BDBtrfsDeviceInfo to copy
15 : *
16 : * Creates a new copy of @info.
17 : */
18 0 : BDBtrfsDeviceInfo* bd_btrfs_device_info_copy (BDBtrfsDeviceInfo *info) {
19 0 : if (info == NULL)
20 0 : return NULL;
21 :
22 0 : BDBtrfsDeviceInfo *new_info = g_new0 (BDBtrfsDeviceInfo, 1);
23 :
24 0 : new_info->id = info->id;
25 0 : new_info->path = g_strdup (info->path);
26 0 : new_info->size = info->size;
27 0 : new_info->used = info->used;
28 :
29 0 : return new_info;
30 : }
31 :
32 : /**
33 : * bd_btrfs_device_info_free: (skip)
34 : * @info: (nullable): %BDBtrfsDeviceInfo to free
35 : *
36 : * Frees @info.
37 : */
38 18 : void bd_btrfs_device_info_free (BDBtrfsDeviceInfo *info) {
39 18 : if (info == NULL)
40 0 : return;
41 :
42 18 : g_free (info->path);
43 18 : g_free (info);
44 : }
45 :
46 11 : GType bd_btrfs_device_info_get_type () {
47 : static GType type = 0;
48 :
49 11 : if (G_UNLIKELY(type == 0)) {
50 1 : type = g_boxed_type_register_static("BDBtrfsDeviceInfo",
51 : (GBoxedCopyFunc) bd_btrfs_device_info_copy,
52 : (GBoxedFreeFunc) bd_btrfs_device_info_free);
53 : }
54 :
55 11 : return type;
56 : }
57 :
58 : /**
59 : * BDBtrfsSubvolumeInfo:
60 : * @id: ID of the subvolume
61 : * @parent_id: ID of the parent (sub)volume
62 : * @path: path of the subvolume
63 : */
64 : /**
65 : * bd_btrfs_subvolume_info_copy: (skip)
66 : * @info: (nullable): %BDBtrfsSubvolumeInfo to copy
67 : *
68 : * Creates a new copy of @info.
69 : */
70 0 : BDBtrfsSubvolumeInfo* bd_btrfs_subvolume_info_copy (BDBtrfsSubvolumeInfo *info) {
71 0 : if (info == NULL)
72 0 : return NULL;
73 :
74 0 : BDBtrfsSubvolumeInfo *new_info = g_new0 (BDBtrfsSubvolumeInfo, 1);
75 :
76 0 : new_info->id = info->id;
77 0 : new_info->parent_id = info->parent_id;
78 0 : new_info->path = g_strdup (info->path);
79 :
80 0 : return new_info;
81 : }
82 :
83 : /**
84 : * bd_btrfs_subvolume_info_free: (skip)
85 : * @info: (nullable): %BDBtrfsSubvolumeInfo to free
86 : *
87 : * Frees @info.
88 : */
89 145 : void bd_btrfs_subvolume_info_free (BDBtrfsSubvolumeInfo *info) {
90 145 : if (info == NULL)
91 0 : return;
92 :
93 145 : g_free (info->path);
94 145 : g_free (info);
95 : }
96 :
97 7814 : GType bd_btrfs_subvolume_info_get_type () {
98 : static GType type = 0;
99 :
100 7814 : if (G_UNLIKELY(type == 0)) {
101 1 : type = g_boxed_type_register_static("BDBtrfsSubvolumeInfo",
102 : (GBoxedCopyFunc) bd_btrfs_subvolume_info_copy,
103 : (GBoxedFreeFunc) bd_btrfs_subvolume_info_free);
104 : }
105 :
106 7814 : return type;
107 : }
108 :
109 : /**
110 : * BDBtrfsFilesystemInfo:
111 : * @label: label of the filesystem
112 : * @uuid: uuid of the filesystem
113 : * @num_devices: number of device in the filesystem
114 : * @used: size of the used space
115 : */
116 : /**
117 : * bd_btrfs_filesystem_info_copy: (skip)
118 : * @info: (nullable): %BDBtrfsFilesystemInfo to copy
119 : *
120 : * Creates a new copy of @info.
121 : */
122 0 : BDBtrfsFilesystemInfo* bd_btrfs_filesystem_info_copy (BDBtrfsFilesystemInfo *info) {
123 0 : if (info == NULL)
124 0 : return NULL;
125 :
126 0 : BDBtrfsFilesystemInfo *new_info = g_new0 (BDBtrfsFilesystemInfo, 1);
127 :
128 0 : new_info->label = g_strdup (info->label);
129 0 : new_info->uuid = g_strdup (info->uuid);
130 0 : new_info->num_devices = info->num_devices;
131 0 : new_info->used = info->used;
132 :
133 0 : return new_info;
134 : }
135 :
136 : /**
137 : * bd_btrfs_filesystem_info_free: (skip)
138 : * @info: (nullable): %BDBtrfsFilesystemInfo to free
139 : *
140 : * Frees @info.
141 : */
142 3 : void bd_btrfs_filesystem_info_free (BDBtrfsFilesystemInfo *info) {
143 3 : if (info == NULL)
144 0 : return;
145 :
146 3 : g_free (info->label);
147 3 : g_free (info->uuid);
148 3 : g_free (info);
149 : }
150 :
151 12 : GType bd_btrfs_filesystem_info_get_type () {
152 : static GType type = 0;
153 :
154 12 : if (G_UNLIKELY(type == 0)) {
155 1 : type = g_boxed_type_register_static("BDBtrfsFilesystemInfo",
156 : (GBoxedCopyFunc) bd_btrfs_filesystem_info_copy,
157 : (GBoxedFreeFunc) bd_btrfs_filesystem_info_free);
158 : }
159 :
160 12 : return type;
161 : }
162 :
163 0 : static gboolean bd_btrfs_is_tech_avail_stub (BDBtrfsTech tech G_GNUC_UNUSED, guint64 mode G_GNUC_UNUSED, GError **error) {
164 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_btrfs_is_tech_avail' called, but not implemented!");
165 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
166 : "The function 'bd_btrfs_is_tech_avail' called, but not implemented!");
167 0 : return FALSE;
168 : }
169 :
170 : static gboolean (*_bd_btrfs_is_tech_avail) (BDBtrfsTech tech, guint64 mode, GError **error) = bd_btrfs_is_tech_avail_stub;
171 :
172 : /**
173 : * bd_btrfs_is_tech_avail:
174 : * @tech: the queried tech
175 : * @mode: a bit mask of queried modes of operation (#BDBtrfsTechMode) for @tech
176 : * @error: (out) (optional): place to store error (details about why the @tech-@mode combination is not available)
177 : *
178 : * Returns: whether the @tech-@mode combination is available -- supported by the
179 : * plugin implementation and having all the runtime dependencies available
180 : */
181 4 : gboolean bd_btrfs_is_tech_avail (BDBtrfsTech tech, guint64 mode, GError **error) {
182 4 : return _bd_btrfs_is_tech_avail (tech, mode, error);
183 : }
184 :
185 :
186 0 : static gboolean bd_btrfs_create_volume_stub (const gchar **devices G_GNUC_UNUSED, const gchar *label G_GNUC_UNUSED, const gchar *data_level G_GNUC_UNUSED, const gchar *md_level G_GNUC_UNUSED, const BDExtraArg **extra G_GNUC_UNUSED, GError **error) {
187 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_btrfs_create_volume' called, but not implemented!");
188 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
189 : "The function 'bd_btrfs_create_volume' called, but not implemented!");
190 0 : return FALSE;
191 : }
192 :
193 : static gboolean (*_bd_btrfs_create_volume) (const gchar **devices, const gchar *label, const gchar *data_level, const gchar *md_level, const BDExtraArg **extra, GError **error) = bd_btrfs_create_volume_stub;
194 :
195 : /**
196 : * bd_btrfs_create_volume:
197 : * @devices: (array zero-terminated=1): list of devices to create btrfs volume from
198 : * @label: (nullable): label for the volume
199 : * @data_level: (nullable): RAID level for the data or %NULL to use the default
200 : * @md_level: (nullable): RAID level for the metadata or %NULL to use the default
201 : * @extra: (nullable) (array zero-terminated=1): extra options for the volume creation (right now
202 : * passed to the 'mkfs.btrfs' utility)
203 : * @error: (out) (optional): place to store error (if any)
204 : *
205 : * Returns: whether the new btrfs volume was created from @devices or not
206 : *
207 : * See mkfs.btrfs(8) for details about @data_level, @md_level and btrfs in general.
208 : *
209 : * Tech category: %BD_BTRFS_TECH_MULTI_DEV-%BD_BTRFS_TECH_MODE_CREATE
210 : */
211 34 : gboolean bd_btrfs_create_volume (const gchar **devices, const gchar *label, const gchar *data_level, const gchar *md_level, const BDExtraArg **extra, GError **error) {
212 34 : return _bd_btrfs_create_volume (devices, label, data_level, md_level, extra, error);
213 : }
214 :
215 :
216 0 : static gboolean bd_btrfs_add_device_stub (const gchar *mountpoint G_GNUC_UNUSED, const gchar *device G_GNUC_UNUSED, const BDExtraArg **extra G_GNUC_UNUSED, GError **error) {
217 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_btrfs_add_device' called, but not implemented!");
218 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
219 : "The function 'bd_btrfs_add_device' called, but not implemented!");
220 0 : return FALSE;
221 : }
222 :
223 : static gboolean (*_bd_btrfs_add_device) (const gchar *mountpoint, const gchar *device, const BDExtraArg **extra, GError **error) = bd_btrfs_add_device_stub;
224 :
225 : /**
226 : * bd_btrfs_add_device:
227 : * @mountpoint: mountpoint of the btrfs volume to add new device to
228 : * @device: a device to add to the btrfs volume
229 : * @extra: (nullable) (array zero-terminated=1): extra options for the addition (right now
230 : * passed to the 'btrfs' utility)
231 : * @error: (out) (optional): place to store error (if any)
232 : *
233 : * Returns: whether the @device was successfully added to the @mountpoint btrfs volume or not
234 : *
235 : * Tech category: %BD_BTRFS_TECH_MULTI_DEV-%BD_BTRFS_TECH_MODE_MODIFY
236 : */
237 1 : gboolean bd_btrfs_add_device (const gchar *mountpoint, const gchar *device, const BDExtraArg **extra, GError **error) {
238 1 : return _bd_btrfs_add_device (mountpoint, device, extra, error);
239 : }
240 :
241 :
242 0 : static gboolean bd_btrfs_remove_device_stub (const gchar *mountpoint G_GNUC_UNUSED, const gchar *device G_GNUC_UNUSED, const BDExtraArg **extra G_GNUC_UNUSED, GError **error) {
243 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_btrfs_remove_device' called, but not implemented!");
244 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
245 : "The function 'bd_btrfs_remove_device' called, but not implemented!");
246 0 : return FALSE;
247 : }
248 :
249 : static gboolean (*_bd_btrfs_remove_device) (const gchar *mountpoint, const gchar *device, const BDExtraArg **extra, GError **error) = bd_btrfs_remove_device_stub;
250 :
251 : /**
252 : * bd_btrfs_remove_device:
253 : * @mountpoint: mountpoint of the btrfs volume to remove device from
254 : * @device: a device to remove from the btrfs volume
255 : * @extra: (nullable) (array zero-terminated=1): extra options for the removal (right now
256 : * passed to the 'btrfs' utility)
257 : * @error: (out) (optional): place to store error (if any)
258 : *
259 : * Returns: whether the @device was successfully removed from the @mountpoint btrfs volume or not
260 : *
261 : * Tech category: %BD_BTRFS_TECH_MULTI_DEV-%BD_BTRFS_TECH_MODE_MODIFY
262 : */
263 1 : gboolean bd_btrfs_remove_device (const gchar *mountpoint, const gchar *device, const BDExtraArg **extra, GError **error) {
264 1 : return _bd_btrfs_remove_device (mountpoint, device, extra, error);
265 : }
266 :
267 :
268 0 : static gboolean bd_btrfs_create_subvolume_stub (const gchar *mountpoint G_GNUC_UNUSED, const gchar *name G_GNUC_UNUSED, const BDExtraArg **extra G_GNUC_UNUSED, GError **error) {
269 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_btrfs_create_subvolume' called, but not implemented!");
270 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
271 : "The function 'bd_btrfs_create_subvolume' called, but not implemented!");
272 0 : return FALSE;
273 : }
274 :
275 : static gboolean (*_bd_btrfs_create_subvolume) (const gchar *mountpoint, const gchar *name, const BDExtraArg **extra, GError **error) = bd_btrfs_create_subvolume_stub;
276 :
277 : /**
278 : * bd_btrfs_create_subvolume:
279 : * @mountpoint: mountpoint of the btrfs volume to create subvolume under
280 : * @name: name of the subvolume
281 : * @extra: (nullable) (array zero-terminated=1): extra options for the subvolume creation (right now
282 : * passed to the 'btrfs' utility)
283 : * @error: (out) (optional): place to store error (if any)
284 : *
285 : * Returns: whether the @mountpoint/@name subvolume was successfully created or not
286 : *
287 : * Tech category: %BD_BTRFS_TECH_SUBVOL-%BD_BTRFS_TECH_MODE_CREATE
288 : */
289 11 : gboolean bd_btrfs_create_subvolume (const gchar *mountpoint, const gchar *name, const BDExtraArg **extra, GError **error) {
290 11 : return _bd_btrfs_create_subvolume (mountpoint, name, extra, error);
291 : }
292 :
293 :
294 0 : static gboolean bd_btrfs_delete_subvolume_stub (const gchar *mountpoint G_GNUC_UNUSED, const gchar *name G_GNUC_UNUSED, const BDExtraArg **extra G_GNUC_UNUSED, GError **error) {
295 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_btrfs_delete_subvolume' called, but not implemented!");
296 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
297 : "The function 'bd_btrfs_delete_subvolume' called, but not implemented!");
298 0 : return FALSE;
299 : }
300 :
301 : static gboolean (*_bd_btrfs_delete_subvolume) (const gchar *mountpoint, const gchar *name, const BDExtraArg **extra, GError **error) = bd_btrfs_delete_subvolume_stub;
302 :
303 : /**
304 : * bd_btrfs_delete_subvolume:
305 : * @mountpoint: mountpoint of the btrfs volume to delete subvolume from
306 : * @name: name of the subvolume
307 : * @extra: (nullable) (array zero-terminated=1): extra options for the subvolume deletion (right now
308 : * passed to the 'btrfs' utility)
309 : * @error: (out) (optional): place to store error (if any)
310 : *
311 : * Returns: whether the @mountpoint/@name subvolume was successfully deleted or not
312 : *
313 : * Tech category: %BD_BTRFS_TECH_SUBVOL-%BD_BTRFS_TECH_MODE_DELETE
314 : */
315 2 : gboolean bd_btrfs_delete_subvolume (const gchar *mountpoint, const gchar *name, const BDExtraArg **extra, GError **error) {
316 2 : return _bd_btrfs_delete_subvolume (mountpoint, name, extra, error);
317 : }
318 :
319 :
320 0 : static guint64 bd_btrfs_get_default_subvolume_id_stub (const gchar *mountpoint G_GNUC_UNUSED, GError **error) {
321 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_btrfs_get_default_subvolume_id' called, but not implemented!");
322 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
323 : "The function 'bd_btrfs_get_default_subvolume_id' called, but not implemented!");
324 0 : return 0;
325 : }
326 :
327 : static guint64 (*_bd_btrfs_get_default_subvolume_id) (const gchar *mountpoint, GError **error) = bd_btrfs_get_default_subvolume_id_stub;
328 :
329 : /**
330 : * bd_btrfs_get_default_subvolume_id:
331 : * @mountpoint: mountpoint of the volume to get the default subvolume ID of
332 : * @error: (out) (optional): place to store error (if any)
333 : *
334 : * Returns: ID of the @mountpoint volume's default subvolume. If 0,
335 : * @error may be set to indicate error
336 : *
337 : * Tech category: %BD_BTRFS_TECH_SUBVOL-%BD_BTRFS_TECH_MODE_QUERY
338 : */
339 5 : guint64 bd_btrfs_get_default_subvolume_id (const gchar *mountpoint, GError **error) {
340 5 : return _bd_btrfs_get_default_subvolume_id (mountpoint, error);
341 : }
342 :
343 :
344 0 : static gboolean bd_btrfs_set_default_subvolume_stub (const gchar *mountpoint G_GNUC_UNUSED, guint64 subvol_id G_GNUC_UNUSED, const BDExtraArg **extra G_GNUC_UNUSED, GError **error) {
345 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_btrfs_set_default_subvolume' called, but not implemented!");
346 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
347 : "The function 'bd_btrfs_set_default_subvolume' called, but not implemented!");
348 0 : return FALSE;
349 : }
350 :
351 : static gboolean (*_bd_btrfs_set_default_subvolume) (const gchar *mountpoint, guint64 subvol_id, const BDExtraArg **extra, GError **error) = bd_btrfs_set_default_subvolume_stub;
352 :
353 : /**
354 : * bd_btrfs_set_default_subvolume:
355 : * @mountpoint: mountpoint of the volume to set the default subvolume ID of
356 : * @subvol_id: ID of the subvolume to be set as the default subvolume
357 : * @extra: (nullable) (array zero-terminated=1): extra options for the setting (right now
358 : * passed to the 'btrfs' utility)
359 : * @error: (out) (optional): place to store error (if any)
360 : *
361 : * Returns: whether the @mountpoint volume's default subvolume was correctly set
362 : * to @subvol_id or not
363 : *
364 : * Tech category: %BD_BTRFS_TECH_SUBVOL-%BD_BTRFS_TECH_MODE_MODIFY
365 : */
366 2 : gboolean bd_btrfs_set_default_subvolume (const gchar *mountpoint, guint64 subvol_id, const BDExtraArg **extra, GError **error) {
367 2 : return _bd_btrfs_set_default_subvolume (mountpoint, subvol_id, extra, error);
368 : }
369 :
370 :
371 0 : static gboolean bd_btrfs_create_snapshot_stub (const gchar *source G_GNUC_UNUSED, const gchar *dest G_GNUC_UNUSED, gboolean ro G_GNUC_UNUSED, const BDExtraArg **extra G_GNUC_UNUSED, GError **error) {
372 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_btrfs_create_snapshot' called, but not implemented!");
373 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
374 : "The function 'bd_btrfs_create_snapshot' called, but not implemented!");
375 0 : return FALSE;
376 : }
377 :
378 : static gboolean (*_bd_btrfs_create_snapshot) (const gchar *source, const gchar *dest, gboolean ro, const BDExtraArg **extra, GError **error) = bd_btrfs_create_snapshot_stub;
379 :
380 : /**
381 : * bd_btrfs_create_snapshot:
382 : * @source: path to source subvolume
383 : * @dest: path to new snapshot volume
384 : * @ro: whether the snapshot should be read-only
385 : * @extra: (nullable) (array zero-terminated=1): extra options for the snapshot creation (right now
386 : * passed to the 'btrfs' utility)
387 : * @error: (out) (optional): place to store error (if any)
388 : *
389 : * Returns: whether the @dest snapshot of @source was successfully created or not
390 : *
391 : * Tech category: %BD_BTRFS_TECH_SNAPSHOT-%BD_BTRFS_TECH_MODE_CREATE
392 : */
393 2 : gboolean bd_btrfs_create_snapshot (const gchar *source, const gchar *dest, gboolean ro, const BDExtraArg **extra, GError **error) {
394 2 : return _bd_btrfs_create_snapshot (source, dest, ro, extra, error);
395 : }
396 :
397 :
398 0 : static BDBtrfsDeviceInfo** bd_btrfs_list_devices_stub (const gchar *device G_GNUC_UNUSED, GError **error) {
399 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_btrfs_list_devices' called, but not implemented!");
400 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
401 : "The function 'bd_btrfs_list_devices' called, but not implemented!");
402 0 : return NULL;
403 : }
404 :
405 : static BDBtrfsDeviceInfo** (*_bd_btrfs_list_devices) (const gchar *device, GError **error) = bd_btrfs_list_devices_stub;
406 :
407 : /**
408 : * bd_btrfs_list_devices:
409 : * @device: a device that is part of the queried btrfs volume
410 : * @error: (out) (optional): place to store error (if any)
411 : *
412 : * Returns: (array zero-terminated=1): information about the devices that are part of the btrfs volume
413 : * containing @device or %NULL in case of error
414 : *
415 : * Tech category: %BD_BTRFS_TECH_MULTI_DEV-%BD_BTRFS_TECH_MODE_QUERY
416 : */
417 12 : BDBtrfsDeviceInfo** bd_btrfs_list_devices (const gchar *device, GError **error) {
418 12 : return _bd_btrfs_list_devices (device, error);
419 : }
420 :
421 :
422 0 : static BDBtrfsSubvolumeInfo** bd_btrfs_list_subvolumes_stub (const gchar *mountpoint G_GNUC_UNUSED, gboolean snapshots_only G_GNUC_UNUSED, GError **error) {
423 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_btrfs_list_subvolumes' called, but not implemented!");
424 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
425 : "The function 'bd_btrfs_list_subvolumes' called, but not implemented!");
426 0 : return NULL;
427 : }
428 :
429 : static BDBtrfsSubvolumeInfo** (*_bd_btrfs_list_subvolumes) (const gchar *mountpoint, gboolean snapshots_only, GError **error) = bd_btrfs_list_subvolumes_stub;
430 :
431 : /**
432 : * bd_btrfs_list_subvolumes:
433 : * @mountpoint: a mountpoint of the queried btrfs volume
434 : * @snapshots_only: whether to list only snapshot subvolumes or not
435 : * @error: (out) (optional): place to store error (if any)
436 : *
437 : * Returns: (array zero-terminated=1): information about the subvolumes that are part of the btrfs volume
438 : * mounted at @mountpoint or %NULL in case of error
439 : *
440 : * The subvolumes are sorted in a way that no child subvolume appears in the
441 : * list before its parent (sub)volume.
442 : *
443 : * Tech category: %BD_BTRFS_TECH_SUBVOL-%BD_BTRFS_TECH_MODE_QUERY
444 : */
445 14 : BDBtrfsSubvolumeInfo** bd_btrfs_list_subvolumes (const gchar *mountpoint, gboolean snapshots_only, GError **error) {
446 14 : return _bd_btrfs_list_subvolumes (mountpoint, snapshots_only, error);
447 : }
448 :
449 :
450 0 : static BDBtrfsFilesystemInfo* bd_btrfs_filesystem_info_stub (const gchar *device G_GNUC_UNUSED, GError **error) {
451 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_btrfs_filesystem_info' called, but not implemented!");
452 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
453 : "The function 'bd_btrfs_filesystem_info' called, but not implemented!");
454 0 : return NULL;
455 : }
456 :
457 : static BDBtrfsFilesystemInfo* (*_bd_btrfs_filesystem_info) (const gchar *device, GError **error) = bd_btrfs_filesystem_info_stub;
458 :
459 : /**
460 : * bd_btrfs_filesystem_info:
461 : * @device: a device that is part of the queried btrfs volume
462 : * @error: (out) (optional): place to store error (if any)
463 : *
464 : * Returns: information about the @device's volume's filesystem or %NULL in case of error
465 : *
466 : * Tech category: %BD_BTRFS_TECH_FS-%BD_BTRFS_TECH_MODE_QUERY
467 : */
468 3 : BDBtrfsFilesystemInfo* bd_btrfs_filesystem_info (const gchar *device, GError **error) {
469 3 : return _bd_btrfs_filesystem_info (device, error);
470 : }
471 :
472 :
473 0 : static gboolean bd_btrfs_mkfs_stub (const gchar **devices G_GNUC_UNUSED, const gchar *label G_GNUC_UNUSED, const gchar *data_level G_GNUC_UNUSED, const gchar *md_level G_GNUC_UNUSED, const BDExtraArg **extra G_GNUC_UNUSED, GError **error) {
474 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_btrfs_mkfs' called, but not implemented!");
475 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
476 : "The function 'bd_btrfs_mkfs' called, but not implemented!");
477 0 : return FALSE;
478 : }
479 :
480 : static gboolean (*_bd_btrfs_mkfs) (const gchar **devices, const gchar *label, const gchar *data_level, const gchar *md_level, const BDExtraArg **extra, GError **error) = bd_btrfs_mkfs_stub;
481 :
482 : /**
483 : * bd_btrfs_mkfs:
484 : * @devices: (array zero-terminated=1): list of devices to create btrfs volume from
485 : * @label: (nullable): label for the volume
486 : * @data_level: (nullable): RAID level for the data or %NULL to use the default
487 : * @md_level: (nullable): RAID level for the metadata or %NULL to use the default
488 : * @extra: (nullable) (array zero-terminated=1): extra options for the volume creation (right now
489 : * passed to the 'btrfs' utility)
490 : * @error: (out) (optional): place to store error (if any)
491 : *
492 : * Returns: whether the new btrfs volume was created from @devices or not
493 : *
494 : * See mkfs.btrfs(8) for details about @data_level, @md_level and btrfs in general.
495 : *
496 : * Tech category: %BD_BTRFS_TECH_FS-%BD_BTRFS_TECH_MODE_CREATE
497 : */
498 7 : gboolean bd_btrfs_mkfs (const gchar **devices, const gchar *label, const gchar *data_level, const gchar *md_level, const BDExtraArg **extra, GError **error) {
499 7 : return _bd_btrfs_mkfs (devices, label, data_level, md_level, extra, error);
500 : }
501 :
502 :
503 0 : static gboolean bd_btrfs_resize_stub (const gchar *mountpoint G_GNUC_UNUSED, guint64 size G_GNUC_UNUSED, const BDExtraArg **extra G_GNUC_UNUSED, GError **error) {
504 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_btrfs_resize' called, but not implemented!");
505 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
506 : "The function 'bd_btrfs_resize' called, but not implemented!");
507 0 : return FALSE;
508 : }
509 :
510 : static gboolean (*_bd_btrfs_resize) (const gchar *mountpoint, guint64 size, const BDExtraArg **extra, GError **error) = bd_btrfs_resize_stub;
511 :
512 : /**
513 : * bd_btrfs_resize:
514 : * @mountpoint: a mountpoint of the to be resized btrfs filesystem
515 : * @size: requested new size
516 : * @extra: (nullable) (array zero-terminated=1): extra options for the volume resize (right now
517 : * passed to the 'btrfs' utility)
518 : * @error: (out) (optional): place to store error (if any)
519 : *
520 : * Returns: whether the @mountpoint filesystem was successfully resized to @size
521 : * or not
522 : *
523 : * Tech category: %BD_BTRFS_TECH_FS-%BD_BTRFS_TECH_MODE_MODIFY
524 : */
525 1 : gboolean bd_btrfs_resize (const gchar *mountpoint, guint64 size, const BDExtraArg **extra, GError **error) {
526 1 : return _bd_btrfs_resize (mountpoint, size, extra, error);
527 : }
528 :
529 :
530 0 : static gboolean bd_btrfs_check_stub (const gchar *device G_GNUC_UNUSED, const BDExtraArg **extra G_GNUC_UNUSED, GError **error) {
531 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_btrfs_check' called, but not implemented!");
532 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
533 : "The function 'bd_btrfs_check' called, but not implemented!");
534 0 : return FALSE;
535 : }
536 :
537 : static gboolean (*_bd_btrfs_check) (const gchar *device, const BDExtraArg **extra, GError **error) = bd_btrfs_check_stub;
538 :
539 : /**
540 : * bd_btrfs_check:
541 : * @device: a device that is part of the checked btrfs volume
542 : * @extra: (nullable) (array zero-terminated=1): extra options for the check (right now
543 : * passed to the 'btrfs' utility)
544 : * @error: (out) (optional): place to store error (if any)
545 : *
546 : * Returns: whether the filesystem was successfully checked or not
547 : *
548 : * Tech category: %BD_BTRFS_TECH_FS-%BD_BTRFS_TECH_MODE_QUERY
549 : */
550 1 : gboolean bd_btrfs_check (const gchar *device, const BDExtraArg **extra, GError **error) {
551 1 : return _bd_btrfs_check (device, extra, error);
552 : }
553 :
554 :
555 0 : static gboolean bd_btrfs_repair_stub (const gchar *device G_GNUC_UNUSED, const BDExtraArg **extra G_GNUC_UNUSED, GError **error) {
556 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_btrfs_repair' called, but not implemented!");
557 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
558 : "The function 'bd_btrfs_repair' called, but not implemented!");
559 0 : return FALSE;
560 : }
561 :
562 : static gboolean (*_bd_btrfs_repair) (const gchar *device, const BDExtraArg **extra, GError **error) = bd_btrfs_repair_stub;
563 :
564 : /**
565 : * bd_btrfs_repair:
566 : * @device: a device that is part of the to be repaired btrfs volume
567 : * @extra: (nullable) (array zero-terminated=1): extra options for the repair (right now
568 : * passed to the 'btrfs' utility)
569 : * @error: (out) (optional): place to store error (if any)
570 : *
571 : * Returns: whether the filesystem was successfully checked and repaired or not
572 : *
573 : * Tech category: %BD_BTRFS_TECH_FS-%BD_BTRFS_TECH_MODE_MODIFY
574 : */
575 1 : gboolean bd_btrfs_repair (const gchar *device, const BDExtraArg **extra, GError **error) {
576 1 : return _bd_btrfs_repair (device, extra, error);
577 : }
578 :
579 :
580 0 : static gboolean bd_btrfs_change_label_stub (const gchar *mountpoint G_GNUC_UNUSED, const gchar *label G_GNUC_UNUSED, GError **error) {
581 0 : bd_utils_log_format (BD_UTILS_LOG_CRIT, "The function 'bd_btrfs_change_label' called, but not implemented!");
582 0 : g_set_error (error, BD_INIT_ERROR, BD_INIT_ERROR_NOT_IMPLEMENTED,
583 : "The function 'bd_btrfs_change_label' called, but not implemented!");
584 0 : return FALSE;
585 : }
586 :
587 : static gboolean (*_bd_btrfs_change_label) (const gchar *mountpoint, const gchar *label, GError **error) = bd_btrfs_change_label_stub;
588 :
589 : /**
590 : * bd_btrfs_change_label:
591 : * @mountpoint: a mountpoint of the btrfs filesystem to change label of
592 : * @label: new label for the filesystem
593 : * @error: (out) (optional): place to store error (if any)
594 : *
595 : * Returns: whether the label of the @mountpoint filesystem was successfully set
596 : * to @label or not
597 : *
598 : * Tech category: %BD_BTRFS_TECH_FS-%BD_BTRFS_TECH_MODE_MODIFY
599 : */
600 1 : gboolean bd_btrfs_change_label (const gchar *mountpoint, const gchar *label, GError **error) {
601 1 : return _bd_btrfs_change_label (mountpoint, label, error);
602 : }
603 :
604 :
605 24 : static gpointer load_btrfs_from_plugin(const gchar *so_name) {
606 24 : void *handle = NULL;
607 24 : char *error = NULL;
608 24 : gboolean (*init_fn) (void) = NULL;
609 :
610 24 : handle = dlopen(so_name, RTLD_LAZY);
611 24 : if (!handle) {
612 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load module btrfs: %s", dlerror());
613 0 : return NULL;
614 : }
615 :
616 24 : dlerror();
617 24 : * (void**) (&init_fn) = dlsym(handle, "bd_btrfs_init");
618 24 : if ((error = dlerror()) != NULL)
619 0 : bd_utils_log_format (BD_UTILS_LOG_DEBUG, "failed to load the init() function for btrfs: %s", error);
620 : /* coverity[dead_error_condition] */
621 24 : if (init_fn && !init_fn()) {
622 0 : dlclose(handle);
623 0 : return NULL;
624 : }
625 24 : init_fn = NULL;
626 :
627 24 : dlerror();
628 24 : * (void**) (&_bd_btrfs_is_tech_avail) = dlsym(handle, "bd_btrfs_is_tech_avail");
629 24 : if ((error = dlerror()) != NULL)
630 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_btrfs_is_tech_avail: %s", error);
631 :
632 24 : dlerror();
633 24 : * (void**) (&_bd_btrfs_create_volume) = dlsym(handle, "bd_btrfs_create_volume");
634 24 : if ((error = dlerror()) != NULL)
635 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_btrfs_create_volume: %s", error);
636 :
637 24 : dlerror();
638 24 : * (void**) (&_bd_btrfs_add_device) = dlsym(handle, "bd_btrfs_add_device");
639 24 : if ((error = dlerror()) != NULL)
640 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_btrfs_add_device: %s", error);
641 :
642 24 : dlerror();
643 24 : * (void**) (&_bd_btrfs_remove_device) = dlsym(handle, "bd_btrfs_remove_device");
644 24 : if ((error = dlerror()) != NULL)
645 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_btrfs_remove_device: %s", error);
646 :
647 24 : dlerror();
648 24 : * (void**) (&_bd_btrfs_create_subvolume) = dlsym(handle, "bd_btrfs_create_subvolume");
649 24 : if ((error = dlerror()) != NULL)
650 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_btrfs_create_subvolume: %s", error);
651 :
652 24 : dlerror();
653 24 : * (void**) (&_bd_btrfs_delete_subvolume) = dlsym(handle, "bd_btrfs_delete_subvolume");
654 24 : if ((error = dlerror()) != NULL)
655 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_btrfs_delete_subvolume: %s", error);
656 :
657 24 : dlerror();
658 24 : * (void**) (&_bd_btrfs_get_default_subvolume_id) = dlsym(handle, "bd_btrfs_get_default_subvolume_id");
659 24 : if ((error = dlerror()) != NULL)
660 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_btrfs_get_default_subvolume_id: %s", error);
661 :
662 24 : dlerror();
663 24 : * (void**) (&_bd_btrfs_set_default_subvolume) = dlsym(handle, "bd_btrfs_set_default_subvolume");
664 24 : if ((error = dlerror()) != NULL)
665 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_btrfs_set_default_subvolume: %s", error);
666 :
667 24 : dlerror();
668 24 : * (void**) (&_bd_btrfs_create_snapshot) = dlsym(handle, "bd_btrfs_create_snapshot");
669 24 : if ((error = dlerror()) != NULL)
670 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_btrfs_create_snapshot: %s", error);
671 :
672 24 : dlerror();
673 24 : * (void**) (&_bd_btrfs_list_devices) = dlsym(handle, "bd_btrfs_list_devices");
674 24 : if ((error = dlerror()) != NULL)
675 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_btrfs_list_devices: %s", error);
676 :
677 24 : dlerror();
678 24 : * (void**) (&_bd_btrfs_list_subvolumes) = dlsym(handle, "bd_btrfs_list_subvolumes");
679 24 : if ((error = dlerror()) != NULL)
680 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_btrfs_list_subvolumes: %s", error);
681 :
682 24 : dlerror();
683 24 : * (void**) (&_bd_btrfs_filesystem_info) = dlsym(handle, "bd_btrfs_filesystem_info");
684 24 : if ((error = dlerror()) != NULL)
685 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_btrfs_filesystem_info: %s", error);
686 :
687 24 : dlerror();
688 24 : * (void**) (&_bd_btrfs_mkfs) = dlsym(handle, "bd_btrfs_mkfs");
689 24 : if ((error = dlerror()) != NULL)
690 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_btrfs_mkfs: %s", error);
691 :
692 24 : dlerror();
693 24 : * (void**) (&_bd_btrfs_resize) = dlsym(handle, "bd_btrfs_resize");
694 24 : if ((error = dlerror()) != NULL)
695 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_btrfs_resize: %s", error);
696 :
697 24 : dlerror();
698 24 : * (void**) (&_bd_btrfs_check) = dlsym(handle, "bd_btrfs_check");
699 24 : if ((error = dlerror()) != NULL)
700 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_btrfs_check: %s", error);
701 :
702 24 : dlerror();
703 24 : * (void**) (&_bd_btrfs_repair) = dlsym(handle, "bd_btrfs_repair");
704 24 : if ((error = dlerror()) != NULL)
705 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_btrfs_repair: %s", error);
706 :
707 24 : dlerror();
708 24 : * (void**) (&_bd_btrfs_change_label) = dlsym(handle, "bd_btrfs_change_label");
709 24 : if ((error = dlerror()) != NULL)
710 0 : bd_utils_log_format (BD_UTILS_LOG_WARNING, "failed to load bd_btrfs_change_label: %s", error);
711 :
712 24 : return handle;
713 : }
714 :
715 24 : static gboolean unload_btrfs (gpointer handle) {
716 24 : char *error = NULL;
717 24 : gboolean (*close_fn) (void) = NULL;
718 :
719 24 : _bd_btrfs_is_tech_avail = bd_btrfs_is_tech_avail_stub;
720 24 : _bd_btrfs_create_volume = bd_btrfs_create_volume_stub;
721 24 : _bd_btrfs_add_device = bd_btrfs_add_device_stub;
722 24 : _bd_btrfs_remove_device = bd_btrfs_remove_device_stub;
723 24 : _bd_btrfs_create_subvolume = bd_btrfs_create_subvolume_stub;
724 24 : _bd_btrfs_delete_subvolume = bd_btrfs_delete_subvolume_stub;
725 24 : _bd_btrfs_get_default_subvolume_id = bd_btrfs_get_default_subvolume_id_stub;
726 24 : _bd_btrfs_set_default_subvolume = bd_btrfs_set_default_subvolume_stub;
727 24 : _bd_btrfs_create_snapshot = bd_btrfs_create_snapshot_stub;
728 24 : _bd_btrfs_list_devices = bd_btrfs_list_devices_stub;
729 24 : _bd_btrfs_list_subvolumes = bd_btrfs_list_subvolumes_stub;
730 24 : _bd_btrfs_filesystem_info = bd_btrfs_filesystem_info_stub;
731 24 : _bd_btrfs_mkfs = bd_btrfs_mkfs_stub;
732 24 : _bd_btrfs_resize = bd_btrfs_resize_stub;
733 24 : _bd_btrfs_check = bd_btrfs_check_stub;
734 24 : _bd_btrfs_repair = bd_btrfs_repair_stub;
735 24 : _bd_btrfs_change_label = bd_btrfs_change_label_stub;
736 :
737 24 : dlerror();
738 24 : * (void**) (&close_fn) = dlsym(handle, "bd_btrfs_close");
739 24 : if (((error = dlerror()) != NULL) || !close_fn)
740 0 : bd_utils_log_format (BD_UTILS_LOG_DEBUG, "failed to load the close_plugin() function for btrfs: %s", error);
741 : /* coverity[dead_error_condition] */
742 24 : if (close_fn) {
743 24 : close_fn();
744 : }
745 :
746 24 : return dlclose(handle) == 0;
747 : }
748 :
|