BTRFS: libblockdev Reference Manual

## BTRFS BTRFS — plugin for operations with BTRFS devices |

## Functions

gboolean | bd_btrfs_check_deps ()
gboolean | bd_btrfs_init ()
void | bd_btrfs_close ()
GQuark | bd_btrfs_error_quark ()
void | bd_btrfs_device_info_free ()
BDBtrfsDeviceInfo * | bd_btrfs_device_info_copy ()
void | bd_btrfs_subvolume_info_free ()
BDBtrfsSubvolumeInfo * | bd_btrfs_subvolume_info_copy ()
void | bd_btrfs_filesystem_info_free ()
BDBtrfsFilesystemInfo * | bd_btrfs_filesystem_info_copy ()
gboolean | bd_btrfs_create_volume ()
gboolean | bd_btrfs_add_device ()
gboolean | bd_btrfs_remove_device ()
gboolean | bd_btrfs_create_subvolume ()
gboolean | bd_btrfs_delete_subvolume ()
guint64 | bd_btrfs_get_default_subvolume_id ()
gboolean | bd_btrfs_set_default_subvolume ()
gboolean | bd_btrfs_create_snapshot ()
BDBtrfsDeviceInfo ** | bd_btrfs_list_devices ()
BDBtrfsSubvolumeInfo ** | bd_btrfs_list_subvolumes ()
BDBtrfsFilesystemInfo * | bd_btrfs_filesystem_info ()
gboolean | bd_btrfs_mkfs ()
gboolean | bd_btrfs_resize ()
gboolean | bd_btrfs_check ()
gboolean | bd_btrfs_repair ()
gboolean | bd_btrfs_change_label ()
gboolean | bd_btrfs_is_tech_avail ()

## Types and Values

#define | BD_BTRFS_MAIN_VOLUME_ID
#define | BD_BTRFS_MIN_MEMBER_SIZE
#define | BD_BTRFS_ERROR
enum | BDBtrfsError
| BDBtrfsDeviceInfo
| BDBtrfsSubvolumeInfo
| BDBtrfsFilesystemInfo
enum | BDBtrfsTech
enum | BDBtrfsTechMode

## Includes

    #include <btrfs.h>

## Description

A plugin for operations with btrfs devices.

## Functions

### bd_btrfs_check_deps ()

    gboolean
    bd_btrfs_check_deps (void);

#### Returns

whether the plugin's runtime dependencies are satisfied or not

Function checking plugin's runtime dependencies.

### bd_btrfs_init ()

    gboolean
    bd_btrfs_init (void);

Initializes the plugin. **This function is called automatically by the library's initialization functions.**

### bd_btrfs_close ()

    void
    bd_btrfs_close (void);

Cleans up after the plugin. **This function is called automatically by the library's functions that unload it.**

### bd_btrfs_error_quark ()

    GQuark
    bd_btrfs_error_quark (void);

[skip]

### bd_btrfs_device_info_free ()

    void
    bd_btrfs_device_info_free (BDBtrfsDeviceInfo *info);

Frees `info` .

[skip]

### bd_btrfs_device_info_copy ()

    BDBtrfsDeviceInfo *
    bd_btrfs_device_info_copy (BDBtrfsDeviceInfo *info);

Creates a new copy of `info` .

[skip]

### bd_btrfs_subvolume_info_free ()

    void
    bd_btrfs_subvolume_info_free (BDBtrfsSubvolumeInfo *info);

Frees `info` .

[skip]

### bd_btrfs_subvolume_info_copy ()

    BDBtrfsSubvolumeInfo *
    bd_btrfs_subvolume_info_copy (BDBtrfsSubvolumeInfo *info);

Creates a new copy of `info` .

[skip]

### bd_btrfs_filesystem_info_free ()

    void
    bd_btrfs_filesystem_info_free (BDBtrfsFilesystemInfo *info);

Frees `info` .

[skip]

### bd_btrfs_filesystem_info_copy ()

    BDBtrfsFilesystemInfo *
    bd_btrfs_filesystem_info_copy (BDBtrfsFilesystemInfo *info);

Creates a new copy of `info` .

[skip]

### bd_btrfs_create_volume ()

    gboolean
    bd_btrfs_create_volume (const gchar **devices,
                            const gchar *label,
                            const gchar *data_level,
                            const gchar *md_level,
                            const BDExtraArg **extra,
                            GError **error);

#### Parameters

