Skip to content

Commit 1223d82

Browse files
committed
fs: basic bcachefs support
This adds mkfs/get_info support for Bcachefs.
1 parent 4222e69 commit 1223d82

File tree

13 files changed

+451
-4
lines changed

13 files changed

+451
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Following storage technologies are supported by libblockdev
1616
- partitions
1717
- MSDOS, GPT
1818
- filesystem operations
19-
- ext2, ext3, ext4, xfs, vfat, ntfs, exfat, btrfs, f2fs, nilfs2, udf
19+
- ext2, ext3, ext4, xfs, vfat, ntfs, exfat, btrfs, f2fs, nilfs2, udf, bcachefs
2020
- mounting
2121
- LVM
2222
- thin provisioning, LVM RAID, cache, LVM VDO

misc/install-test-dependencies.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@
6969
- xfsprogs
7070
when: ansible_distribution == 'Fedora' and test_dependencies|bool
7171

72+
- name: Install bcachefs-tools test dependency (Fedora)
73+
package: name=bcachefs-tools state=present
74+
when: ansible_distribution == 'Fedora' and ansible_distribution_version = '40' and test_dependencies|bool
75+
7276
####### CentOS 8
7377
- name: Install basic build tools (CentOS 8)
7478
package: name={{item}} state=present

src/lib/plugin_apis/fs.api

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ typedef enum {
527527
BD_FS_TECH_EXFAT,
528528
BD_FS_TECH_BTRFS,
529529
BD_FS_TECH_UDF,
530+
BD_FS_TECH_BCACHEFS,
530531
} BDFSTech;
531532

