BTRFS

BTRFS — plugin for operations with BTRFS devices

Functions

Types and Values

Includes

#include <btrfs.h>

Description

A plugin for operations with btrfs devices.

Functions

BD_BTRFS_MIN_MEMBER_SIZE

#define BD_BTRFS_MIN_MEMBER_SIZE (16 MiB)

bd_btrfs_error_quark ()

GQuark
bd_btrfs_error_quark (void);

bd_btrfs_device_info_free ()

void
bd_btrfs_device_info_free (BDBtrfsDeviceInfo *info);

bd_btrfs_device_info_copy ()

BDBtrfsDeviceInfo *
bd_btrfs_device_info_copy (BDBtrfsDeviceInfo *info);

bd_btrfs_subvolume_info_free ()

void
bd_btrfs_subvolume_info_free (BDBtrfsSubvolumeInfo *info);

bd_btrfs_subvolume_info_copy ()

BDBtrfsSubvolumeInfo *
bd_btrfs_subvolume_info_copy (BDBtrfsSubvolumeInfo *info);

bd_btrfs_filesystem_info_free ()

void
bd_btrfs_filesystem_info_free (BDBtrfsFilesystemInfo *info);

bd_btrfs_filesystem_info_copy ()

BDBtrfsFilesystemInfo *
bd_btrfs_filesystem_info_copy (BDBtrfsFilesystemInfo *info);

bd_btrfs_create_volume ()

gboolean
bd_btrfs_create_volume (gchar **devices,
                        gchar *label,
                        gchar *data_level,
                        gchar *md_level,
                        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]

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.


bd_btrfs_add_device ()

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

Parameters

mountpoint

mountpoint of the btrfs volume to add new device to

 

device

a device to add to the btrfs volume

 

error

place to store error (if any).

[out]

Returns

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


bd_btrfs_remove_device ()

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

Parameters

mountpoint

mountpoint of the btrfs volume to remove device from

 

device

a device to remove from the btrfs volume

 

error

place to store error (if any).

[out]

Returns

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


bd_btrfs_create_subvolume ()

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

Parameters

mountpoint

mountpoint of the btrfs volume to create subvolume under

 

name

name of the subvolume

 

error

place to store error (if any).

[out]

Returns

whether the mountpoint /name subvolume was successfully created or not


bd_btrfs_delete_subvolume ()

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

Parameters

mountpoint

mountpoint of the btrfs volume to delete subvolume from

 

name

name of the subvolume

 

error

place to store error (if any).

[out]

Returns

whether the mountpoint /name subvolume was successfully deleted or not


bd_btrfs_get_default_subvolume_id ()

guint64
bd_btrfs_get_default_subvolume_id (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


bd_btrfs_set_default_subvolume ()

gboolean
bd_btrfs_set_default_subvolume (gchar *mountpoint,
                                guint64 subvol_id,
                                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

 

error

place to store error (if any).

[out]

Returns

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


bd_btrfs_create_snapshot ()

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

Parameters

source

path to source subvolume

 

dest

path to new snapshot volume

 

ro

whether the snapshot should be read-only

 

error

place to store error (if any).

[out]

Returns

whether the dest snapshot of source was successfully created or not


bd_btrfs_list_devices ()

BDBtrfsDeviceInfo **
bd_btrfs_list_devices (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.

[array zero-terminated=1]


bd_btrfs_list_subvolumes ()

BDBtrfsSubvolumeInfo **
bd_btrfs_list_subvolumes (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.

[array zero-terminated=1]


bd_btrfs_filesystem_info ()

BDBtrfsFilesystemInfo *
bd_btrfs_filesystem_info (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


bd_btrfs_mkfs ()

gboolean
bd_btrfs_mkfs (gchar **devices,
               gchar *label,
               gchar *data_level,
               gchar *md_level,
               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]

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.


bd_btrfs_resize ()

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

Parameters

mountpoint

a mountpoint of the to be resized btrfs filesystem

 

size

requested new size

 

error

place to store error (if any).

[out]

Returns

whether the mountpoint filesystem was successfully resized to size or not


bd_btrfs_check ()

gboolean
bd_btrfs_check (gchar *device,
                GError **error);

Parameters

device

a device that is part of the checked btrfs volume

 

error

place to store error (if any).

[out]

Returns

whether the filesystem was successfully checked or not


bd_btrfs_repair ()

gboolean
bd_btrfs_repair (gchar *device,
                 GError **error);

Parameters

device

a device that is part of the to be repaired btrfs volume

 

error

place to store error (if any).

[out]

Returns

whether the filesystem was successfully checked and repaired or not


bd_btrfs_change_label ()

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

Parameters

mountpoint

a mountpoint of the btrfs filesystem to change label of

 

label

new label for the filesystem

 

error

place to store error (if any).

[out]

Returns

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

Types and Values

BD_BTRFS_MAIN_VOLUME_ID

#define BD_BTRFS_MAIN_VOLUME_ID 5

BD_BTRFS_ERROR

#define BD_BTRFS_ERROR bd_btrfs_error_quark ()

enum BDBtrfsError

Members

BD_BTRFS_ERROR_DEVICE

   

BD_BTRFS_ERROR_PARSE

   

BDBtrfsDeviceInfo

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

BDBtrfsSubvolumeInfo

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

BDBtrfsFilesystemInfo

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