Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: basic bcachefs support #959

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Following storage technologies are supported by libblockdev
- partitions
- MSDOS, GPT
- filesystem operations
- ext2, ext3, ext4, xfs, vfat, ntfs, exfat, btrfs, f2fs, nilfs2, udf
- ext2, ext3, ext4, xfs, vfat, ntfs, exfat, btrfs, f2fs, nilfs2, udf, bcachefs
- mounting
- LVM
- thin provisioning, LVM RAID, cache, LVM VDO
Expand Down
4 changes: 4 additions & 0 deletions misc/install-test-dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
- xfsprogs
when: ansible_distribution == 'Fedora' and test_dependencies|bool

- name: Install bcachefs-tools test dependency (Fedora)
package: name=bcachefs-tools state=present
when: ansible_distribution == 'Fedora' and ansible_distribution_version == '40' and test_dependencies|bool

####### CentOS 8
- name: Install basic build tools (CentOS 8)
package: name={{item}} state=present
Expand Down
87 changes: 87 additions & 0 deletions src/lib/plugin_apis/fs.api
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ typedef enum {
BD_FS_TECH_EXFAT,
BD_FS_TECH_BTRFS,
BD_FS_TECH_UDF,
BD_FS_TECH_BCACHEFS,
} BDFSTech;

typedef enum {
Expand Down Expand Up @@ -811,6 +812,63 @@ GType bd_fs_udf_info_get_type () {
return type;
}

/**
* BDFSBcachefsInfo:
* @uuid: uuid of the filesystem
* @size: size of the filesystem in bytes
* @free_space: free space on the filesystem in bytes
*/
typedef struct BDFSBcachefsInfo {
gchar *uuid;
guint64 size;
guint64 free_space;
} BDFSBcachefsInfo;

/**
* bd_fs_bcachefs_info_copy: (skip)
* @data: (nullable): %BDFSBcachefsInfo to copy
*
* Creates a new copy of @data.
*/
BDFSBcachefsInfo* bd_fs_bcachefs_info_copy (BDFSBcachefsInfo *data) {
if (data == NULL)
return NULL;

BDFSBcachefsInfo *ret = g_new0 (BDFSBcachefsInfo, 1);

ret->uuid = g_strdup (data->uuid);
ret->size = data->size;
ret->free_space = data->free_space;

return ret;
}

/**
* bd_fs_bcachefs_info_free: (skip)
* @data: (nullable): %BDFSBcachefsInfo to free
*
* Frees @data.
*/
void bd_fs_bcachefs_info_free (BDFSBcachefsInfo *data) {
if (data == NULL)
return;

g_free (data->uuid);
g_free (data);
}

GType bd_fs_bcachefs_info_get_type () {
static GType type = 0;

if (G_UNLIKELY(type == 0)) {
type = g_boxed_type_register_static("BDFSBcachefsInfo",
(GBoxedCopyFunc) bd_fs_bcachefs_info_copy,
(GBoxedFreeFunc) bd_fs_bcachefs_info_free);
}

return type;
}

/**
* bd_fs_is_tech_avail:
* @tech: the queried tech
Expand Down Expand Up @@ -2634,6 +2692,35 @@ gboolean bd_fs_udf_check_uuid (const gchar *uuid, GError **error);
*/
BDFSUdfInfo* bd_fs_udf_get_info (const gchar *device, GError **error);

/**
* bd_fs_bcachefs_mkfs:
* @device: the device to create a new bcachefs fs on
* @extra: (nullable) (array zero-terminated=1): extra options for the creation (right now
* passed to the 'mkfs.bcachefs' utility)
* @error: (out) (optional): place to store error (if any)
*
* Returns: whether a new bcachefs fs was successfully created on @device or not
*
* Tech category: %BD_FS_TECH_BCACHEFS-%BD_FS_TECH_MODE_MKFS
*
*/
gboolean bd_fs_bcachefs_mkfs (const gchar *device, const BDExtraArg **extra, GError **error);

/**
* bd_fs_bcachefs_get_info:
* @mpoint: a mountpoint of the bcachefs filesystem to get information about
* @error: (out) (optional): place to store error (if any)
*
* Returns: (transfer full): information about the file system on @device or
* %NULL in case of error
*
* Note: This function WON'T WORK for multi device bcachefs filesystems,
* for more complicated setups use the bcachefs plugin instead.
*
* Tech category: %BD_FS_TECH_BCACHEFS-%BD_FS_TECH_MODE_QUERY
*/
BDFSBcachefsInfo* bd_fs_bcachefs_get_info (const gchar *mpoint, GError **error);

typedef enum {
BD_FS_SUPPORT_SET_LABEL = 1 << 1,
BD_FS_SUPPORT_SET_UUID = 1 << 2
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ extern gboolean bd_fs_nilfs2_is_tech_avail (BDFSTech tech, guint64 mode, GError
extern gboolean bd_fs_exfat_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
extern gboolean bd_fs_btrfs_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
extern gboolean bd_fs_udf_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
extern gboolean bd_fs_bcachefs_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);

/**
* bd_fs_error_quark: (skip)
Expand Down Expand Up @@ -116,6 +117,8 @@ gboolean bd_fs_is_tech_avail (BDFSTech tech, guint64 mode, GError **error) {
return bd_fs_btrfs_is_tech_avail (tech, mode, error);
case BD_FS_TECH_UDF:
return bd_fs_udf_is_tech_avail (tech, mode, error);
case BD_FS_TECH_BCACHEFS:
return bd_fs_bcachefs_is_tech_avail (tech, mode, error);
/* coverity[dead_error_begin] */
default:
/* this should never be reached (see the comparison with LAST_FS
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ typedef enum {

/* XXX: where the file systems start at the enum of technologies */
#define BD_FS_OFFSET 2
#define BD_FS_LAST_FS 13
#define BD_FS_LAST_FS 14
typedef enum {
BD_FS_TECH_GENERIC = 0,
BD_FS_TECH_MOUNT = 1,
Expand All @@ -38,6 +38,7 @@ typedef enum {
BD_FS_TECH_EXFAT = 10,
BD_FS_TECH_BTRFS = 11,
BD_FS_TECH_UDF = 12,
BD_FS_TECH_BCACHEFS = 13,
} BDFSTech;

/* XXX: number of the highest bit of all modes */
Expand Down Expand Up @@ -80,3 +81,4 @@ gboolean bd_fs_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
#include "fs/exfat.h"
#include "fs/btrfs.h"
#include "fs/udf.h"
#include "fs/bcachefs.h"
3 changes: 2 additions & 1 deletion src/plugins/fs/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ libbd_fs_la_SOURCES = ../check_deps.c ../check_deps.h \
nilfs.c nilfs.h \
exfat.c exfat.h \
btrfs.c btrfs.h \
udf.c udf.h
udf.c udf.h \
bcachefs.c bcachefs.h

libincludefsdir = $(includedir)/blockdev/fs/
libincludefs_HEADERS = ext.h \
Expand Down
Loading
Loading