532533
typedef enum {
@@ -811,6 +812,63 @@ GType bd_fs_udf_info_get_type () {
811812
return type;
812813
}
813814

815+
/**
816+
* BDFSBcachefsInfo:
817+
* @uuid: uuid of the filesystem
818+
* @size: size of the filesystem in bytes
819+
* @free_space: free space on the filesystem in bytes
820+
*/
821+
typedef struct BDFSBcachefsInfo {
822+
gchar *uuid;
823+
guint64 size;
824+
guint64 free_space;
825+
} BDFSBcachefsInfo;
826+
827+
/**
828+
* bd_fs_bcachefs_info_copy: (skip)
829+
* @data: (nullable): %BDFSBcachefsInfo to copy
830+
*
831+
* Creates a new copy of @data.
832+
*/
833+
BDFSBcachefsInfo* bd_fs_bcachefs_info_copy (BDFSBcachefsInfo *data) {
834+
if (data == NULL)
835+
return NULL;
836+
837+
BDFSBcachefsInfo *ret = g_new0 (BDFSBcachefsInfo, 1);
838+
839+
ret->uuid = g_strdup (data->uuid);
840+
ret->size = data->size;
841+
ret->free_space = data->free_space;
842+
843+
return ret;
844+
}
845+
846+
/**
847+
* bd_fs_bcachefs_info_free: (skip)
848+
* @data: (nullable): %BDFSBcachefsInfo to free
849+
*
850+
* Frees @data.
851+
*/
852+
void bd_fs_bcachefs_info_free (BDFSBcachefsInfo *data) {
853+
if (data == NULL)
854+
return;
855+
856+
g_free (data->uuid);
857+
g_free (data);
858+
}
859+
860+
GType bd_fs_bcachefs_info_get_type () {
861+
static GType type = 0;
862+
863+
if (G_UNLIKELY(type == 0)) {
864+
type = g_boxed_type_register_static("BDFSBcachefsInfo",
865+
(GBoxedCopyFunc) bd_fs_bcachefs_info_copy,
866+
(GBoxedFreeFunc) bd_fs_bcachefs_info_free);
867+
}
868+
869+
return type;
870+
}
871+
814872
/**
815873
* bd_fs_is_tech_avail:
816874
* @tech: the queried tech
@@ -2634,6 +2692,35 @@ gboolean bd_fs_udf_check_uuid (const gchar *uuid, GError **error);
26342692
*/
26352693
BDFSUdfInfo* bd_fs_udf_get_info (const gchar *device, GError **error);
26362694

2695+
/**
2696+
* bd_fs_bcachefs_mkfs:
2697+
* @device: the device to create a new bcachefs fs on
2698+
* @extra: (nullable) (array zero-terminated=1): extra options for the creation (right now
2699+
* passed to the 'mkfs.bcachefs' utility)
2700+
* @error: (out) (optional): place to store error (if any)
2701+
*
2702+
* Returns: whether a new bcachefs fs was successfully created on @device or not
2703+
*
2704+
* Tech category: %BD_FS_TECH_BCACHEFS-%BD_FS_TECH_MODE_MKFS
2705+
*
2706+
*/
2707+
gboolean bd_fs_bcachefs_mkfs (const gchar *device, const BDExtraArg **extra, GError **error);
2708+
2709+
/**
2710+
* bd_fs_bcachefs_get_info:
2711+
* @mpoint: a mountpoint of the bcachefs filesystem to get information about
2712+
* @error: (out) (optional): place to store error (if any)
2713+
*
2714+
* Returns: (transfer full): information about the file system on @device or
2715+
* %NULL in case of error
2716+
*
2717+
* Note: This function WON'T WORK for multi device bcachefs filesystems,
2718+
* for more complicated setups use the bcachefs plugin instead.
2719+
*
2720+
* Tech category: %BD_FS_TECH_BCACHEFS-%BD_FS_TECH_MODE_QUERY
2721+
*/
2722+
BDFSBcachefsInfo* bd_fs_bcachefs_get_info (const gchar *mpoint, GError **error);
2723+
26372724
typedef enum {
26382725
BD_FS_SUPPORT_SET_LABEL = 1 << 1,
26392726
BD_FS_SUPPORT_SET_UUID = 1 << 2

src/plugins/fs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ extern gboolean bd_fs_nilfs2_is_tech_avail (BDFSTech tech, guint64 mode, GError
4141
extern gboolean bd_fs_exfat_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
4242
extern gboolean bd_fs_btrfs_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
4343
extern gboolean bd_fs_udf_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
44+
extern gboolean bd_fs_bcachefs_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
4445

4546
/**
4647
* bd_fs_error_quark: (skip)
@@ -116,6 +117,8 @@ gboolean bd_fs_is_tech_avail (BDFSTech tech, guint64 mode, GError **error) {
116117
return bd_fs_btrfs_is_tech_avail (tech, mode, error);
117118
case BD_FS_TECH_UDF:
118119
return bd_fs_udf_is_tech_avail (tech, mode, error);
120+
case BD_FS_TECH_BCACHEFS:
121+
return bd_fs_bcachefs_is_tech_avail (tech, mode, error);
119122
/* coverity[dead_error_begin] */
120123
default:
121124
/* this should never be reached (see the comparison with LAST_FS

src/plugins/fs.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ typedef enum {
2323

2424
/* XXX: where the file systems start at the enum of technologies */
2525
#define BD_FS_OFFSET 2
26-
#define BD_FS_LAST_FS 13
26+
#define BD_FS_LAST_FS 14
2727
typedef enum {
2828
BD_FS_TECH_GENERIC = 0,
2929
BD_FS_TECH_MOUNT = 1,
@@ -38,6 +38,7 @@ typedef enum {
3838
BD_FS_TECH_EXFAT = 10,
3939
BD_FS_TECH_BTRFS = 11,
4040
BD_FS_TECH_UDF = 12,
41+
BD_FS_TECH_BCACHEFS = 13,
4142
} BDFSTech;
4243

4344
/* XXX: number of the highest bit of all modes */
@@ -80,3 +81,4 @@ gboolean bd_fs_is_tech_avail (BDFSTech tech, guint64 mode, GError **error);
8081
#include "fs/exfat.h"
8182
#include "fs/btrfs.h"
8283
#include "fs/udf.h"
84+
#include "fs/bcachefs.h"

src/plugins/fs/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ libbd_fs_la_SOURCES = ../check_deps.c ../check_deps.h \
1919
nilfs.c nilfs.h \
2020
exfat.c exfat.h \
2121
btrfs.c btrfs.h \
22-
udf.c udf.h
22+
udf.c udf.h \
23+
bcachefs.c bcachefs.h
2324

2425
libincludefsdir = $(includedir)/blockdev/fs/
2526
libincludefs_HEADERS = ext.h \

0 commit comments

Comments
 (0)