devices | list of devices to create btrfs volume from. | [array zero-terminated=1]
label | label for the volume. | [allow-none]
data_level | RAID level for the data or `NULL` to use the default. | [allow-none]
md_level | RAID level for the metadata or `NULL` to use the default. | [allow-none]
extra | extra options for the volume creation (right now passed to the 'mkfs.btrfs' utility). | [allow-none][array zero-terminated=1]
error | place to store error (if any). | [out]

#### Returns

whether the new btrfs volume was created from `devices` or not

See mkfs.btrfs(8) for details about `data_level` , `md_level` and btrfs in general.

Tech category: `BD_BTRFS_TECH_MULTI_DEV`-`BD_BTRFS_TECH_MODE_CREATE`

### bd_btrfs_add_device ()

    gboolean
    bd_btrfs_add_device (const gchar *mountpoint,
                         const gchar *device,
                         const BDExtraArg **extra,
                         GError **error);

#### Parameters

mountpoint | mountpoint of the btrfs volume to add new device to |
device | a device to add to the btrfs volume |
extra | extra options for the addition (right now passed to the 'btrfs' utility). | [allow-none][array zero-terminated=1]
error | place to store error (if any). | [out]

#### Returns

whether the `device` was successfully added to the `mountpoint` btrfs volume or not

Tech category: `BD_BTRFS_TECH_MULTI_DEV`-`BD_BTRFS_TECH_MODE_MODIFY`

### bd_btrfs_remove_device ()

    gboolean
    bd_btrfs_remove_device (const gchar *mountpoint,
                            const gchar *device,
                            const BDExtraArg **extra,
                            GError **error);

#### Parameters

mountpoint | mountpoint of the btrfs volume to remove device from |
device | a device to remove from the btrfs volume |
extra | extra options for the removal (right now passed to the 'btrfs' utility). | [allow-none][array zero-terminated=1]
error | place to store error (if any). | [out]

#### Returns

whether the `device` was successfully removed from the `mountpoint` btrfs volume or not

Tech category: `BD_BTRFS_TECH_MULTI_DEV`-`BD_BTRFS_TECH_MODE_MODIFY`

### bd_btrfs_create_subvolume ()

    gboolean
    bd_btrfs_create_subvolume (const gchar *mountpoint,
                               const gchar *name,
                               const BDExtraArg **extra,
                               GError **error);

#### Parameters

mountpoint | mountpoint of the btrfs volume to create subvolume under |
name | name of the subvolume |
extra | extra options for the subvolume creation (right now passed to the 'btrfs' utility). | [allow-none][array zero-terminated=1]
error | place to store error (if any). | [out]

#### Returns

whether the `mountpoint` /`name` subvolume was successfully created or not

Tech category: `BD_BTRFS_TECH_SUBVOL`-`BD_BTRFS_TECH_MODE_CREATE`

### bd_btrfs_delete_subvolume ()

    gboolean
    bd_btrfs_delete_subvolume (const gchar *mountpoint,
                               const gchar *name,
                               const BDExtraArg **extra,
                               GError **error);

#### Parameters

mountpoint | mountpoint of the btrfs volume to delete subvolume from |
name | name of the subvolume |
extra | extra options for the subvolume deletion (right now passed to the 'btrfs' utility). | [allow-none][array zero-terminated=1]
error | place to store error (if any). | [out]

#### Returns

whether the `mountpoint` /`name` subvolume was successfully deleted or not

Tech category: `BD_BTRFS_TECH_SUBVOL`-`BD_BTRFS_TECH_MODE_DELETE`

### bd_btrfs_get_default_subvolume_id ()

    guint64
    bd_btrfs_get_default_subvolume_id (const gchar *mountpoint,
                                       GError **error);

#### Parameters

mountpoint | mountpoint of the volume to get the default subvolume ID of |
error | place to store error (if any). | [out]

#### Returns

ID of the `mountpoint` volume's default subvolume. If 0, `error` ) may be set to indicate error

Tech category: `BD_BTRFS_TECH_SUBVOL`-`BD_BTRFS_TECH_MODE_QUERY`

### bd_btrfs_set_default_subvolume ()

    gboolean
    bd_btrfs_set_default_subvolume (const gchar *mountpoint,
                                    guint64 subvol_id,
                                    const BDExtraArg **extra,
                                    GError **error);

#### Parameters

mountpoint | mountpoint of the volume to set the default subvolume ID of |
subvol_id | ID of the subvolume to be set as the default subvolume |
extra | extra options for the setting (right now passed to the 'btrfs' utility). | [allow-none][array zero-terminated=1]
error | place to store error (if any). | [out]

