@@ -65,6 +65,10 @@ config HAVE_LIBEXT2FS
bool
option env="HAVE_LIBEXT2FS"
+config HAVE_LIBBTRFS
+ bool
+ option env="HAVE_LIBBTRFS"
+
config HAVE_LIBZEROMQ
bool
option env="HAVE_LIBZEROMQ"
@@ -66,6 +66,10 @@ ifeq ($(HAVE_LIBEXT2FS),)
export HAVE_LIBEXT2FS = y
endif
+ifeq ($(HAVE_LIBBTRFS),)
+export HAVE_LIBBTRFS = y
+endif
+
ifeq ($(HAVE_LIBSSL),)
export HAVE_LIBSSL = y
endif
@@ -193,6 +193,10 @@ ifeq ($(CONFIG_EXT_FILESYSTEM),y)
LDLIBS += ext2fs uuid blkid
endif
+ifeq ($(CONFIG_BTRFS_FILESYSTEM),y)
+LDLIBS += mkfsbtrfs btrfs btrfsutil udev
+endif
+
ifeq ($(CONFIG_UNIQUEUUID),y)
LDLIBS += blkid
endif
@@ -18,4 +18,14 @@ config EXT_FILESYSTEM
comment "EXT2 / EXT3 / EXT4 file system creation support needs libext2fs"
depends on !HAVE_LIBEXT2FS
+
+config BTRFS_FILESYSTEM
+ bool "BTRFS file system creation support"
+ depends on HAVE_LIBBTRFS
+ default n
+ help
+ Enable support for creating BTRFS file systems.
+
+comment "BTRFS file system creation support needs libbtrfs libbtrfsutil"
+ depends on !HAVE_LIBBTRFS
endif
@@ -6,4 +6,7 @@ lib-$(CONFIG_DISKFORMAT) += diskformat.o
lib-$(CONFIG_FAT_FILESYSTEM) += diskio.o \
fat_fs.o \
ff.o
-lib-$(CONFIG_EXT_FILESYSTEM) += mke2fs.o \
+lib-$(CONFIG_EXT_FILESYSTEM) += mke2fs.o
+
+#lib-$(CONFIG_BTRFS_FILESYSTEM) += btrfs/hash.o btrfs/crc32c.o btrfs/btrfs.o btrfs/common.o btrfs/hash.o btrfs/xxhash.o btrfs/blake2b-ref.o btrfs/sha224-256.o btrfs/inode-item.o
+lib-$(CONFIG_BTRFS_FILESYSTEM) += btrfs.o
new file mode 100644
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2023 Stefano Babic, sbabic@denx.de
+ *
+ * SPDX-License-Identifier: GPL-2.0-only
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <ctype.h>
+#include <time.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <libgen.h>
+#include <limits.h>
+#include <blkid/blkid.h>
+#include <uuid/uuid.h>
+#include "util.h"
+#include "fs_interface.h"
+#include "pctl.h"
+
+extern int mkfs_main(int argc, const char **argv);
+int btrfs_mkfs(const char *device_name, const char __attribute__ ((__unused__)) *fstype)
+{
+ int fd, ret;
+ int argc;
+ const char *argv[3] = { "mkfs.btrfs", "-f", NULL };
+
+ if (!device_name)
+ return -EINVAL;
+
+ fd = open(device_name, O_RDWR);
+
+ if (fd < 0) {
+ ERROR("%s cannot be opened", device_name);
+ return -EINVAL;
+ }
+ close(fd);
+
+ optind = 1;
+ argv[2] = device_name;
+ argc = 3;
+
+ ret = run_function_background(mkfs_main, argc, (char **)argv);
+
+ return ret;
+}
@@ -33,6 +33,9 @@ static struct supported_filesystems fs[] = {
{"ext3", ext_mkfs_short},
{"ext4", ext_mkfs_short},
#endif
+#if defined(CONFIG_BTRFS_FILESYSTEM)
+ {"btrfs", btrfs_mkfs},
+#endif
};
/*
@@ -21,4 +21,7 @@ extern int ext_mkfs(const char *device_name, const char *fstype, unsigned long f
const char *volume_label);
#endif
+#if defined (CONFIG_BTRFS_FILESYSTEM)
+extern int btrfs_mkfs(const char *device_name, const char *fstype);
+#endif
#endif
This allows to link with a modified version of btrfs-tools, that makes availale mkfs.btrfs as library and SWupdate can call it : https://github.com/kdave/btrfs-progs/compare/master...sbabic:btrfs-progs:swupdate Standard default parameters are taken, there is currently no support for btrfs tuning. Signed-off-by: Stefano Babic <sbabic@denx.de> --- Kconfig | 4 ++++ Makefile.deps | 4 ++++ Makefile.flags | 4 ++++ fs/Config.in | 10 ++++++++ fs/Makefile | 5 +++- fs/btrfs.c | 52 ++++++++++++++++++++++++++++++++++++++++++ fs/diskformat.c | 3 +++ include/fs_interface.h | 3 +++ 8 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 fs/btrfs.c