#### Returns

whether the `mountpoint` volume's default subvolume was correctly set to `subvol_id` or not

Tech category: `BD_BTRFS_TECH_SUBVOL`-`BD_BTRFS_TECH_MODE_MODIFY`

### bd_btrfs_create_snapshot ()

    gboolean
    bd_btrfs_create_snapshot (const gchar *source,
                              const gchar *dest,
                              gboolean ro,
                              const BDExtraArg **extra,
                              GError **error);

#### Parameters

source | path to source subvolume |
dest | path to new snapshot volume |
ro | whether the snapshot should be read-only |
extra | extra options for the snapshot creation (right now passed to the 'btrfs' utility). | [allow-none][array zero-terminated=1]
error | place to store error (if any). | [out]

#### Returns

whether the `dest` snapshot of `source` was successfully created or not

Tech category: `BD_BTRFS_TECH_SNAPSHOT`-`BD_BTRFS_TECH_MODE_CREATE`

### bd_btrfs_list_devices ()

    BDBtrfsDeviceInfo **
    bd_btrfs_list_devices (const gchar *device,
                           GError **error);

#### Parameters

device | a device that is part of the queried btrfs volume |
error | place to store error (if any). | [out]

#### Returns

information about the devices that are part of the btrfs volume containing `device` or `NULL` in case of error

Tech category: `BD_BTRFS_TECH_MULTI_DEV`-`BD_BTRFS_TECH_MODE_QUERY`.

[array zero-terminated=1]

### bd_btrfs_list_subvolumes ()

    BDBtrfsSubvolumeInfo **
    bd_btrfs_list_subvolumes (const gchar *mountpoint,
                              gboolean snapshots_only,
                              GError **error);

#### Parameters

mountpoint | a mountpoint of the queried btrfs volume |
snapshots_only | whether to list only snapshot subvolumes or not |
error | place to store error (if any). | [out]

#### Returns

information about the subvolumes that are part of the btrfs volume mounted at `mountpoint` or `NULL` in case of error

The subvolumes are sorted in a way that no child subvolume appears in the list before its parent (sub)volume.

Tech category: `BD_BTRFS_TECH_SUBVOL`-`BD_BTRFS_TECH_MODE_QUERY`.

[array zero-terminated=1]

### bd_btrfs_filesystem_info ()

    BDBtrfsFilesystemInfo *
    bd_btrfs_filesystem_info (const gchar *device,
                              GError **error);

#### Parameters

device | a device that is part of the queried btrfs volume |
error | place to store error (if any). | [out]

#### Returns

information about the `device` 's volume's filesystem or `NULL` in case of error

Tech category: `BD_BTRFS_TECH_FS`-`BD_BTRFS_TECH_MODE_QUERY`

### bd_btrfs_mkfs ()

    gboolean
    bd_btrfs_mkfs (const gchar **devices,
                   const gchar *label,
                   const gchar *data_level,
                   const gchar *md_level,
                   const BDExtraArg **extra,
                   GError **error);

#### Parameters

devices | list of devices to create btrfs volume from. | [array zero-terminated=1]
label | label for the volume. | [allow-none]
data_level | RAID level for the data or `NULL` to use the default. | [allow-none]
md_level | RAID level for the metadata or `NULL` to use the default. | [allow-none]
extra | extra options for the volume creation (right now passed to the 'btrfs' utility). | [allow-none][array zero-terminated=1]
error | place to store error (if any). | [out]

#### Returns

whether the new btrfs volume was created from `devices` or not

See mkfs.btrfs(8) for details about `data_level` , `md_level` and btrfs in general.

Tech category: `BD_BTRFS_TECH_FS`-`BD_BTRFS_TECH_MODE_CREATE`

### bd_btrfs_resize ()

    gboolean
    bd_btrfs_resize (const gchar *mountpoint,
                     guint64 size,
                     const BDExtraArg **extra,
                     GError **error);

#### Parameters

mountpoint | a mountpoint of the to be resized btrfs filesystem |
size | requested new size |
extra | extra options for the volume resize (right now passed to the 'btrfs' utility). | [allow-none][array zero-terminated=1]
error | place to store error (if any). | [out]

#### Returns

whether the `mountpoint` filesystem was successfully resized to `size` or not

Tech category: `BD_BTRFS_TECH_FS`-`BD_BTRFS_TECH_MODE_MODIFY`

### bd_btrfs_check ()

    gboolean
    bd_btrfs_check (const gchar *device,
                    const BDExtraArg **extra,
                    GError **error);

#### Parameters

device | a device that is part of the checked btrfs volume |
extra | extra options for the check (right now passed to the 'btrfs' utility). | [allow-none][array zero-terminated=1]
error | place to store error (if any). | [out]

#### Returns

whether the filesystem was successfully checked or not

Tech category: `BD_BTRFS_TECH_FS`-`BD_BTRFS_TECH_MODE_QUERY`

### bd_btrfs_repair ()

    gboolean
    bd_btrfs_repair (const gchar *device,
                     const BDExtraArg **extra,
                     GError **error);

#### Parameters

device | a device that is part of the to be repaired btrfs volume |
extra | extra options for the repair (right now passed to the 'btrfs' utility). | [allow-none][array zero-terminated=1]
error | place to store error (if any). | [out]

#### Returns

whether the filesystem was successfully checked and repaired or not

Tech category: `BD_BTRFS_TECH_FS`-`BD_BTRFS_TECH_MODE_MODIFY`

### bd_btrfs_change_label ()

    gboolean
    bd_btrfs_change_label (const gchar *mountpoint,
                           const gchar *label,
                           GError **error);

#### Parameters

mountpoint | a mountpoint of the btrfs filesystem to change label of |
label | new label for the filesystem |
extra | extra options for the volume creation (right now passed to the 'btrfs' utility). | [allow-none][array zero-terminated=1]
error | place to store error (if any). | [out]

#### Returns

whether the label of the `mountpoint` filesystem was successfully set to `label` or not

Tech category: `BD_BTRFS_TECH_FS`-`BD_BTRFS_TECH_MODE_MODIFY`

### bd_btrfs_is_tech_avail ()

    gboolean
    bd_btrfs_is_tech_avail (BDBtrfsTech tech,
                            guint64 mode,
                            GError **error);

#### Parameters

tech | the queried tech |
mode | a bit mask of queried modes of operation (BDBtrfsTechMode) for `tech` |
error | place to store error (details about why the `tech` -`mode` combination is not available). | [out]

#### Returns

whether the `tech` -`mode` combination is avaible -- supported by the plugin implementation and having all the runtime dependencies available

## Types and Values

### BD_BTRFS_MAIN_VOLUME_ID

    #define             BD_BTRFS_MAIN_VOLUME_ID

### BD_BTRFS_MIN_MEMBER_SIZE

    #define             BD_BTRFS_MIN_MEMBER_SIZE

### BD_BTRFS_ERROR

    #define             BD_BTRFS_ERROR

### enum BDBtrfsError

#### Members

BD_BTRFS_ERROR_DEVICE |  |
BD_BTRFS_ERROR_PARSE |  |
BD_BTRFS_ERROR_TECH_UNAVAIL |  |

### BDBtrfsDeviceInfo

    typedef struct {
        guint64 id;
        gchar *path;
        guint64 size;
        guint64 used;
    } BDBtrfsDeviceInfo;

#### Members

guint64 `id`; | ID of the device |
gchar *`path`; | path of the device |
guint64 `size`; | size of the device |
guint64 `used`; | size of the used space |

### BDBtrfsSubvolumeInfo

    typedef struct {
        guint64 id;
        guint64 parent_id;
        gchar *path;
    } BDBtrfsSubvolumeInfo;

#### Members

guint64 `id`; | ID of the subvolume |
guint64 `parent_id`; | ID of the parent (sub)volume |
gchar *`path`; | path of the subvolume |

### BDBtrfsFilesystemInfo

    typedef struct {
        gchar *label;
        gchar *uuid;
        guint64 num_devices;
        guint64 used;
    } BDBtrfsFilesystemInfo;

#### Members

gchar *`label`; | label of the filesystem |
gchar *`uuid`; | uuid of the filesystem |
guint64 `num_devices`; | number of device in the filesystem |
guint64 `used`; | size of the used space |

### enum BDBtrfsTech

#### Members

BD_BTRFS_TECH_FS |  |
BD_BTRFS_TECH_MULTI_DEV |  |
BD_BTRFS_TECH_SUBVOL |  |
BD_BTRFS_TECH_SNAPSHOT |  |

### enum BDBtrfsTechMode

#### Members

BD_BTRFS_TECH_MODE_CREATE |  |
BD_BTRFS_TECH_MODE_DELETE |  |
BD_BTRFS_TECH_MODE_MODIFY |  |
BD_BTRFS_TECH_MODE_QUERY |  |